Skip to content

fix: gaze quality produces output and gates on empty results (#103) - #211

Merged
jflowers merged 5 commits into
unbound-force:mainfrom
jflowers:opsx/quality-empty-results-gate
Aug 13, 2026
Merged

jflowers merged 5 commits into
unbound-force:mainfrom
jflowers:opsx/quality-empty-results-gate

Conversation

@jflowers

Copy link
Copy Markdown
Collaborator

Summary

Fixes #103 — gaze quality previously produced no stdout output and exited 0 when
all test functions had unresolvable targets (e.g., Ginkgo/BDD suites using dynamic
dispatch). This made CI pipelines silently pass on unanalyzable packages.

Changes:

  • Track skipped test functions in quality.Assess with SkippedTests/SkippedTestNames
    fields on taxonomy.PackageSummary
  • Print structured summary to stdout when zero test-target pairs are resolved, including
    skipped test names (truncated at 20) and --target hint
  • Return error (exit 1) when quality threshold flags are set but no pairs were resolved
  • Add skipped test section to text report output for partial-success cases
  • Propagate skipped test count through the gaze report pipeline
    (qualityStepResult → ReportSummary → compact AI payload)
  • Update Quality JSON Schema with skipped_tests and skipped_test_names fields
  • Add bddstyle test fixture simulating Ginkgo's dynamic dispatch pattern

How to Test

# Run the full short test suite (includes 14 new tests)
go test -race -count=1 -short ./...

# Run just the new tests
go test -race -count=1 -run "TestAssess_SkippedTests|TestMergeSummaries_SkippedTests|TestRunQuality_EmptyResults|TestWriteSkippedTests|TestRunQualityStep_DI_SkippedTests" ./...

# Verify lint
golangci-lint run

# Manual verification: run against a BDD-style package (if available)
go run ./cmd/gaze quality ./path/to/ginkgo/pkg/
# Expected: stdout shows "Quality: 0 of N test functions mapped to a target"

# Manual verification: threshold gate
go run ./cmd/gaze quality --min-contract-coverage=50 ./path/to/ginkgo/pkg/
# Expected: exit 1 with "quality gate failed" error

How to Demo

  1. Build gaze: go build ./cmd/gaze

  2. Run against the bddstyle fixture (simulates Ginkgo):

    ./gaze quality ./internal/quality/testdata/src/bddstyle
    

    Observe: stdout shows "Quality: 0 of 2 test functions mapped to a target",
    lists TestCalculatorSuite and TestFormatSuite, and shows the --target hint.

  3. Run with threshold flag:

    ./gaze quality --min-contract-coverage=50 ./internal/quality/testdata/src/bddstyle
    

    Observe: same summary output, then exit 1 with gate failure error.

  4. Run with JSON format:

    ./gaze quality --format=json ./internal/quality/testdata/src/bddstyle
    

    Observe: valid JSON with empty quality_reports array and quality_summary
    containing skipped_tests: 2 and skipped_test_names.

Key Files Changed

File What Changed
internal/taxonomy/types.go Added SkippedTests, SkippedTestNames to PackageSummary
internal/quality/quality.go Accumulate skipped tests in Assess
internal/quality/report.go Added writeSkippedTests section to text output
cmd/gaze/main.go Empty-result gate, stdout summary, mergeSummaries update
internal/report/schema.go JSON Schema update for new fields
internal/aireport/runner_steps.go qualityStepResult.SkippedTests, 3-return runQualityForPackage
internal/aireport/payload.go ReportSummary.SkippedTests
internal/aireport/runner.go Pipeline wiring
internal/aireport/compact.go Compact payload fields for AI reporter
internal/quality/testdata/src/bddstyle/ BDD-style test fixture
cmd/gaze/main_test.go 7 new tests for empty-result gate
internal/quality/quality_test.go 2 new tests for skipped test tracking
internal/quality/report_internal_test.go 4 new subtests for text rendering
internal/aireport/runner_steps_test.go Pipeline propagation test + 7 updated tests
openspec/changes/quality-empty-results-gate/ Spec artifacts (proposal, design, specs, tasks)
AGENTS.md Recent changes entry

Known Issues

The following findings from the review council were acknowledged but not resolved:

  • LOW: No test for combined --max-over-specification + --min-contract-coverage on empty results (OR logic is simple enough; individual flag tests exist)
  • LOW: compactPackageSummary.SkippedTestNames field missing GoDoc comment
  • MEDIUM: Error message says "quality gate failed" but spec says "cannot evaluate thresholds" — minor wording inconsistency with gaze crap pattern
  • MEDIUM: No multi-package BDD scenario test (single-package BDD test covers the core path)

This PR was generated by /uf.finale (AI-assisted).

@jflowers jflowers self-assigned this Aug 11, 2026
@jflowers jflowers moved this to Ready for Review 👀 in Unbound Force Planning Aug 11, 2026

@yvonnedevlinrh yvonnedevlinrh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 this

This 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 SSADegraded propagation pattern
  • Clean package boundaries — business logic in internal/quality/, CLI in cmd/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

@jflowers jflowers moved this from Ready for Review 👀 to In Review 🏁 in Unbound Force Planning Aug 12, 2026
jflowers added a commit to jflowers/gaze that referenced this pull request Aug 12, 2026
- 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)
jflowers added a commit to jflowers/gaze that referenced this pull request Aug 13, 2026
…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 jflowers left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jflowers jflowers self-assigned this Aug 13, 2026
…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
@jflowers
jflowers force-pushed the opsx/quality-empty-results-gate branch from 5a4557c to 7f9b2b7 Compare August 13, 2026 13:14

@yvonnedevlinrh yvonnedevlinrh left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

@jflowers
jflowers merged commit 8ed66a8 into unbound-force:main Aug 13, 2026
5 checks passed
jflowers added a commit that referenced this pull request Aug 13, 2026
- 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)
@yvonnedevlinrh yvonnedevlinrh moved this from In Review 🏁 to Done ✔️ in Unbound Force Planning Aug 17, 2026
em-redhat pushed a commit to em-redhat/gaze that referenced this pull request Sep 1, 2026
- 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)
em-redhat pushed a commit to em-redhat/gaze that referenced this pull request Sep 1, 2026
…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
jflowers deleted the opsx/quality-empty-results-gate branch November 15, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

Bug: gaze quality produces no output and exits 0 on Ginkgo/BDD suites and unresolvable targets

2 participants