Skip to content

Commit 72bd975

Browse files
bbertuccclaude
andauthored
test: run the suite with Sparkplug off, which is what kills the #405 segfault (#477)
#405's crash has an upstream name — nodejs/node#62393, V8 CL 0b94a9fd23ba: the BaselineOutOfLinePrologue builtin left a random value on the stack where the GC found it. `ClearStaleLeftTrimmedPointerVisitor` reads it as a heap pointer and faults at 0xe, the address in all five local reports. Sparkplug generates that prologue, so `--no-sparkplug` removes the path. The two decisions #405 was holding both answer no. Node cannot be bumped into the fix: the backport (nodejs/node#65753) is open, not landed, so no released 24.x has it, and one upstream report has the crash live on v26.7.0. CI needs no dead-child retry: every occurrence here and upstream is macOS arm64, and every workflow runs ubuntu-latest. Cost is nothing measurable — 55.8 s mean either way over two runs each locally, ~3% on Linux x64 over the two heaviest jsdom files, against a 22-minute review step. The flag is on the test script only, on purpose: `npm start` and `npm run dev` keep the Sparkplug path, because one dev server dying is loud where a dead test child reads as a clean run with a short pass count. A test pins the flag, and after round 1 it pins its *position*: `node --test "glob" --no-sparkplug` exits 0, warns nothing, and the child's `execArgv` does not carry the flag, so a presence-only check could go green through the exact regression it exists to catch. Drop the flag and that test together when nodejs/node#65753 ships in a 24.x release. Two rounds, both approved; round 1's three notes fixed, round 2 clean. Refs #405 Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 24af463 commit 72bd975

5 files changed

