The per-chunk timeout fired correctly but reported almost nothing, so every diagnosis cost a CI round-trip. run-tests.cjs logged chunk START only — no timestamp, no duration, no end line — then on a kill printed all ~55 basenames and asked the operator to work out whether output kept flowing (slow) or stopped early (hang). It could not name the in-flight file because the child is spawned with stdio inherit, deliberately, per #3597/#1051. Three additions. Per-chunk elapsed timing on every path, not just failures, so drift toward the cap is visible before it becomes a kill. Every timing number in the investigation behind this had to be reconstructed by hand from GitHub log timestamps. A second, machine-readable reporter running ALONGSIDE the human one, writing NDJSON to its own file. On a kill that file is read back and the files with a test:start and no matching completion are named, with the staleness of the last event, so "stopped 480s ago at X" reads differently from "still emitting at kill". stdio stays inherit and nothing is piped or tee'd — the maxBuffer and live-output risks that shaped the original design are untouched. Ranking of the killed chunk's files by known weight, flagging any absent from tests/test-timings.json, since an unweighted file is an unknown quantity. Two details that are correct rather than lucky. Passing --test-reporter at all replaces node's implicit default, so the human reporter is now named explicitly and reproduces node's own selection (spec on a TTY, tap otherwise) — visible output is unchanged. And the destination path's chunk index is zero-padded to a fixed width because FIXED_OVERHEAD is computed ONCE before chunking; a variable-length path would have silently mis-accounted the Windows 32,767-char argv ceiling and reintroduced #3597. The reporter flags are added to FIXED_OVERHEAD exactly as --test-force-exit is. The multi-reporter pairing and the stream.compose reporter contract were confirmed against Node's v24 documentation, not recalled — the first draft carried them as an unverified assumption and said so. Also corrects a stale comment claiming the 600s cap sits "below the 20m job cap". The lane is sharded 3x at timeout-minutes: 45; the windows shards were at 19m when chunk 1/5 was killed onb351c83e0andc3e667df3. The per-chunk cap is now the binding constraint, and the old silent-cancel model leads to the wrong conclusion. Verification runs on the remote runner. Closes #4012
48 lines
2.1 KiB
JavaScript
48 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
// Machine-readable companion reporter for scripts/run-tests.cjs (#3889).
|
|
//
|
|
// node:test's built-in reporters (spec/tap) are human-formatted and
|
|
// scripts/run-tests.cjs spawns the child with `stdio: 'inherit'` — by design,
|
|
// per #3597/#1051, to avoid the maxBuffer and live-output risks of piping —
|
|
// so the parent process has no way to see WHICH file was executing when a
|
|
// per-chunk timeout kills the child. This reporter runs ALONGSIDE the normal
|
|
// human reporter (a second `--test-reporter`/`--test-reporter-destination`
|
|
// pair on the same invocation, per Node's documented multi-reporter pairing)
|
|
// and appends one JSON object per line to its own destination file. On a
|
|
// timeout, run-tests.cjs reads that file back to name the file(s) still
|
|
// in flight (a `test:start` with no matching `test:pass`/`test:fail`).
|
|
//
|
|
// Contract targeted: Node's "Custom reporters" contract
|
|
// (https://nodejs.org/api/test.html#custom-reporters) — a reporter module's
|
|
// default export is a function receiving the test runner's event stream
|
|
// (an AsyncIterable of `{ type, data }` objects) and returning/yielding the
|
|
// reporter's output. This repo's `engines.node` requires >=24.0.0
|
|
// (package.json), where this contract — including the CommonJS
|
|
// `async function*` form used here — has been stable since Node 20.
|
|
//
|
|
// Kept intentionally tiny: only the three event types run-tests.cjs needs to
|
|
// pair start/completion are handled; everything else (diagnostics, plans,
|
|
// coverage) is ignored so a truncated destination file (the process is
|
|
// SIGKILLed mid-write on timeout) never leaves more than one dangling
|
|
// unparsable trailing line.
|
|
module.exports = async function* ndjsonEventReporter(source) {
|
|
for await (const event of source) {
|
|
if (
|
|
event.type === 'test:start' ||
|
|
event.type === 'test:pass' ||
|
|
event.type === 'test:fail'
|
|
) {
|
|
const { file, name, nesting, testNumber } = event.data || {};
|
|
yield `${JSON.stringify({
|
|
type: event.type,
|
|
file,
|
|
name,
|
|
nesting,
|
|
testNumber,
|
|
ts: Date.now(),
|
|
})}\n`;
|
|
}
|
|
}
|
|
};
|