Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cli/logs_orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ func downloadRunArtifactsConcurrent(ctx context.Context, runs []WorkflowRun, out
CLIVersion: GetVersion(),
RunID: run.DatabaseID,
ProcessedAt: time.Now(),
Run: run,
Run: result.Run,
Metrics: metrics,
AccessAnalysis: accessAnalysis,
FirewallAnalysis: firewallAnalysis,
Expand Down
43 changes: 43 additions & 0 deletions pkg/cli/logs_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,46 @@ func TestRunSummaryJSONStructure(t *testing.T) {
t.Errorf("ArtifactsList length mismatch after round-trip: got %d, want %d", len(testUnmarshal.ArtifactsList), len(testSummary.ArtifactsList))
}
}

// TestSaveAndLoadRunSummary_SafeItemsCount verifies that SafeItemsCount is correctly
// persisted to and loaded from the RunSummary cache. This is a regression test for
// the bug where filtering logs by workflow_name returned safe_items_count=0 because
// the RunSummary was saved with Run: run (which had SafeItemsCount=0) instead of
// Run: result.Run (which had SafeItemsCount set after extractCreatedItemsFromManifest).
func TestSaveAndLoadRunSummary_SafeItemsCount(t *testing.T) {
tmpDir := testutil.TempDir(t, "test-safe-items-*")
runDir := filepath.Join(tmpDir, "run-99999")
if err := os.MkdirAll(runDir, 0755); err != nil {
t.Fatalf("Failed to create test directory: %v", err)
}

originalVersion := GetVersion()
SetVersionInfo("1.0.0-test")
defer SetVersionInfo(originalVersion)

testSummary := &RunSummary{
CLIVersion: GetVersion(),
RunID: 99999,
ProcessedAt: time.Now(),
Run: WorkflowRun{
DatabaseID: 99999,
WorkflowName: "Plan Command",
Status: "completed",
Conclusion: "success",
SafeItemsCount: 4,
},
}

if err := saveRunSummary(runDir, testSummary, false); err != nil {
t.Fatalf("Failed to save run summary: %v", err)
}

loaded, ok := loadRunSummary(runDir, false)
if !ok {
t.Fatal("Failed to load run summary")
}

if loaded.Run.SafeItemsCount != 4 {
t.Errorf("SafeItemsCount not persisted: got %d, want 4", loaded.Run.SafeItemsCount)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid regression test! The test clearly documents the bug and verifies the fix by round-tripping through save/load. The SafeItemsCount: 4 value makes the assertion easy to follow.

Loading