Skip to content

Bug: crap discards the coverage profile and aborts when go test exits non-zero #101

Closed

Description

@trevor-vaughan
  • Severity: Critical
  • Status: Confirmed — reproduced first-hand on 2026-06-08
  • Component: internal/crap/analyze.go → generateCoverProfile (lines 158–188)
  • Affected commands: gaze crap, gaze report, gaze self-check
  • Audited commit: 1a06131 (main)
  • Target codebase: complytime-labs/crosscodex @ dae5cc4
  • Evaluation model: Claude Opus 4.6 (1M context) — claude-opus-4-6 (analysis and parallel audit subagents)

Summary

gaze crap ./... computes coverage by shelling out to go test -coverprofile.
If that single invocation exits non-zero — because one package fails to
build, or one test fails — gaze deletes the coverage profile and returns an
error, producing zero output for the entire run. go test writes a
complete, usable coverprofile for every package that did pass; gaze throws it
away. A test-quality tool therefore refuses to analyze any repository in the
extremely common state of "one failing test" or "one non-building package."

Reproduction

Real-world target: github.com/complytime-labs/crosscodex (one package,
internal/testgrpc, imports an uncommitted generated package, so
go test ./... fails to build it).

$ cd /tmp/crosscodex && GOTOOLCHAIN=auto gaze crap ./... >out.txt 2>err.txt
$ echo "exit=$?  stdout_bytes=$(wc -c <out.txt)"
exit=1  stdout_bytes=0
$ tail -3 err.txt
ok      github.com/complytime-labs/crosscodex/pkg/tlsconfig/pki   coverage: 82.0% of statements
ok      github.com/complytime-labs/crosscodex/pkg/vectordb        coverage: 37.8% of statements
FAIL

The same tool on any single clean package works perfectly:

$ gaze crap ./pkg/tlsconfig
# → full 34-function CRAP table, exit 0

So ~30 packages that tested fine produced no report solely because one
unrelated package would not build.

Expected vs Actual

  • Expected: Use the coverprofile that go test wrote, report scores for the
    packages that were measured, and warn that some packages could not be tested.
  • Actual: Empty stdout, exit 1, and the go test failure text dumped to
    stderr.

Root cause

internal/crap/analyze.go:179-185:

cmd := exec.Command("go", args...)
cmd.Dir = moduleDir
output, err := cmd.CombinedOutput()
if err != nil {
    _ = os.Remove(profilePath)   // <-- deletes the usable partial profile
    return "", fmt.Errorf("go test failed: %s\n%s", err, string(output))
}

go test's exit code conflates "the test binary reported a failure" with "no
data is available." The coverprofile at profilePath is fully written before
go test returns non-zero.

Impact

This is the single largest usability defect in the tool and the most likely
reason a first-time user pointed at a real repo "gets nothing." Running with
./... — the form the README and CI guide recommend — fails closed on any repo
that is not 100% green and 100% building.

Suggested fix

After cmd.Run(), check whether profilePath is non-empty and parseable. If
so, proceed with the partial data and emit a warning listing what failed,
instead of aborting. Only return a hard error when no profile was produced at
all. Consider separating "build failure" (fatal) from "test failure" (warn and
continue) by inspecting the output.

Activity

  1. added
    bug
    on Jun 8, 2026
  2. jflowers commented on Jun 16, 2026

    @jflowers
    Collaborator

    Triage Summary

    Verdict: Valid bug — unanimous across all 5 review agents.
    Category: Bug (error handling defect)
    Objectivity: Objective — root cause verified at internal/crap/analyze.go:179-185

    Analysis

    The panel confirms this is a genuine error handling gap in generateCoverProfile. The function unconditionally deletes the coverage profile and returns an error when go test exits non-zero, discarding valid partial coverage data that go test -coverprofile writes for all successfully-tested packages.

    Key findings:

    • Constitution violations: This behavior violates Principle II (Minimal Assumptions — assumes an all-green test suite) and Principle III (Actionable Output — zero output instead of partial results with warnings).
    • Architectural inconsistency: The project has an established graceful degradation pattern for SSA builder failures (SSADegraded, SSADegradedPackages) that returns partial results instead of aborting. The coverage profile handling should follow the same pattern.
    • Blast radius: Affects gaze crap, gaze report (when no --coverprofile is supplied), and gaze self-check (which has no workaround).
    • Downstream resilience: ParseCoverProfile and computeScores already handle partial coverage data gracefully — only generateCoverProfile needs to change.
    • Test gap: generateCoverProfile is currently untested; all existing Analyze tests bypass it via pre-supplied profiles.

    Recommended fix approach (following the SSA degradation pattern):

    1. After cmd.CombinedOutput() returns non-zero, check if profilePath exists and has non-zero size
    2. Attempt cover.ParseProfiles(profilePath) — if valid, proceed with partial data
    3. Emit a warning to stderr listing failed packages (extractable from go test output)
    4. Add CoverageDegradedPackages []string to crap.Summary (mirroring SSADegradedPackages)
    5. Only delete the profile and return a hard error when no usable data was produced

    This triage was performed by the Divisor review panel.

  3. moved this from Backlog to Ready 🚀 in Unbound Force Planningon Jun 16, 2026
  4. moved this from Ready 🚀 to In Progress 📋 in Unbound Force Planningon Jun 16, 2026
  5. self-assigned this
    on Jun 16, 2026
  6. moved this from In Progress 📋 to Done ✔️ in Unbound Force Planningon Jul 16, 2026
  7. added 2 commits that reference this issue on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions