Repository navigation
Conversation
|
Found 3 issues this PR may fix:
🤖 Generated with Claude Code |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughBuilds and filters function byte-range sets in the C++ coverage binding to exclude synthetic-only ranges, preserves statement-derived executed lines when processing function ranges in the Zig report generator, and adds an LCOV regression test for classes extending factory-call results without explicit constructors. Changes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/bun.js/bindings/CodeCoverage.cpp`:
- Around line 49-80: The current filter incorrectly skips cached function ranges
by checking only numeric collisions against syntheticFunctionRanges, which can
drop real same-source functions that happen to share offsets; when iterating
vm.heap.forEachCodeBlock and collecting ranges (see syntheticFunctionRanges, the
collect lambda using unlinked->unlinkedFunctionStart()/End(), and the
functionRanges from vm.functionHasExecutedCache()->getFunctionRanges), build two
sets: synthetic ranges and same_source ranges (i.e., ranges produced from
executables whose sourceID == sourceID) and then, when iterating functionRanges,
only skip a range if it is in syntheticFunctionRanges and NOT in the same_source
set (skip only synthetic && !same_source) so real same-source cached ranges are
preserved.
In `@test/cli/test/coverage.test.ts`:
- Around line 95-98: The current assertion using
expect(subjectRecord).toContain("DA:2,") can match "DA:2,0" (uncovered); update
the assertion to require a non-zero hit count for line 2 by asserting the exact
non-zero value or using a pattern that excludes zero — e.g., change the check on
subjectRecord (the LCOV "DA" entry) to assert "DA:2,1" or use a regex/assertion
that ensures DA:2,<n> where n > 0 so the class declaration is confirmed
executed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: a75343ad-404a-4233-83a2-63bcb42c7bda
⛔ Files ignored due to path filters (1)
test/cli/test/__snapshots__/coverage.test.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (3)
src/bun.js/bindings/CodeCoverage.cppsrc/sourcemap/CodeCoverage.zigtest/cli/test/coverage.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/cli/test/coverage.test.ts`:
- Around line 69-99: Add a new, small regression test that specifically triggers
the synthetic && !same_source branch in CodeCoverage.cpp by creating a real
(non-synthetic) user function that deliberately shares the synthetic
constructor's raw (start,end) offsets so the same-source guard collision is
exercised; mirror the existing "derived class with no explicit constructor" test
pattern (test/cli/test/coverage.test.ts) but add a fixture file that defines a
user function with the same raw offsets as the synthetic constructor and assert
coverage records show both entries handled correctly (so the new branch is
executed and prevents the collision regression).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 27803008-9b31-48a6-a328-2393a6a3bd29
📒 Files selected for processing (2)
src/bun.js/bindings/CodeCoverage.cpptest/cli/test/coverage.test.ts
| test("derived class with no explicit constructor (issue #29691)", () => { | ||
| const dir = tempDirWithFiles("cov-29691", { | ||
| "dep.ts": `export const Base = () => class {};\n`, | ||
| "subject.ts": `import { Base } from "./dep"; | ||
| export class Derived extends Base() {} | ||
| `, | ||
| "subject.test.ts": `import { expect, test } from "bun:test"; | ||
| import { Derived } from "./subject"; | ||
| test("loads the class", () => { | ||
| expect(Derived.name).toBe("Derived"); | ||
| }); | ||
| `, | ||
| }); | ||
| const result = Bun.spawnSync([bunExe(), "test", "--coverage", "--coverage-reporter", "lcov"], { | ||
| cwd: dir, | ||
| env: bunEnv, | ||
| stdio: [null, null, "pipe"], | ||
| }); | ||
| expect(result.exitCode).toBe(0); | ||
| expect(result.signalCode).toBeUndefined(); | ||
|
|
||
| const lcov = readFileSync(path.join(dir, "coverage", "lcov.info"), "utf-8"); | ||
|
|
||
| // subject.ts should not report the import on line 1 as uncovered (DA:1,0), | ||
| // and should not count the synthetic default constructor as a function. | ||
| const subjectRecord = lcov.split("end_of_record").find(r => r.includes("SF:subject.ts"))!; | ||
| expect(subjectRecord).toContain("FNF:1"); | ||
| expect(subjectRecord).toContain("FNH:1"); | ||
| expect(subjectRecord).toMatch(/DA:2,[1-9]\d*/); // class declaration line was evaluated (non-zero hits) | ||
| expect(subjectRecord).not.toContain("DA:1,0"); // import line is not bogusly marked unexecuted | ||
| }); |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider adding a collision-specific regression for the new same-source guard.
This repro locks down the original synthetic-constructor bug, but it still doesn't exercise the new synthetic && !same_source branch in CodeCoverage.cpp. A tiny fixture where a real user function shares the synthetic constructor's raw (start, end) offsets would protect the collision fix directly.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@test/cli/test/coverage.test.ts` around lines 69 - 99, Add a new, small
regression test that specifically triggers the synthetic && !same_source branch
in CodeCoverage.cpp by creating a real (non-synthetic) user function that
deliberately shares the synthetic constructor's raw (start,end) offsets so the
same-source guard collision is exercised; mirror the existing "derived class
with no explicit constructor" test pattern (test/cli/test/coverage.test.ts) but
add a fixture file that defines a user function with the same raw offsets as the
synthetic constructor and assert coverage records show both entries handled
correctly (so the new branch is executed and prevents the collision regression).
Fixes #29691. JSC synthesizes a default class constructor for `class Foo {}` and `class Foo extends Bar() {}` by linking a fresh SourceProvider whose body is `(function () { })` or `(function (...args) { super(...args); })`. `CodeBlock::finishCreation` then calls `FunctionHasExecutedCache::insertUnexecutedRange(ownerSourceID, start, end)` with offsets that live in the synthetic provider — not the owner's source — so coverage saw a 37-byte range `[1, 38)` for the derived case and marked whatever user code happened to sit at those offsets as an uncovered 'function'. With a one-line file like: import { Base } from "./dep"; export class Derived extends Base() {} that meant `DA:1,0` for the import line, 50% line coverage, and 0% function coverage. Filter these out in the C++ binding: a function executable reached from this source's code blocks whose `sourceID()` resolves to a different provider is synthetic (see `UnlinkedFunctionExecutable::linkedSourceCode`), so collect its `unlinkedFunctionStart`/`End` and skip matching entries when reading `functionHasExecutedCache` ranges. Also preserve statement-level line coverage when a function did not execute: a never-called function's declaration line still ran as a statement (`export function foo() {` executes even if `foo` is never called), so don't unset that bit when its body range is marked unexecuted. This matches V8/istanbul behavior and fixes a pre-existing `DA:declLine,0` quirk the lcov snapshot test was pinning.
…te inline snapshot
- C++ filter: also collect `sameSourceFunctionRanges` so a real user
function whose unlinkedFunctionStart/End numerically coincides with a
synthetic default class constructor (e.g. a file opening with
`!function(){return 1}();class X{}`) isn't dropped alongside the
synthetic one. Skip only when a range is synthetic AND not also
present in the same-source set.
- Test assertion: replace `toContain("DA:2,")` with a regex that
requires a non-zero hit count, so a latent `DA:2,0` regression can't
slip past.
- Inline snapshot: the `coveragePathIgnorePatterns - partial coverage
without nan` test in coverage.test.ts hardcoded `include-me.ts |
50.00 | 66.67`. The Zig statement-preservation change pushes its
line coverage to 100% for the same reason `demo2.ts` line 9 went
from DA:9,0 to DA:9,5 in the lcov snapshot — the module's
top-level export-binding statements cover the `neverCalled`
declaration line, which now survives the unexecuted-function sweep.
Update the inline snapshot to match.
Debug/ASAN builds print `WARNING: ASAN interferes with JSC signal handlers; useWasmFastMemory and useWasmFaultSignalHandler will be disabled.` to stderr on every JS-executing subprocess (emitted via `std::call_once` in Options.cpp — at most one line per process). `normalizeBunSnapshot` doesn't scrub it, so the inline `toMatchInlineSnapshot` calls in coverage.test.ts fail on the debug-ASAN CI lane against snapshots captured from a release build. Filter lines starting with `WARNING: ASAN interferes` out of `stderr` before normalizing — the repo convention used in test/js/bun/resolve/, test/js/node/, test/cli/install/ and elsewhere.
38247ef to
f5309d0
Compare
|
Closing: this PR predates the Rust rewrite and modifies source files that no longer exist on If the underlying issue is still present, it will need a fresh fix against the current tree. |
Fixes #29691.
Fixes #7025.
Fixes #24908.
Repro
bun test --coveragereportssubject.tsat 50% line coverage and 0%function coverage. The lcov output marks the import line as uncovered
(
DA:1,0) even though the module clearly loaded.Also surfaces as 50% function coverage on any class without an explicit
constructor (#7025, #24908) because JSC's synthesized default constructor
gets counted as an uncovered function.
Cause
JSC synthesizes the default constructor for
class Derived extends Base() {}by linking a standalone builtin source:
(function (...args) { super(...args); }).CodeBlock::finishCreationthen records an unexecuted range in theFunctionHasExecutedCacheunder the owner's sourceID (subject.ts),but the range's offsets (
[1, 38)) live in the synthetic source,not subject.ts. When coverage consumes those offsets as subject.ts byte
offsets, they happen to straddle bytes 1-37 — the import, a newline, and
the start of
export class …— and flip both lines to 'uncovered'.V8 doesn't emit anything similar, which is why Node's
NODE_V8_COVERAGEreports 100% on the same repro.
Fix
Two changes in
src/bun.js/bindings/CodeCoverage.cppandsrc/sourcemap/CodeCoverage.zig:Drop synthetic ranges at the binding. Walk the VM's CodeBlocks
whose owner matches the source we're reporting; for each of their
function declarations and expressions, check whether the linked
FunctionExecutable::sourceID()resolves to a different provider.That indicates
UnlinkedFunctionExecutable::linkedSourceCodepicked upBuiltinExecutables::defaultConstructorSourceCodeinstead of theparent source, which is the tell for a synthetic builtin default class
constructor. Collect
(unlinkedFunctionStart, unlinkedFunctionEnd)pairs and skip matching entries when draining
functionHasExecutedCache.Preserve statement-level line hits for unexecuted functions. Snapshot
lines_which_have_executedafter statement blocks are processed. When alater function block wants to mark lines unexecuted, don't unset bits
that statement processing already set — a never-called
foo'sexport function foo() {line still ran as a statement even if thebody didn't. This matches V8/istanbul behavior and incidentally fixed
a pre-existing
DA:9,0in the existinglcov coverage reportersnapshot(
function uncovered()declaration line is nowDA:9,5).Verification
test/cli/test/coverage.test.ts— addedderived class with no explicit constructor (issue #29691)which fails on main and passes on this branch.
lcov coverage reportersnapshot updated to reflect correctnessimprovements (declaration line now shows execution count,
FNHcountsthe real class-field initializer now that the synthetic ctor is gone).
explicit constructor) both report 100% function coverage with this fix,
50% without.