Skip to content

module: disable the compile cache while V8 coverage is collected - #67120

Open
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:module-compile-cache-coverage
Open

codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:module-compile-cache-coverage

Conversation

@codebytere

Copy link
Copy Markdown
Member

With a warm compile cache, V8 coverage is wrong in both directions. V8 can't collect block coverage for functions deserialized from the code cache and only reports a call count for them, so a branch that never ran inside one reads as covered. Tools that merge reports from several processes, including the test runner, can also drop a function that did run.

On main with node --test --experimental-test-coverage and NODE_COMPILE_CACHE set:

no cache warm cache
module with a top-level if that is never taken, lines 57.14% 100%
class instantiated in one of two test files, functions 100% 66.67%

The docs recommended turning the cache off by hand for this. This does it automatically when coverage starts with the process, through NODE_V8_COVERAGE or --experimental-test-coverage. module.enableCompileCache() then returns DISABLED with a message. Coverage started later, e.g. through the inspector, behaves as before, and the docs now say so.

19 compile cache tests now clear NODE_V8_COVERAGE for the processes they spawn, since they would otherwise fail in the coverage jobs.


Disclosure: the code, tests and this description were written by Claude Code, directed and reviewed by @codebytere.

V8 cannot collect block coverage for functions that are deserialized
from the code cache, so it only reports how many times each of them
ran. With a warm compile cache, branches that never ran inside those
functions are reported as covered, and tools that merge reports from
several processes can report functions that ran as never run.

The documentation recommended turning the cache off by hand. Do it
automatically when coverage collection starts with the process, through
NODE_V8_COVERAGE or --experimental-test-coverage.

The compile cache tests stop propagating NODE_V8_COVERAGE to the
processes they spawn, so that they keep working when the test suite
itself runs with coverage.

Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Oct 29, 2026
@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.66%. Comparing base (502c117) to head (ab21ea1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67120      +/-   ##
==========================================
- Coverage   90.66%   90.66%   -0.01%     
==========================================
  Files         797      797              
  Lines      278791   278796       +5     
  Branches    53620    53630      +10     
==========================================
- Hits       252768   252761       -7     
- Misses      16376    16380       +4     
- Partials     9647     9655       +8     
Files with missing lines Coverage Δ
src/compile_cache.h 100.00% <ø> (ø)
src/env.cc 84.49% <100.00%> (+0.18%) ⬆️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants