Skip to content

🧪 test(coverage): raise product coverage to 96.9% and enforce a 96% floor - #37

Merged
scttbnsn merged 2 commits into
mainfrom
test/coverage-96-floor
Jun 23, 2026
Merged

scttbnsn merged 2 commits into
mainfrom
test/coverage-96-floor

Conversation

@scttbnsn

Copy link
Copy Markdown
Contributor

What

Drives statement coverage of the product packages (internal/* + cmd/portwing) from 74.8% → 96.9% and ratchets the CI gate to enforce a 96% floor.

Coverage by package

Package Before After
internal/server 72.4% 97.4%
internal/docker 75.1% 97.4%
internal/metrics 52.2% 100%
internal/edge 80.8% 97.2%
internal/auth 85.4% 95.0%
internal/mcp 79.0% 97.6%
internal/adapter 88.5% 100%
internal/adapter/drydock 89.5% 95.3%
internal/banner 54.8% 98.4%
internal/generic 82.5% 89.5%
internal/audit 85.4% 100%
internal/log 0% 100%
internal/config 97.9% 97.9%
internal/pool 100% 100%
cmd/portwing 0% 93.3%
TOTAL (product scope, -race) 74.8% 96.9%

Gate change (lands with the tests on purpose)

The coverage gate previously counted everything via go test ./..., which folded in three non-shipped tool mains (benchmarks/cmd/loadgen, benchmarks/cmd/mockdocker, internal/banner/gen). The Test step now scopes the coverprofile to internal/* + cmd/* (minus banner/gen) and COVERAGE_MIN goes 68 → 96. go vet ./... still compiles the excluded tooling so it can't silently rot. The gate bump ships in the same PR as the tests so the floor never reddens before coverage catches up.

Behavior-preserving refactors (only non-test product changes)

  • metrics/collector.go — added an overridable procRoot (defaults to /proc) so the /proc parsers can be driven from fixtures deterministically on any OS (they were ~8% covered because this dev/CI matrix can't rely on live /proc contents).
  • cmd/portwing/main.go — split main() into a testable run(args, stdin, stdout, stderr) int that returns exit codes instead of calling os.Exit, writing through injected writers. Production behavior unchanged.

Verification

  • go test -race across the product packages: PASS, total 96.9%
  • gofmt -l clean, go vet ./... clean

Remaining uncovered lines are genuinely unreachable without product changes (crypto/rand failures, json.Marshal-can't-fail paths, OS-specific dead code, multi-minute cleanup tickers, and the main() entry point itself) — documented per package in the agent reports.

…loor

Drive statement coverage of the product packages (internal/* + cmd/portwing)
from 74.8% to 96.9% and ratchet the CI gate to match.

- 🧪 test: add table-driven tests across server, docker, metrics, edge, auth,
  mcp, adapter/drydock, banner, generic, audit, log, and cmd/portwing,
  targeting error paths, branch coverage, and previously-untested files
- 🔧 config(ci): scope the coverprofile to product packages and bump
  COVERAGE_MIN 68→96. Excludes the three non-shipped tool mains
  (benchmarks/cmd/loadgen, benchmarks/cmd/mockdocker, internal/banner/gen);
  `go vet ./...` still compiles them so they can't rot. Gate change lands with
  the tests so the floor never reddens before coverage catches up.
- 🔄 refactor(metrics): inject an overridable procRoot (defaults to /proc) so
  /proc parsers can be driven from fixtures deterministically on any OS
- 🔄 refactor(cmd): split main() into a testable run() that returns exit codes
  and writes through injected io.Writer/Reader; behavior unchanged
The coverage tests were verified with go test/vet but not golangci-lint.
Fix all 27 findings:

- 🐛 fix(test): close response bodies in bodyclose-flagged call sites
  (canonical guard, plus one //nolint where the body is read in a goroutine)
- 🔧 config(lint): exclude unactionable fmt.Fprint* writes to injected
  io.Writers and (net.Listener).Close teardown in errcheck
- 🗑️ remove(test): delete unused drydock test helpers + orphaned io import
- 🎨 style(test): check w.Write/os.RemoveAll returns; #nosec G302 on the
  intentionally world-readable auth fixture

@biggest-littlest biggest-littlest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Coverage tests look solid — product scope to 96.9%, lint/vet/race all green. Gate bump ships with the tests as intended.

@ALARGECOMPANY ALARGECOMPANY left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Behavior-preserving refactors (procRoot, run()) and the 96 floor scoped to product packages. Approving.

@scttbnsn
scttbnsn merged commit 1e8e9cd into main Jun 23, 2026
24 checks passed
@scttbnsn
scttbnsn deleted the test/coverage-96-floor branch June 23, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants