Skip to content

build: add -coverpkg=./pkg/... to unit test target#1575

Open
omercnet wants to merge 3 commits into
project-copacetic:mainfrom
omercnet:coverage/pr1-coverpkg
Open

build: add -coverpkg=./pkg/... to unit test target#1575
omercnet wants to merge 3 commits into
project-copacetic:mainfrom
omercnet:coverage/pr1-coverpkg

Conversation

@omercnet
Copy link
Copy Markdown
Contributor

@omercnet omercnet commented Apr 30, 2026

Part of the coverage-improvement series tracked in #1580.

Summary

One-line Makefile change: adds -coverpkg=./pkg/... to the unit-test command so cross-package coverage attribution is captured.

Why

go test documents:

-coverpkg pattern1,pattern2,pattern3 — Apply coverage analysis in each test to packages whose import paths match the patterns. The default is for each test to analyze only the package being tested.

Without -coverpkg, when a test in pkg/patch/ exercises code in pkg/buildkit/, pkg/pkgmgr/, etc. (sibling packages), those exercised lines are not credited toward the coverage profile — even though they execute at runtime. With -coverpkg=./pkg/... Go instruments every package under ./pkg/..., so cross-package coverage is captured.

Expected impact

Modest lift on Codecov (~3–5 percentage points based on local measurement: 40% → 42.7%). No new tests; this just surfaces coverage that already exists implicitly.

Risk

Compilation gets a bit slower (every test binary instruments every pkg/... package). On the existing 5-min unit-test job, this is negligible.

Test plan

make test CODECOV_OPTS='-coverprofile=coverage.txt -covermode=atomic'
go tool cover -func=coverage.txt | tail -1
# total: 42.7% (vs ~40% baseline locally)

Related

This is part of a small coverage-improvement series. Each PR is independent and can land in any order:

  • (this PR) -coverpkg flag
  • codecov.yml denominator hygiene + flag_management
  • Unit tests for pkg/patch/single.go and pkg/patch/multi.go
  • Convert silent baseline-scan t.Skipt.Fatal
  • Instrumented-binary integration coverage pilot (go build -cover + GOCOVERDIR) — held back until the rest land

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the unit-test Makefile target to generate more accurate cross-package Go coverage by instrumenting all packages under ./pkg/... during go test runs, improving coverage attribution for code exercised via sibling-package calls.

Changes:

  • Add -coverpkg=./pkg/... to the make test go test invocation to include cross-package coverage in the resulting profile.

By default `go test` only attributes coverage to the package being tested.
This means cross-package execution (e.g. pkg/patch tests exercising code
in pkg/buildkit, pkg/pkgmgr, etc.) is NOT credited toward the coverage
profile, even though the lines are exercised at runtime.

Adding `-coverpkg=./pkg/...` instructs the test binary to instrument all
packages under ./pkg/... so cross-package coverage is captured. This is
the minimal change to surface coverage that already exists implicitly.

Expected lift on Codecov: ~5-15 percentage points, no new tests required.

Refs: https://pkg.go.dev/cmd/go#hdr-Testing_flags
Signed-off-by: Omer <omer@descope.com>
@omercnet omercnet force-pushed the coverage/pr1-coverpkg branch from b99b6a3 to 8f811d6 Compare May 8, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

3 participants