Skip to content

fix: relativize Score.File paths in JSON output#87

Merged
jflowers merged 1 commit intounbound-force:mainfrom
marcusburghardt:fix/relativize-score-file-paths
Apr 13, 2026
Merged

fix: relativize Score.File paths in JSON output#87
jflowers merged 1 commit intounbound-force:mainfrom
marcusburghardt:fix/relativize-score-file-paths

Conversation

@marcusburghardt
Copy link
Copy Markdown
Contributor

Summary

  • Relativizes all Score.File paths against the module root directory after computeScores() returns, converting absolute paths to relative
  • Fixes the recommended_actions section (and all other sections) emitting machine-specific absolute paths like /Users/hbraswel/github/complytime/complyctl/cmd/... in JSON output
  • Adds TestAnalyze_RelativizesFilePaths to verify both Score.File and RecommendedAction.File are relative

Context

Discovered during review of complytime/complyctl#471. The regenerated .gaze/baseline.json contained 20 absolute paths in the new recommended_actions section, while scores, worst_crap, and worst_gaze_crap happened to appear relative depending on how the tool was invoked.

Root cause

computeScores() sets Score.File = stat.Pos.Filename, where the filename comes from gocyclo.Analyze() which walks the filesystem using an absolute moduleDir from os.Getwd(). No relativization was applied before the scores were passed to buildSummary(), which propagates file paths into worst_crap, worst_gaze_crap, and recommended_actions.

Fix

A filepath.Rel(moduleDir, ...) pass is added between computeScores() (which needs absolute paths for lookupCoverage() map matching) and buildSummary() (which propagates paths to all summary sections). This single fix point ensures all downstream consumers get relative paths.

Verification

  • go build ./... — clean
  • golangci-lint run ./internal/crap/... — 0 issues
  • All 6 TestAnalyze_* tests pass (including the new one)
  • 87/88 total tests pass (1 pre-existing failure in TestResolvePackagePaths_InvalidPattern — unrelated go list behavior)

The Analyze function populates Score.File from gocyclo's
Stat.Pos.Filename, which contains absolute paths derived from
filepath.WalkDir with an absolute module root. This causes the
recommended_actions section (and potentially scores, worst_crap,
worst_gaze_crap) to embed machine-specific absolute paths in JSON
output, making baselines non-portable and leaking filesystem structure.

Add a relativization pass after computeScores() returns — converting
all Score.File values from absolute to relative using filepath.Rel
against moduleDir. This is placed after coverage lookups (which need
exact paths) but before buildSummary (which propagates paths to all
summary sections), fixing all downstream consumers in one place.

Assisted-by: OpenCode (claude-opus-4-6)
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
@jflowers jflowers merged commit 6fbaafb into unbound-force:main Apr 13, 2026
5 checks passed
@marcusburghardt marcusburghardt deleted the fix/relativize-score-file-paths branch April 13, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants