build: add -coverpkg=./pkg/... to unit test target#1575
Open
omercnet wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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 themake testgo testinvocation to include cross-package coverage in the resulting profile.
This was referenced Apr 30, 2026
2689857 to
b99b6a3
Compare
This was referenced May 6, 2026
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>
b99b6a3 to
8f811d6
Compare
sozercan
approved these changes
May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
One-line Makefile change: adds
-coverpkg=./pkg/...to the unit-test command so cross-package coverage attribution is captured.Why
go testdocuments:Without
-coverpkg, when a test inpkg/patch/exercises code inpkg/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
Related
This is part of a small coverage-improvement series. Each PR is independent and can land in any order:
-coverpkgflagpkg/patch/single.goandpkg/patch/multi.got.Skip→t.Fatalgo build -cover+GOCOVERDIR) — held back until the rest land