Skip to content

test: hold the coverage gate's unfloored set to a recorded reason (#199) - #359

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/coverage-floors-unlisted-199
Aug 5, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/coverage-floors-unlisted-199

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #199.

The invariant the issue asks for: the set scripts/coverage-gate.sh reports as unfloored matches the set .coverage-floors' header explains, exactly. That equality is what's worth having — not a particular coverage number.

Why a test and not one round of editing

The gate already names every unfloored package in every run, so nothing about the situation was hidden. What a run cannot supply is the only thing that matters: whether an absence was decided or overlooked. That distinction lives in a hand-written comment block — the same shape labels_test.go's comment describes, a description of state held somewhere else with nothing comparing the two. It had drifted three ways.

Four of the issue's premises did not survive measurement

premise what's actually true
the gate has a --report-unlisted flag it does not; line 20's comment names one, but the reporting is unconditional. Passing it makes the script read the flag as the profile path
pkg/optimization is unexplained it does not exist — 4d10da0 deleted pkg/optimization/interfaces.go. Its explanation outlived it by two releases
pkg/types and tests need "a floor or a doc" neither is in the gate's report and neither can be: no statements, so go test says coverage: [no statements] and no profile line is emitted. A floor fails the gate — pkg/types 50 hits the stale-floor arm at coverage-gate.sh:97-105 and exits 1. Verified, not reasoned. One branch of the issue's choice is unavailable for them
"eight packages, five explained" wrong in both numbers. CI's profile yields six; the header explained five while claiming four. Two of the local eight are Go files vendored inside node_modules by two copies of the npm flatted package, which go list ./... reports as module packages on any machine that has run npm ci. CI's coverage job installs no npm deps

0.0% is an artifact, not a measurement

go test -coverprofile instruments only the package under test, so a support package's statements produce count-0 profile lines even when a sibling suite executes every one of them. Measured with -coverpkg pointed at each from its consumers:

internal/cache/cachetest        0.0% reported, 81.9% under internal/cache + internal/cache/redis
internal/testhttp               0.0% reported, 75.6% under internal/adapter
pkg/compression                 0.0% reported, 88.9% under internal/compression
pkg/archive                     0.0% reported, 48.6% under internal/archive
internal/awsrates/…/offertest   0.0% reported, 48.9% under internal/awsrates/...

A floor for any of them would have to be 0 to pass, and 0 is not a gate. Those numbers are now in the header.

Two findings the issue did not have

  • pkg/archive was described as "dead code pending a decision (Part 4)". internal/archive imports it from five files. The claim was wrong in the direction that matters: it read as a reason not to test a package that a floored package depends on.
  • sdks/c is unfloorable for a different reason than the other five. Its number depends on CGO_ENABLED, because main.go is a CgoFile — so CGO_ENABLED=0 go test ./sdks/c/ does not fall back to a tag-excluded variant, it fails to compile (undefined: codeFromErr, undefined: fillCStr). CI sets CGO_ENABLED=0 for the cross-build matrix and the release build, so a floor there would be a claim about a file set part of CI never compiles.

How the test works

TestUnfloorablePackagesAreExplained runs coverage-gate.sh rather than re-deriving the unlisted set. The gate's derivation has its own recorded failure: the module path was once a literal inside its awk program, a rename stopped it matching anything, and every package reported "no floor set" while the run failed naming nothing. A test re-deriving from go list would have been green throughout that. For the same reason the module path here is read from go.mod, not held as a const.

The script needs a profile, and a real one takes twenty minutes, so it's synthesized from go list + go/parser: one line per package with at least one statement, count 1 throughout. The counts are fiction and it doesn't matter — the unlisted set is a difference of key sets, so presence is all that decides membership. Checked against CI's own coverage.out from the last green run on main: same six packages either way. Two bugs found that way rather than by argument — CgoFiles is a separate go list field (so sdks/c parsed as empty), and go list's trailing empty fields collapse under a plain separator (so tests, one of the three packages the header has to classify, was unparseable).

The header's declared set is marked, not inferred:

# no-floor: <pkg>       the gate reports this package as unfloored, and that is intended
# no-statements: <pkg>  this package has no statements, so the gate cannot report it at all

The first parser inferred the set from indented path-shaped tokens and reported six packages the header names for unrelated reasons — internal/fuse and pkg/errors from the "furthest from 80%" table, internal/cache and internal/adapter from the -coverpkg measurements — as stale entries. Prose has no parseable structure, and a test that pretends otherwise fails on prose edits that aren't drift.

