Repository navigation
fix: gaze quality produces output and gates on empty results (#103) - #211
Conversation
yvonnedevlinrh
left a comment
There was a problem hiding this comment.
PR #211 Review: fix: gaze quality produces output and gates on empty results (#103)
Verdict: REQUEST CHANGES
Findings
| # | Severity | Finding | File |
|---|---|---|---|
| 1 | HIGH | Missing combined threshold test — no test exercises both --min-contract-coverage and --max-over-specification set simultaneously on empty results. The gate uses || at line 1210; individual tests exist but the combined case is untested. |
cmd/gaze/main_test.go |
| 2 | MEDIUM | SkippedTests always 0 in quality JSON within the gaze report pipeline. BuildPackageSummary(allReports) rebuilds the summary from reports only — skipped tests don't produce reports, so the rebuilt summary has SkippedTests=0. Meanwhile payload.Summary.SkippedTests (set at runner.go:314) has the correct value. Two contradictory truths in the same payload. |
internal/aireport/runner_steps.go:178 |
| 3 | MEDIUM | Missing edge case test: SkippedTests > len(SkippedTestNames) divergence. The defensive guard at report.go:226 and main.go:1196 handles this, but no test verifies the invariant-violation scenario. |
internal/quality/report.go, cmd/gaze/main.go |
| 4 | MEDIUM | Missing multi-package mixed BDD + normal scenario test. When some packages have BDD tests (zero reports) and others have well-tested packages (non-zero reports), the merged result should carry both skipped tests and quality reports. This combination is not tested. | cmd/gaze/main_test.go |
| 5 | LOW | BuildPackageSummary name suggests a complete summary but produces a partial one — it does not set SkippedTests or SkippedTestNames. This naming gap is the root cause of finding #2. |
internal/quality/quality.go:271 |
| 6 | LOW | DRY violation: duplicated truncation constant. maxSkippedTestDisplay = 20 in main.go:1169 and maxSkippedTestNames = 20 in report.go:210. The comment acknowledges the mirror but the constant should ideally be defined once. |
cmd/gaze/main.go, internal/quality/report.go |
| 7 | LOW | Error message wording inconsistency with gaze crap pattern. CRAP uses "no functions analyzed — cannot evaluate thresholds", quality uses "quality gate failed: no test-target pairs resolved, but threshold flags are set". Different structure and tone. |
cmd/gaze/main.go:1211-1213 |
| 8 | LOW | totalTestFuncs computed but unused in JSON format branch. The variable is only used in the default (text) case of the format switch. |
cmd/gaze/main.go:1179 |
| 9 | LOW | WriteJSON error not wrapped with context (CS-006). return err at line 1186 loses the "writing empty quality JSON" context. |
cmd/gaze/main.go:1186 |
| 10 | LOW | Defensive guard limit > len(merged.SkippedTestNames) is unreachable in practice — SkippedTests always equals len(SkippedTestNames) given the current Assess() implementation. Not a bug, but dead code. |
cmd/gaze/main.go:1196 |
Blocking (must fix before merge)
Finding #1 — Add a combined threshold test:
func TestRunQuality_EmptyResults_BothThresholds_ExitsNonZero(t *testing.T) {
var stdout, stderr bytes.Buffer
err := runQuality(qualityParams{
patterns: []string{"...bddstyle"},
format: "text",
minContractCoverage: 10,
maxOverSpecification: 5,
stdout: &stdout,
stderr: &stderr,
})
if err == nil {
t.Fatal("expected error when both thresholds set with zero results")
}
if !strings.Contains(err.Error(), "quality gate failed") {
t.Errorf("expected 'quality gate failed', got: %v", err)
}
}Finding #2 — Patch the rebuilt summary with skipped test data. In runQualityStep (internal/aireport/runner_steps.go), after line 178:
summary := quality.BuildPackageSummary(allReports)
summary.SkippedTests = totalSkipped // <-- add thisThis ensures the quality JSON embedded in the payload has a consistent skipped_tests value matching payload.Summary.SkippedTests.
Strengths
- Excellent data flow design following the established
SSADegradedpropagation pattern - Clean package boundaries — business logic in
internal/quality/, CLI incmd/gaze/ - Solid BDD test fixture simulating Ginkgo registration pattern without external dependencies
- 13+ new tests with deep assertions across 3 layers (core, CLI, report rendering)
- Schema, types, and compact payload all correctly extended
- Gate semantics correct (zero-means-disabled)
- Constitution compliance: all 4 principles PASS
- No governance gates modified
- Breaking change (exit 1 where previously exit 0) is intentional and documented
- Fix skipped test data missing from report pipeline quality JSON: BuildPackageSummary only aggregates report-level data, so SkippedTests/SkippedTestNames are now set post-hoc in runQualityStep and propagated through ReportSummary (#2, unbound-force#5) - Add combined threshold test for --min-contract-coverage + --max-over-specification both set on empty results (#1) - Add divergence edge case test: SkippedTests > len(SkippedTestNames) verifies defensive guard prevents out-of-bounds (unbound-force#3) - Extract shared MaxSkippedTestDisplay constant from quality package, replacing duplicate magic 20 in main.go and report.go (unbound-force#6) - Move totalTestFuncs computation inside text format branch where it is actually used (unbound-force#8) - Wrap WriteJSON/WriteText errors with context per CS-006 (unbound-force#9) - Filed follow-up issue unbound-force#219 for multi-package mixed BDD+normal scenario test (unbound-force#4)
…nbound-force#4, unbound-force#7) - Align quality zero-result error message to match gaze crap pattern: 'no test-target pairs resolved — cannot evaluate thresholds' (unbound-force#7) - Add TestMergeSummaries_SkippedTestsDivergence to exercise defensive guard when SkippedTests > len(SkippedTestNames) (unbound-force#3) - Add TestMergeSummaries_MultiPackage_AggregatesSkipped for mergeSummaries aggregation coverage - Add TestRunQuality_MixedBDDAndNormalPackages for mixed BDD + normal multi-package scenario (unbound-force#4) - Update 3 existing test assertions for new error message wording
jflowers
left a comment
There was a problem hiding this comment.
Feedback Response
Thanks for the thorough review! Here is the disposition of each finding:
Addressed in this push (commit 5a4557c)
#3 (MEDIUM) — SkippedTests divergence test: Added TestMergeSummaries_SkippedTestsDivergence which constructs a summary where SkippedTests=5 but only 2 names, then exercises the text output path to verify the defensive guard prevents a panic. Also added TestMergeSummaries_MultiPackage_AggregatesSkipped for general mergeSummaries coverage.
#4 (MEDIUM) — Mixed BDD + normal multi-package test: Added TestRunQuality_MixedBDDAndNormalPackages which runs welltested (produces reports) and bddstyle (all tests skipped) together, verifying the merged output contains both analyzed test data and skipped test names.
#7 (LOW) — Error message wording: Aligned to match gaze crap pattern. Now reads: "no test-target pairs resolved — cannot evaluate thresholds (--min-contract-coverage=N, --max-over-specification=N)". Existing test assertions updated to match.
Already addressed in current code
#1 (HIGH) — Combined threshold test: TestRunQuality_EmptyResults_BothThresholds_ExitsNonZero already exists at main_test.go:1396. It sets both minContractCoverage: 10 and maxOverSpecification: 5, asserts cannot evaluate thresholds in the error, and verifies both flag values appear in the error message.
#2 (MEDIUM) — SkippedTests always 0 in report pipeline: The current code at runner_steps.go:185-186 already patches the summary post-hoc: summary.SkippedTests = totalSkipped / summary.SkippedTestNames = allSkippedNames. Lines 207-208 propagate these into qualityStepResult, and runner.go:314-315 copies them to the payload. TestRunQualityStep_DI_SkippedTestsPropagation verifies end-to-end flow. This may have been fixed after the reviewed commit.
#6 (LOW) — DRY truncation constant: There is a single definition at quality.MaxSkippedTestDisplay = 20 (report.go:211). The CLI references it via maxSkippedTestDisplay := quality.MaxSkippedTestDisplay (main.go:1166). No duplication exists.
#9 (LOW) — WriteJSON error wrapping: Line 1182 already wraps: return fmt.Errorf("writing empty quality JSON: %w", err). This follows CS-006.
Kept as-is (with rationale)
#5 (LOW) — BuildPackageSummary naming: The GoDoc at quality.go:270-274 explicitly documents this design: "Skipped test data ... must be set by the caller post-hoc, since skipped tests do not produce QualityReport entries." The function name is accurate for what it does; callers complete the picture.
#8 (LOW) — totalTestFuncs scope: On re-examination, totalTestFuncs is already declared inside the default: case of the format switch (line 1185), not in shared scope. It is not visible to the case "json": branch. No change needed.
#10 (LOW) — Defensive guard: The guard at line 1193 is intentional defense-in-depth for the invariant violation that #3 now tests. Removing it would create risk if a future caller violates the invariant.
…force#103) Addresses issue unbound-force#103: gaze quality produces no output and exits 0 on BDD suites and unresolvable targets. Artifacts: - proposal.md: four-link silent-skip chain root cause analysis - design.md: 7 decisions (D1-D7) with pipeline propagation chain - specs/quality-empty-results-gate.md: 17 GIVEN/WHEN/THEN scenarios - tasks.md: 27 tasks across 6 sections Spec review council: all 7 themes resolved (pipeline propagation, gate condition semantics, truncation, no-test-files case, JSON format, fixture approach, task clarity).
…-force#103) Add SkippedTests and SkippedTestNames fields to PackageSummary to track test functions that could not be resolved to target functions (e.g., Ginkgo/BDD suites using dynamic dispatch invisible to SSA). quality.Assess now counts and names skipped test functions at the len(targets) == 0 continue site. runQuality prints structured stdout summary when allReports is empty (total test count, skipped names truncated at 20, --target hint), returns error when quality thresholds are set, and produces valid JSON for --format=json. Add writeSkippedTests section to quality.WriteText with 20-name truncation. Update mergeSummaries to aggregate skipped test data. Update JSON Schema. Propagate through report pipeline: runQualityForPackage returns 3 values, qualityStepResult.SkippedTests, ReportSummary.SkippedTests, compactSummary.SkippedTests, compactPackageSummary.SkippedTests/SkippedTestNames. Add testdata/src/bddstyle/ fixture. 13 new tests across 3 packages. Closes unbound-force#103
- Fix potential slice bounds panic in runQuality truncation by adding defensive len() guard (Adversary MEDIUM) - Extract maxSkippedTestDisplay constant to eliminate magic number 20 duplication across main.go and report.go (Architect MEDIUM) - Fix misleading GoDoc on SkippedTestNames - clarify truncation is display-only, JSON includes all names (Adversary MEDIUM) - Strengthen TestAssess_SkippedTests with exact count (==2) and specific name assertions instead of inequality guards (Tester HIGH) - Add content verification to TestMergeSummaries_SkippedTests (Tester HIGH) - Verify quality_summary.skipped_tests in JSON output test (Tester HIGH) - Add TestRunQualityStep_DI_SkippedTestsPropagation for pipeline coverage (Tester HIGH) - Add header count assertion to truncation_at_20 subtest (Tester MEDIUM)
- Fix skipped test data missing from report pipeline quality JSON: BuildPackageSummary only aggregates report-level data, so SkippedTests/SkippedTestNames are now set post-hoc in runQualityStep and propagated through ReportSummary (#2, unbound-force#5) - Add combined threshold test for --min-contract-coverage + --max-over-specification both set on empty results (#1) - Add divergence edge case test: SkippedTests > len(SkippedTestNames) verifies defensive guard prevents out-of-bounds (unbound-force#3) - Extract shared MaxSkippedTestDisplay constant from quality package, replacing duplicate magic 20 in main.go and report.go (unbound-force#6) - Move totalTestFuncs computation inside text format branch where it is actually used (unbound-force#8) - Wrap WriteJSON/WriteText errors with context per CS-006 (unbound-force#9) - Filed follow-up issue unbound-force#219 for multi-package mixed BDD+normal scenario test (unbound-force#4)
…nbound-force#4, unbound-force#7) - Align quality zero-result error message to match gaze crap pattern: 'no test-target pairs resolved — cannot evaluate thresholds' (unbound-force#7) - Add TestMergeSummaries_SkippedTestsDivergence to exercise defensive guard when SkippedTests > len(SkippedTestNames) (unbound-force#3) - Add TestMergeSummaries_MultiPackage_AggregatesSkipped for mergeSummaries aggregation coverage - Add TestRunQuality_MixedBDDAndNormalPackages for mixed BDD + normal multi-package scenario (unbound-force#4) - Update 3 existing test assertions for new error message wording
5a4557c to
7f9b2b7
Compare
There was a problem hiding this comment.
Review: Correctness, Contract Fidelity, Caller Impact, Reachability
CI: all 5 checks pass. All callers of changed functions are correctly updated. No missed call sites.
Verdict: APPROVE
Two LOW non-blocking observations below. The implementation correctly fixes the silent exit-0 bug, all data flows are verified end-to-end, and all new branches are reachable and tested.
Findings
| # | Severity | Category | File | Summary |
|---|---|---|---|---|
| 1 | LOW | Coverage gap | cmd/gaze/main.go:1199 |
CLI truncation path duplicates writeSkippedTests logic without its own integration test |
| 2 | LOW | UX | cmd/gaze/main.go:1185-1186 |
"Quality: 0 of 0" output is ambiguous but improves on prior silent behavior |
Finding 1 — CLI truncation path lacks integration test (LOW)
The "... and %d more" branch at cmd/gaze/main.go:1199-1201 is a copy of writeSkippedTests truncation logic. The truncation_at_20 subtest validates writeSkippedTests (report.go), but the CLI's copy at main.go:1199 is only exercised indirectly. Not blocking — the logic is identical — but the duplication itself is the concern.
Finding 2 — "Quality: 0 of 0" is ambiguous (LOW)
When a package has no test functions, Assess returns early with TotalTests=0, SkippedTests=0, producing:
Quality: 0 of 0 test functions mapped to a target
This doesn't tell the user whether there are no tests or no packages. Not a regression (prior behavior was silent exit-0), so non-blocking.
Caller Impact Verification
All callers traced and verified correct:
Reachability Verification
All new branches are reachable:
- Fix skipped test data missing from report pipeline quality JSON: BuildPackageSummary only aggregates report-level data, so SkippedTests/SkippedTestNames are now set post-hoc in runQualityStep and propagated through ReportSummary (#2, #5) - Add combined threshold test for --min-contract-coverage + --max-over-specification both set on empty results (#1) - Add divergence edge case test: SkippedTests > len(SkippedTestNames) verifies defensive guard prevents out-of-bounds (#3) - Extract shared MaxSkippedTestDisplay constant from quality package, replacing duplicate magic 20 in main.go and report.go (#6) - Move totalTestFuncs computation inside text format branch where it is actually used (#8) - Wrap WriteJSON/WriteText errors with context per CS-006 (#9) - Filed follow-up issue #219 for multi-package mixed BDD+normal scenario test (#4)
- Fix skipped test data missing from report pipeline quality JSON: BuildPackageSummary only aggregates report-level data, so SkippedTests/SkippedTestNames are now set post-hoc in runQualityStep and propagated through ReportSummary (unbound-force#2, unbound-force#5) - Add combined threshold test for --min-contract-coverage + --max-over-specification both set on empty results (unbound-force#1) - Add divergence edge case test: SkippedTests > len(SkippedTestNames) verifies defensive guard prevents out-of-bounds (unbound-force#3) - Extract shared MaxSkippedTestDisplay constant from quality package, replacing duplicate magic 20 in main.go and report.go (unbound-force#6) - Move totalTestFuncs computation inside text format branch where it is actually used (unbound-force#8) - Wrap WriteJSON/WriteText errors with context per CS-006 (unbound-force#9) - Filed follow-up issue unbound-force#219 for multi-package mixed BDD+normal scenario test (unbound-force#4)
…nbound-force#4, unbound-force#7) - Align quality zero-result error message to match gaze crap pattern: 'no test-target pairs resolved — cannot evaluate thresholds' (unbound-force#7) - Add TestMergeSummaries_SkippedTestsDivergence to exercise defensive guard when SkippedTests > len(SkippedTestNames) (unbound-force#3) - Add TestMergeSummaries_MultiPackage_AggregatesSkipped for mergeSummaries aggregation coverage - Add TestRunQuality_MixedBDDAndNormalPackages for mixed BDD + normal multi-package scenario (unbound-force#4) - Update 3 existing test assertions for new error message wording
Summary
Fixes #103 —
gaze qualitypreviously produced no stdout output and exited 0 whenall test functions had unresolvable targets (e.g., Ginkgo/BDD suites using dynamic
dispatch). This made CI pipelines silently pass on unanalyzable packages.
Changes:
quality.AssesswithSkippedTests/SkippedTestNamesfields on
taxonomy.PackageSummaryskipped test names (truncated at 20) and
--targethintgaze reportpipeline(
qualityStepResult→ReportSummary→ compact AI payload)skipped_testsandskipped_test_namesfieldsbddstyletest fixture simulating Ginkgo's dynamic dispatch patternHow to Test
How to Demo
Build gaze:
go build ./cmd/gazeRun against the bddstyle fixture (simulates Ginkgo):
Observe: stdout shows "Quality: 0 of 2 test functions mapped to a target",
lists
TestCalculatorSuiteandTestFormatSuite, and shows the--targethint.Run with threshold flag:
Observe: same summary output, then exit 1 with gate failure error.
Run with JSON format:
Observe: valid JSON with empty
quality_reportsarray andquality_summarycontaining
skipped_tests: 2andskipped_test_names.Key Files Changed
internal/taxonomy/types.goSkippedTests,SkippedTestNamestoPackageSummaryinternal/quality/quality.goAssessinternal/quality/report.gowriteSkippedTestssection to text outputcmd/gaze/main.gomergeSummariesupdateinternal/report/schema.gointernal/aireport/runner_steps.goqualityStepResult.SkippedTests, 3-returnrunQualityForPackageinternal/aireport/payload.goReportSummary.SkippedTestsinternal/aireport/runner.gointernal/aireport/compact.gointernal/quality/testdata/src/bddstyle/cmd/gaze/main_test.gointernal/quality/quality_test.gointernal/quality/report_internal_test.gointernal/aireport/runner_steps_test.goopenspec/changes/quality-empty-results-gate/AGENTS.mdKnown Issues
The following findings from the review council were acknowledged but not resolved:
--max-over-specification+--min-contract-coverageon empty results (OR logic is simple enough; individual flag tests exist)compactPackageSummary.SkippedTestNamesfield missing GoDoc commentgaze crappatternThis PR was generated by /uf.finale (AI-assisted).