Lines changed: 56 additions & 9 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,23 @@ npm test # the unit suite (node --test; run it through np
6161
./test/e2e.sh # full API lifecycle against mock GitHub + mock model (needs jq)
6262
```
6363

64-
Run the unit suite through `npm`, not as a bare `node --test`. The `npm test` script
65-
registers a second reporter (`test/spec-with-signals.mjs`) that prints `signal` and
66-
`exitCode` when a test file's *process* dies. Node's default reporter shows that as `✖
67-
some.test.ts` and `'test failed'` — identical to a failed assertion, with nothing on
68-
stderr — and the tests after the death simply never run, so the pass count reads clean
69-
while being short. See #405.
64+
Run the unit suite through `npm`, not as a bare `node --test`. The script carries two
65+
things a bare run does not:
66+
67+
- **A second reporter** (`test/spec-with-signals.mjs`) that prints `signal` and `exitCode`
68+
when a test file's *process* dies. Node's default reporter shows that as `✖ some.test.ts`
69+
and `'test failed'` — identical to a failed assertion, with nothing on stderr — and the
70+
tests after the death simply never run, so the pass count reads clean while being short.
71+
- **`--no-sparkplug`**, which avoids a V8 bug that segfaults test children inside the
72+
garbage collector roughly once in ten full runs on macOS arm64. The crash needs code
73+
Sparkplug generates, so turning that tier off removes the path; it cost nothing
74+
measurable here (two runs each, 55.8 s either way). It is on the test script only: `npm start`
75+
and `npm run dev` keep the Sparkplug path on purpose, because one dev server dying is loud,
76+
where a dead test child reads as a clean run with a short count. **Drop the flag when
77+
[nodejs/node#65753](https://github.com/nodejs/node/pull/65753) ships in a 24.x release** —
78+
it is the backport of the V8 fix, and no released 24.x has it yet.
79+
80+
Both exist because of #405, which has the crash stack and the evidence.
7081

7182
The demo page must stay accessible — it's audited with the project's own axe-core lint and
7283
should report **0 violations**.

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,10 @@ Four things that catch most mistakes:
316316
- **Do not write a closing keyword next to an issue number** you do not mean to close. GitHub closes
317317
issues from PR bodies and commit messages, including from prose.
318318

319-
Commands: `npm test` is `node --test` over `test/*.test.ts` (not vitest), `npm run typecheck` is
320-
`tsc --noEmit`, and `./test/e2e.sh` runs the whole lifecycle against mocks with no credentials.
319+
Commands: `npm test` is `node --test` over `test/*.test.ts` (not vitest), plus a reporter and a V8
320+
flag a bare run loses — see [CONTRIBUTING.md § Development](CONTRIBUTING.md#development). `npm run
321+
typecheck` is `tsc --noEmit`, and `./test/e2e.sh` runs the whole lifecycle against mocks with no
322+
credentials.
321323

322324
## Further reading
323325

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"start": "node --use-system-ca --env-file-if-exists=.env src/index.ts",
2020
"dev": "node --use-system-ca --env-file-if-exists=.env --watch src/index.ts",
2121
"typecheck": "tsc --noEmit",
22-
"test": "node --test --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./test/spec-with-signals.mjs --test-reporter-destination=stdout \"test/*.test.ts\""
22+
"test": "node --no-sparkplug --test --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./test/spec-with-signals.mjs --test-reporter-destination=stdout \"test/*.test.ts\""
2323
},
2424
"dependencies": {
2525
"@aws-sdk/client-bedrock-runtime": "^3.682.0",

‎test/spec-with-signals.mjs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
// a flake in that file's own harness, while the machine had six crash reports across the
1111
// same four days, every one of them a SIGSEGV inside node's own garbage collector.
1212
//
13+
// That crash now has a name and a workaround: V8 pushed an uninitialized register as a tagged
14+
// pointer in Sparkplug's out-of-line prologue (nodejs/node#62393, V8 CL 0b94a9fd23ba), so
15+
// `npm test` runs with `--no-sparkplug` and the path is gone. This reporter stays anyway — it is
16+
// what would catch the next dead child, including the same one if the flag is ever dropped before
17+
// the fix lands (nodejs/node#65753).
18+
//
1319
// Registered as a second `--test-reporter` rather than a `spec` subclass because
1420
// `node:test/reporters`' spec carries no `_transform` on its prototype (its class body
1521
// declares no prototype methods at all), so an override of it is never called. Two

‎test/spec-with-signals.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,31 @@ test("the reporter spec runs the suite with is the one this file tests", () => {
299299
// destination silently sends both to the same place in the wrong order.
300300
assert.equal(pkg.scripts.test.match(/--test-reporter-destination=/g)?.length, 2);
301301
});
302+
303+
test("the suite runs with Sparkplug off, which is what stops the #405 segfault", () => {
304+
// The crash this reporter was written to name is a V8 bug in Sparkplug's out-of-line
305+
// prologue (nodejs/node#62393): an uninitialized register is pushed where the GC later
306+
// reads a tagged pointer, so a test child dies of SIGSEGV roughly once in ten full runs
307+
// on macOS arm64. `--no-sparkplug` removes the path.
308+
//
309+
// Pinned here because the flag is invisible in a passing run: dropping it costs nothing
310+
// today and reintroduces a rare silent death weeks later, which is the hardest kind of
311+
// regression to attribute. Drop the flag AND this test when nodejs/node#65753 — the
312+
// backport of the V8 fix — ships in a 24.x release. No released 24.x has it yet.
313+
const pkg = JSON.parse(
314+
readFileSync(join(import.meta.dirname, "..", "package.json"), "utf8"),
315+
) as { scripts: Record<string, string> };
316+
// Position, not presence. `node --test "test/*.test.ts" --no-sparkplug` exits 0 and prints
317+
// no warning, and the child's `execArgv` does not carry the flag — anything after the
318+
// positional is an argument to the runner rather than a V8 option. A reorder would leave a
319+
// presence-only assertion green while dropping the protection, which is the same silence
320+
// this test exists to break. So: the flag has to be a token, and it has to come first.
321+
const argv = pkg.scripts.test.split(" ");
322+
const flagAt = argv.indexOf("--no-sparkplug");
323+
const testAt = argv.indexOf("--test");
324+
assert.notEqual(flagAt, -1, "package.json's test script does not pass --no-sparkplug");
325+
assert.ok(
326+
testAt !== -1 && flagAt < testAt,
327+
`--no-sparkplug must come before --test to reach the test children (got ${flagAt} and ${testAt})`,
328+
);
329+
});

0 commit comments

Comments
 (0)