Both directions fail, and the stale-entry arm splits three ways because each cause wants a different fix: the package doesn't exist (delete the entry), it has no statements (use # no-statements:), or it has a floor now (move to a per-floor note). That split came from a false message — marking pkg/types as # no-floor: reported "no such package exists in this module", which is untrue.

TestNoStatementPackagesStillHaveNone holds the three # no-statements: claims, which are otherwise unfalsifiable: if pkg/types grew a function body it would start producing profile lines and the header entry would simply be false. test/benchmarks is checked by stat, since //go:build benchmark keeps go list ./... from reporting it at all.

Verification

  • mutation-verified 6/6 — dropped marker, marker for a floored package, marker for a nonexistent package, a function body added to pkg/types, a genuinely new unfloored package, a package marked both ways
  • go test -race -timeout 25m ./... exit 0 · go build ./... · go vet · gofmt -l clean
  • golangci-lint --new-from-merge-base=origin/main ./internal/config/... — 0 issues
  • gate against CI's real profile: same six packages, 35 packages at/above floor
  • markdownlint CHANGELOG.md — 361, byte-identical to the merge base

No floor values changed.

Follow-ups worth filing

pkg/archive's uncovered half — metadata.go's index construction, ~19 statements internal/archive doesn't exercise — and a floor for sdks/c once the coverage job's cgo posture is explicit rather than incidental.

The gate already names every unfloored package in every run, so nothing was
hidden. What a run cannot supply is the only thing that matters here: whether
an absence was decided or overlooked. That lives in .coverage-floors' comment
header, and a hand-written description of state held somewhere else drifts —
which it had, three ways:

  - the header said "four packages", listed five, and the gate reported six.
    internal/cache/cachetest arrived with #178 and was never explained
  - two of the three packages #199 names as unexplained, pkg/types and tests,
    are not in the gate's report at all and cannot be: they contain no
    statements. A floor for either *fails* the gate through its stale-floor arm
    rather than weakening it — verified, `pkg/types 50` exits 1 — so the issue's
    "floor it, or document it" choice has one available branch for them
  - the third, pkg/optimization, was deleted in 4d10da0 and its explanation
    outlived it by two releases

Five of the six reported packages read as 0.0%, and that number is an artifact
rather than a measurement: `go test -coverprofile` instruments only the package
under test, so a support package's statements produce count-0 lines even when a
sibling suite executes all of them. Measured with -coverpkg from each one's
consumers, they run 48.6%–88.9%. A floor there would have to be 0 to pass, and
0 is not a gate. The header now records those measurements.

Two findings the issue did not have. pkg/archive was described here as "dead
code pending a decision" — internal/archive imports it from five files, so the
claim was wrong in the direction that matters: it read as a reason not to test
a package a floored package depends on. And sdks/c is unfloorable for a
different reason than the rest: main.go is a CgoFile, so `CGO_ENABLED=0 go test
./sdks/c/` does not fall back to a tag-excluded variant, it fails to compile —
and CI sets CGO_ENABLED=0 for the cross-build and release matrices.

TestUnfloorablePackagesAreExplained asserts the two sets are equal in both
directions. It runs coverage-gate.sh rather than re-deriving the set, because
the gate's derivation has its own recorded failure: the module path was once an
awk literal, a rename stopped it matching, and every package reported "no floor
set" while the run failed naming nothing. A test re-deriving from `go list`
would have been green throughout. The profile it feeds the script is synthesized
from go list + go/parser, since a real one takes twenty minutes and only set
membership is under test — checked against CI's own coverage.out, which yields
the same six.

The header's declared set is marked `# no-floor:` / `# no-statements:` rather
than inferred from prose shape. The first parser matched indented path-shaped
tokens and reported six packages the header names for unrelated reasons as
stale entries; prose has no parseable structure.

Mutation-verified 6/6: dropped marker, marker for a floored package, marker for
a nonexistent package, a function body added to pkg/types, a new unfloored
package, and a package marked both ways. No floor values changed.

Closes #199
@scttfrdmn
scttfrdmn merged commit 37d8680 into main Aug 5, 2026
33 checks passed
@scttfrdmn
scttfrdmn deleted the fix/coverage-floors-unlisted-199 branch August 5, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci-cd CI workflows, gates, and release automation area: tests Test infrastructure and test suite effort: xs Extra small effort - <2 hours priority: low Nice to have, low urgency type: testing Test coverage, test infrastructure, or test improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coverage: three packages have no floor and no explanation for not having one

1 participant