Skip to content

test: give pkg/archive tests of its own and sdks/c a floor (#360, #361) - #372

Merged
scttfrdmn merged 1 commit into
mainfrom
test/pkg-archive-coverage-360-361
Aug 6, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
test/pkg-archive-coverage-360-361

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #360. Closes #361.

pkg/archive — 0 own-tests → 100.0%, with a floor (#360)

The package had no tests of its own. Its 48.6% was measured through internal/archive under -coverpkg, which is a number about a consumer rather than about this package — and the code no consumer touches was invisible inside it.

#360 offered two options, and the premise had moved since it was filed: internal/archive now builds an index and reads it back, so the genuinely unreached code was ListDirectory and its two helpers, which no consumer calls at all. Testing directly is the only option that covers them.

pkg/archive/metadata_test.go takes it to 100.0% in three measured steps (94.6% → 97.3% → 100.0%), and the floor is set there.

The branch that is unreachable from the only producer

Reaching 100% surfaced this, and it is covered with the reason written down rather than deleted:

if !containsSlash(remaining) || (entry.IsDir && remaining[len(remaining)-1] == '/' && ...)

The right-hand side needs an entry whose own Path ends in /. internal/archive.BuildIndexFromBytes runs every tar name through path.Clean, which strips exactly that — so no index built in this repository can reach it, and neither can containsSlashExceptLast, which only that branch calls.

Covered rather than removed because ArchiveIndex is exported, and a caller outside this repository may build an index by hand using tar's own convention, where a directory name does keep its slash. The test states which convention each half serves, so a future decision to drop the branch is a decision about the exported surface instead of a coverage cleanup.

Two behaviors are now pinned rather than assumed:

  • TotalFiles counts directories; TotalSize does not. A directory's tar-reported size is not content, and that asymmetry is the kind of thing that gets "cleaned up" into one rule.
  • A repeated path replaces the entry and does not roll either counter back — TotalFiles=2, TotalSize=30 for one replaced path. That is the current contract; the test exists so a change to it is visible.

sdks/c — an explicit cgo posture, then a floor (#361)

Step 1. The coverage job set no CGO_ENABLED, so it took the runner's default. sdks/c is the one package whose coverage depends on that, so its number came from an inherited value no workflow stated. The job now sets CGO_ENABLED: 1.

The direction matters. sdks/c/main.go carries import "C", so with cgo off the package does not fall back to a build-tag-excluded variant — it fails to compile:

sdks/c/main_test.go:105:16: undefined: bytesToCacheString
sdks/c/main_test.go:156:18: undefined: codeFromErr
sdks/c/main_test.go:333:4:  undefined: fillCStr
sdks/c/main_test.go:411:42: undefined: maxPutLength

CGO_ENABLED=0 here would turn a coverage question into a compile failure in the job whose output is a coverage number. The cross-build matrix and the release build set 0 deliberately, because there the point is a static binary; here the point is measuring every package.

Step 2 — the floor is 12, and the stale number is the finding. .coverage-floors claimed 11.0% while arguing the package was unfloorable, and that number was already stale when it was written: #355 added the tests that took it from 11.0% to 12.1%, and the note was authored on a branch cut before #355 merged, so it recorded a measurement its own commit had invalidated.

Verified rather than reasoned:

measured
f6f2ae5^ (before #355) 11.0%
HEAD 12.1%
commits touching sdks/c since the note none

12.1% is stable across three runs and identical under set, count and atomic. The floor is a ratchet on the Go-testable half — codeFromErr, fillCStr, bytesToCacheString, the length and limit error builders — not a coverage target for the SDK. The rest is //export cgo entry points whose parameters are C pointers, which the C suite under sdks/c/tests exercises by linking the shared library and go test cannot reach.

The gate stops measuring npm-vendored Go

Two copies of the flatted npm package ship a Go port under their package directory, so once anything has run npm install in docs-platform or sdks/javascript, go list ./... reports two more packages and the gate named them as unfloored at 0.0%. They are gitignored, absent from a fresh checkout, and never installed by the coverage job — so they appeared only on a developer machine, which is the worst place for a gate to grow noise, and neither a floor nor a test is the fix, because the code is not this repository's.

TestUnfloorablePackagesAreExplained previously filtered them out of its own synthetic profile. That passed the test and left the noise in the output a person actually reads — the wrong half to fix. The filter is gone: the synthetic profile now names those packages, and the assertion that the gate does not report them is what tests the exclusion.

Verification

Both new gates verified by mutation, per the standing rule:

  • Drop the node_modules skip from coverage-gate.sh → TestUnfloorablePackagesAreExplained fails, naming both flatted packages with the "add a # no-floor: entry" message.
  • Set the sdks/c floor to 13 → FAIL sdks/c — 12.1%, below its floor of 13%.

Full-repo gate against a fresh CGO_ENABLED=1 profile:

ok    pkg/archive                        100.0%  (floor 100%)
ok    sdks/c                              12.1%  (floor 12%)
...
no floor set (add to .coverage-floors to gate them):
  internal/awsrates/offerfile/offertest   0.0%
  internal/cache/cachetest             0.0%
  internal/testhttp                    0.0%
  pkg/compression                      0.0%

coverage-gate: 35 package(s) at or above their floor

Four unfloored packages, down from six — and all four are the "no tests, deliberately; every statement runs under a floored consumer" case, where a floor would have to be 0 to pass and 0 is not a gate. .coverage-floors' header count is updated from five to four, its 80%-target sentence recounted from the file (23 of 35), and the no-floor: sdks/c block replaced with a per-floor note.

pkg/archive had no tests. Its 48.6% was measured through internal/archive under
-coverpkg, which is a number about a consumer, and the code no consumer touches
was invisible in it. metadata_test.go takes the package to 100.0%.

#360 offered testing directly or folding into the consumer, and the premise had
moved since it was filed: internal/archive now builds an index and reads it back,
so the genuinely unreached code was ListDirectory and its two helpers, which no
consumer calls at all. Only the first option covers them.

Reaching 100% found a branch that is unreachable from the only producer here, and
it is covered with that written down rather than deleted. ListDirectory's second
disjunct needs an entry whose Path ends in '/', and BuildIndexFromBytes runs every
tar name through path.Clean, which strips exactly that. ArchiveIndex is exported,
so an outside caller may build an index using tar's own convention where a
directory keeps its slash; the test says which convention each half serves, so
removing the branch stays a decision about the exported surface. Two behaviors are
pinned rather than assumed: TotalFiles counts directories and TotalSize does not,
and a repeated path replaces the entry without rolling either counter back.

For #361 the coverage job now states CGO_ENABLED: 1. It set nothing, so it took
the runner default, and sdks/c is the one package whose coverage depends on it — a
floor read off an inherited value is a claim about a configuration no workflow
states. On rather than off: main.go carries `import "C"`, so with cgo off the
package does not fall back to a tag-excluded variant, it fails to compile, because
main_test.go references codeFromErr, fillCStr, maxPutLength and more. CGO_ENABLED=0
would turn a coverage question into a compile failure in the job whose output is a
coverage number.

The sdks/c floor is 12, not the 11 this file claimed while arguing the package was
unfloorable. That number was stale when written: #355 added the tests taking it to
12.1%, and the note was authored on a branch cut before #355 merged, so it recorded
a measurement its own commit had invalidated. Verified rather than reasoned — no
commit has touched sdks/c since, and it measures 11.0% at f6f2ae5^ and 12.1% at
HEAD. The floor is a ratchet on the Go-testable half; the rest is //export entry
points taking C pointers, which the C suite exercises and go test cannot.

Also: the gate stops measuring Go files vendored inside npm dependencies. Two
copies of flatted ship a Go port, so after npm install `go list ./...` reports two
more packages and the gate named them unfloored at 0.0%. Gitignored, absent from a
fresh checkout, never installed by the coverage job — so visible only on a
developer machine, and the fix is neither a floor nor a test because the code is
not ours. TestUnfloorablePackagesAreExplained used to filter them out of its own
synthetic profile, which passed the test and left the noise in the output a person
reads; that filter is gone, so the profile names them and the gate's exclusion is
what the assertion tests.

Verified by mutation, both new gates: dropping the node_modules skip fails
TestUnfloorablePackagesAreExplained naming both packages, and a floor of 13 fails
sdks/c at 12.1%.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant