Repository navigation
fix: make external-analyzer quality gaps deterministic and correctly attributed - #454
Conversation
…attributed Two defects in external-analyzer quality mode (issue unbound-force#448): - Determinism: BuildQualityFromMappings unioned effects by iterating a Go map of distinct targets (random order), making Gaps/GapHints/AmbiguousEffects and report ordering nondeterministic. Now sorts distinct targets by (package, function) and preserves analysis-result order within each target; total-order tie-breaks on report/summary sorts ensure two runs of `gaze report --analyzer` on identical input produce byte-identical JSON. - Attribution: every gap row was labeled with the report's first target even though Gaps unions effects across all referenced targets. Each gap now carries its owning function via new GapTargets []FunctionTarget on taxonomy.ContractCoverage (JSON gap_targets, external-analyzer-only); markdown Target column, text [owner] prefix, HTML owner prefix, and compact AI payload render the per-gap owner with fallback to report-level label. - Scores (Percentage/CoveredCount/TotalContractual) and Go-native quality path untouched; JSON schema and docs (json-schemas.md, quality.md, AGENTS.md) updated. Closes unbound-force#448 Assisted-by: Muse-Spark-Open-816B-A42B-NVFP4 Generated with AI assistance (Muse-Spark-Open-816B-A42B-NVFP4)
uf-divisor
left a comment
There was a problem hiding this comment.
Council Review: APPROVE WITH ADVISORIES
7/7 reviewers approve — divisor-adversary, divisor-architect, divisor-curator, divisor-entropy, divisor-gaze-testing, divisor-guard, divisor-testing (5 APPROVE, 2 APPROVE WITH ADVISORIES). Canonical verdict: APPROVE WITH ADVISORIES — zero CRITICAL or HIGH findings, two LOW advisories.
This PR fixes both defects from #448 in the external-analyzer quality path: gap order is now deterministic (union targets iterated in sorted (package, function) order; report-level sorts made total via (TestFunction, TestLocation) and (Percentage, TestFunction, TestLocation)), and each gap carries and renders its owning function through the additive, schema-documented gap_targets field with fallback-guarded rendering on every surface. The fix is pinned by dual-layer regression tests (25 in-process repetitions plus 5 cross-process sessions with golden score fixtures proving scores are unchanged), and the Go-native path is functionally untouched. All CI checks pass; pre-flight (ci-aware) PASS with gates run at the frozen head commit.
Advisories (non-blocking)
- LOW (DRY, CS-004) — the per-gap owner guard
i < len(GapTargets) && GapTargets[i].Function != ""is duplicated across three renderers (gapOwnerininternal/quality/report.go,gapOwnerNameininternal/aireport/render_markdown.go,buildQualityHTMLEffectsininternal/quality/html.go); ataxonomy.ContractCoveragemethod would centralize it. Scoped deliberately per design D3. - LOW (test isolation, TC-002) —
TestSession_MultiTargetMappingDeterministicGapOrderdefers sessionClose()inside the 5-iteration loop, stacking deferred closes until function return; explicit per-iteration close would release subprocess handles promptly.
This review was generated by /uf.review-pr (AI-assisted).
| } | ||
| } | ||
|
|
||
| // gapOwner returns the qualified name of the function owning gap i when |
There was a problem hiding this comment.
The per-gap owner guard i < len(GapTargets) && GapTargets[i].Function != "" appears in three renderers — gapOwner here, gapOwnerName in internal/aireport/render_markdown.go, and buildQualityHTMLEffects in internal/quality/html.go — each with the identical fallback to the report target. Three occurrences reach the CS-004 extraction threshold: a method on taxonomy.ContractCoverage (for example GapOwnerName(i)) would centralize the bounds and emptiness checks and give every renderer one owner-resolution path. Design D3 scopes this duplication deliberately, so this is a LOW advisory rather than a blocker.
(divisor-architect, LOW)
| // and any per-process state differ, not just in-process order. | ||
| s := adapter.NewSession(fakeBinaryPath, []string{"--stdio", "--multi-target-mapping"}, rootDir, []string{"./..."}, &stderr, nil) | ||
| defer func() { _ = s.Close() }() | ||
|
|
There was a problem hiding this comment.
defer func() { _ = s.Close() }() sits inside the 5-iteration session loop, so the five deferred closes stack and run only when the test function returns. Each session's analyzer subprocess and its file descriptors stay open across the remaining iterations, and a teardown failure in an early session cannot surface before later sessions have run. Closing explicitly at iteration end — or wrapping the loop body in a function with its own defer — releases each subprocess promptly and isolates teardown failures per session. LOW: the test passes and the handles are released at function exit.
(divisor-gaze-testing, LOW)
Summary
Fixed two defects in external-analyzer quality mode (epic #449 Tier 2, issue #448).
In
internal/adapter/quality.goBuildQualityFromMappings:reportsby (TestFunction, TestLocation) andWorstCoverageTestsby (Percentage, TestFunction, TestLocation). Two runs ofgaze report --analyzeron identical input now produce byte-identical JSON.GapTargets []FunctionTargetontaxonomy.ContractCoverage(JSONgap_targets,omitempty, parallel toGaps, external-analyzer-only). Renderers (markdown gaps-table Target column, text[owner]prefix, HTML owner prefix, compact AI payload) name the per-gap owner with fallback to the report-level label.Quality scores (
Percentage/CoveredCount/TotalContractual) and the Go-native quality path (internal/quality/quality.go,coverage.go) are untouched. Updatedinternal/report/schema.go, docs (json-schemas.md,quality.md),AGENTS.mdRecent Changes, and filed website issue unbound-force/website#497.Closes #448
How to Test
From
openspec/changes/external-analyzer-quality-gap-order-is-n/tasks.mdandspecs/quality-external-analyzer/spec.md:go build ./cmd/gazeandgo build ./...succeed.go test -race -count=1 -short -timeout 15m ./...passes (20 packages).golangci-lint run ./...reports 0 issues.git diff origin/main...HEAD -- internal/quality/quality.go internal/quality/coverage.goshows no changes; Go-native golden/text tests pass unchanged (GapTargets nil → fallback rendering).go test -run TestBuildQualityFromMappings -count=25 -race ./internal/adapter— synthetic multi-target fixture invoked ≥25 times produces byte-identical marshaled JSON; gaps ordered by sorted (package,function) then analysis-result order; WorstCoverageTests tie-break verified.go test -run TestGap -race ./internal/aireport ./internal/quality— markdown table rows, text[owner]lines, HTML items, and compact payloadgap_targetsname the owning function per gap; fallback and escaping verified.go test -run TestReportSchema -race ./internal/report— JSON withgap_targetsvalidates.go test -run TestSessionMultiTarget -race -short ./internal/adapterruns the fake_analyzer with--multi-target-mappingacross repeated sessions and asserts byte-identical order/labels.How to Demo
gaze report --analyzer <analyzer> --format=json ./...twice on identical input anddiffthe outputs — they must be identical.--format=markdown) — each gap row's Target column shows its owning function, not the report's first target.gap_targetsin JSON aligns index-parallel withgapsand carries the correctpackage/functionper gap.Key Files Changed
internal/adapter/quality.go— deterministic target iteration, total-order sorts, per-gap target joininternal/taxonomy/types.go—ContractCoverage.GapTargetsfieldinternal/report/schema.go—gap_targetspropertyinternal/aireport/compact.go,render_markdown.go— per-gap owner rendering + compact payloadinternal/quality/report.go,html.go,quality.html.tmpl— text/HTML per-gap ownerinternal/protocol/testdata/fake_analyzer/main.go—--multi-target-mappingflaginternal/adapter/quality_determinism_test.go,quality_internal_test.go,session_multi_target_test.go— regression/tie-break/resilience testsinternal/adapter/testdata/quality-determinism/*— golden fixturesinternal/aireport/compact_test.go,render_markdown_test.go— renderer testsinternal/quality/html_test.go,report_internal_test.go— renderer testsinternal/report/report_test.go— schema validationdocs/reference/cli/quality.md,docs/reference/json-schemas.md— docsAGENTS.md— Recent Changesopenspec/changes/external-analyzer-quality-gap-order-is-n/*— spec artifactsStats: 29 files changed, 5072 insertions(+), 32 deletions(-) vs
upstream/mainKnown Issues
816139f2-f33c-4d5b-b46e-0861d4401e07— APPROVE WITH ADVISORIES (7 reviewers, 0 blocking findings): 1 LOW advisory — duplicatedgapOwnerName/gapOwnerguard across 3 renderers (design D3) — non-blocking, tracked but not requiring follow-up.This PR was generated by /uf.finale (AI-assisted).