diff --git a/pkg/cli/audit_report.go b/pkg/cli/audit_report.go index 9c4d7bf223e..b591e0822b5 100644 --- a/pkg/cli/audit_report.go +++ b/pkg/cli/audit_report.go @@ -339,13 +339,6 @@ func extractDownloadedFiles(logsPath string) []FileInfo { return files } - // Get current working directory to calculate relative paths - cwd, err := os.Getwd() - if err != nil { - auditReportLog.Printf("Failed to get current directory: %v", err) - cwd = "" - } - for _, entry := range entries { // Skip directories if entry.IsDir() { @@ -355,16 +348,15 @@ func extractDownloadedFiles(logsPath string) []FileInfo { name := entry.Name() fullPath := filepath.Join(logsPath, name) - // Calculate relative path from workspace root (current working directory) - relativePath := fullPath - if cwd != "" { - if relPath, err := filepath.Rel(cwd, fullPath); err == nil { - relativePath = relPath - } + // Use absolute path so callers get a directly usable path + absPath, err := filepath.Abs(fullPath) + if err != nil { + auditReportLog.Printf("Failed to resolve absolute path for %s: %v", fullPath, err) + absPath = fullPath } fileInfo := FileInfo{ - Path: relativePath, + Path: absPath, Description: describeFile(name), } diff --git a/pkg/cli/audit_report_helpers_test.go b/pkg/cli/audit_report_helpers_test.go index 49e8f9c5e7a..6e93c090f6b 100644 --- a/pkg/cli/audit_report_helpers_test.go +++ b/pkg/cli/audit_report_helpers_test.go @@ -177,10 +177,17 @@ func TestDownloadedFilesInAuditData(t *testing.T) { t.Errorf("Expected %d files, got %d", expectedCount, len(files)) } + // Verify all paths are absolute + for _, file := range files { + if !filepath.IsAbs(file.Path) { + t.Errorf("Expected absolute path, got relative path: %s", file.Path) + } + } + // Verify specific files have correct attributes fileMap := make(map[string]FileInfo) for _, file := range files { - // Use basename for lookup since paths are now relative to workspace root + // Use basename for lookup since we only need to find files by name basename := filepath.Base(file.Path) fileMap[basename] = file } @@ -323,7 +330,7 @@ func TestAuditReportFileListingIntegration(t *testing.T) { // Build a map for easy lookup fileMap := make(map[string]FileInfo) for _, f := range files { - // Use basename for lookup since paths are now relative to workspace root + // Use basename for lookup since we only need to find files by name basename := filepath.Base(f.Path) fileMap[basename] = f }