Skip to content

Commit c4a6c78

Browse files
committed
more audit cleanup
1 parent b0d6544 commit c4a6c78

3 files changed

Lines changed: 33 additions & 22 deletions

File tree

pkg/cli/audit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ func renderAuditCompletion(runOutputDir string, jsonOutput bool) {
844844
}
845845
absOutputDir, _ := filepath.Abs(runOutputDir)
846846
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Audit complete. Logs saved to "+absOutputDir))
847+
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Tip: use --artifacts to select specific artifact sets (agent, firewall, mcp, activation, detection, etc.)"))
847848
}
848849

849850
// auditJobRunOptions holds parameters for auditJobRun.

pkg/cli/audit_report.go

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -444,43 +444,53 @@ func buildAuditData(processedRun ProcessedRun, metrics LogMetrics, mcpToolUsage
444444
return auditData
445445
}
446446

447-
// extractDownloadedFiles scans the logs directory and returns file information
447+
// extractDownloadedFiles scans the logs directory recursively and returns file information.
448+
// It walks subdirectories (aw-prompts/, base/, etc.) so the JSON output enumerates every
449+
// file available for inspection. Baseline directories are excluded to keep output focused.
448450
func extractDownloadedFiles(logsPath string) []FileInfo {
449451
auditReportLog.Printf("Extracting downloaded files from: %s", logsPath)
450452
var files []FileInfo
451453

452-
entries, err := os.ReadDir(logsPath)
454+
absLogsPath, err := filepath.Abs(logsPath)
453455
if err != nil {
454-
auditReportLog.Printf("Failed to read logs directory: %v", err)
455-
return files
456+
auditReportLog.Printf("Failed to resolve absolute logs path: %v", err)
457+
absLogsPath = logsPath
456458
}
457459

458-
for _, entry := range entries {
459-
// Skip directories
460-
if entry.IsDir() {
461-
continue
460+
err = filepath.WalkDir(absLogsPath, func(path string, d os.DirEntry, walkErr error) error {
461+
if walkErr != nil {
462+
return nil // skip unreadable entries
462463
}
463464

464-
name := entry.Name()
465-
fullPath := filepath.Join(logsPath, name)
465+
// Skip baseline directories — they belong to comparison runs, not the audited run
466+
if d.IsDir() && strings.HasPrefix(d.Name(), "baseline-") {
467+
return filepath.SkipDir
468+
}
466469

467-
// Use absolute path so callers get a directly usable path
468-
absPath, err := filepath.Abs(fullPath)
469-
if err != nil {
470-
auditReportLog.Printf("Failed to resolve absolute path for %s: %v", fullPath, err)
471-
absPath = fullPath
470+
// Skip the base/ directory — it's the full cloned repo, not a log artifact
471+
if d.IsDir() && d.Name() == "base" && path == filepath.Join(absLogsPath, "base") {
472+
return filepath.SkipDir
473+
}
474+
475+
// Skip directories themselves (we only list files)
476+
if d.IsDir() {
477+
return nil
472478
}
473479

474480
fileInfo := FileInfo{
475-
Path: absPath,
476-
Description: describeFile(name),
481+
Path: path,
482+
Description: describeFile(d.Name()),
477483
}
478484

479-
if info, err := os.Stat(fullPath); err == nil {
485+
if info, statErr := os.Stat(path); statErr == nil {
480486
fileInfo.Size = info.Size()
481487
}
482488

483489
files = append(files, fileInfo)
490+
return nil
491+
})
492+
if err != nil {
493+
auditReportLog.Printf("Failed to walk logs directory: %v", err)
484494
}
485495

486496
auditReportLog.Printf("Extracted %d files from logs directory", len(files))

pkg/cli/audit_report_helpers_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ func TestDownloadedFilesInAuditData(t *testing.T) {
171171
// Extract downloaded files
172172
files := extractDownloadedFiles(tmpDir)
173173

174-
// Verify we got all files (directories are now excluded)
175-
expectedCount := len(testFiles)
174+
// Verify we got all files including subdirectory contents
175+
expectedCount := len(testFiles) + 1 // +1 for result.json in agent_output/
176176
if len(files) != expectedCount {
177177
t.Errorf("Expected %d files, got %d", expectedCount, len(files))
178178
}
@@ -320,8 +320,8 @@ func TestAuditReportFileListingIntegration(t *testing.T) {
320320
// Extract downloaded files (simulates what audit command does)
321321
files := extractDownloadedFiles(tmpDir)
322322

323-
// Verify we got all expected files (directories are now excluded)
324-
expectedCount := len(artifacts)
323+
// Verify we got all expected files including subdirectory contents
324+
expectedCount := len(artifacts) + len(dirs) // +3 for file.txt in each subdir
325325
if len(files) != expectedCount {
326326
t.Errorf("Expected %d items, got %d", expectedCount, len(files))
327327
t.Logf("Files found: %v", files)

0 commit comments

Comments
 (0)