Skip to content

fix(cmd/go): prevent stale coverage data when using -coverpkg with test caching #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

austinderek
Copy link

  • Add coverage package source files to cache invalidation calculation
  • Include GoFiles and CgoFiles from testCoverPkgs in computeTestInputsID
  • Ensure cache is invalidated when any covered source file changes
  • Prevent mixing old and new coverage data in profiles
  • Add test case to reproduce and verify the fix

Fixes golang#23565 where cached coverage profiles with -coverpkg contained outdated line references when source files were modified but tests didn't directly depend on the changed packages.


🔄 This is a mirror of upstream PR #74773

@austinderek austinderek force-pushed the master branch 30 times, most recently from 7a1679d to 121e5bb Compare August 5, 2025 07:05
@austinderek austinderek force-pushed the master branch 20 times, most recently from 4e182db to d50240b Compare August 13, 2025 00:03
When using -coverpkg with coverage profiling, the coverage cache keys
did not include the source file hashes of the covered packages. This
could result in stale coverage reports that reference outdated line
numbers when covered package sources were modified between test runs.

This change adds a cached hash of the covered packages' source files
that gets included in the coverage cache key computation. The hash is
computed once per test execution using sync.Once to avoid redundant
file system operations across multiple test packages.

The fix ensures that coverage profiles are properly invalidated when
any source file in the covered packages changes, preventing cache
hits with stale line number references.

Fixes golang#74873
@austinderek austinderek force-pushed the master branch 2 times, most recently from b266318 to d50240b Compare August 13, 2025 01:30
@austinderek austinderek force-pushed the fix/coverage-report-when-coverpkg-is-used branch from e85b4c0 to d8307ea Compare August 13, 2025 01:30
@austinderek austinderek force-pushed the master branch 6 times, most recently from b266318 to d50240b Compare August 13, 2025 04:08
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.

2 participants