test: print running test output when CI cancels run-tests (#101724)
### What?
When CI cancels a test step, or the step times out, `run-tests.js` now
prints the output of the test files that were still running before it
exits. Until now that output was thrown away.
The test workflows `exec` their final `run-tests.js` command, so the
runner's cancellation signal reaches Node.
### Why?
[build-and-test run 43352111755, job
131647039320](https://github.com/vercel/next.js/actions/runs/43352111755/job/131647039320)
started `test/e2e/app-dir/actions/app-action.test.ts` (webpack dev,
React 18.3.1) and never finished it. The step was cancelled at its
30-minute limit. The rerun passed that file in 270s.
The cancelled log contains nothing from inside the file, for two
reasons:
- `run-tests.js` buffers each Jest child's output and only prints it
when the child exits non-zero.
- The GitHub Actions runner sends SIGINT, then SIGTERM, only to the
step's `bash -le` process. Bash doesn't forward these signals to a
foreground `node run-tests.js`, so Node never sees them.
On top of that, Playwright's shared-browser signal handlers would exit
on SIGINT, or close the browser on SIGTERM and keep running, before any
buffered output could be printed.
A second webpack-dev job was cancelled about 5 hours later: [run
43385338261, job
131753071683](https://github.com/vercel/next.js/actions/runs/43385338261/job/131753071683)
(`test dev (8/10, 18.3.1)`). It ran until the 35-minute job timeout, its
test step never completed, and its log is no longer available, so the
file that hung is unknown. It may be the same problem in another file.
This PR does **not** identify or fix these hangs. It makes the next
cancellation show the in-flight output, so the cause can be found.
### How?
- `run-tests.js` handles SIGINT and SIGTERM:
- it records which Jest children are still running;
- it tree-kills them and the shared browser server, waits up to 2s for
the children's stdio to close, and then prints their buffered output;
- it waits for stdout to drain;
- it exits with `128 + signal` within a 5s cancellation deadline.
It also stops starting new tests and retries, and a second signal exits
immediately. Per review, two narrow races are deliberately not handled:
a signal that arrives during end-of-run cleanup, and one that arrives
while the shared browser is starting.
- The shared Playwright browser server is launched with `handleSIGINT:
false` and `handleSIGTERM: false`, so the handler above controls
cleanup. SIGHUP keeps Playwright's default handling.
- Every workflow script whose final command is `node run-tests.js ...`
now uses `exec`, including env-prefixed forms such as `VAR=value exec
node run-tests.js ...`. Earlier sequential `run-tests.js` commands are
unchanged.
This adds no per-file watchdog, test skips, sleeps, or retry or timeout
increases.
### Verification
All on Linux, Node 24.22.1:
- **Runner signal sequence** (SIGINT, 7.5s, SIGTERM): a `bash -le`
script that ends with `node child.js` never delivers a signal to node.
With `exec node child.js`, node receives SIGINT.
- **Temporary hanging Jest suite** with a grandchild process, before and
after this change:
- Before: SIGINT printed none of the suite's output and left 2 processes
behind. SIGTERM was ignored, and the process was still alive after 10s.
- After: SIGINT and SIGTERM print the marker, exit 130 or 143 in about
0.1s, and leave no processes behind.
- **Real `app-action.test.ts` run** (webpack dev, React 18.3.1, strict
route types), cancelled after about 90s:
- Before: no in-file output printed, and Jest and server processes left
behind.
- After: the file's buffered output printed, exit 130, and no Jest, Next
server, or browser processes left.
- **Edge cases:** 4 MiB replayed through a slow pipe: all output
arrived. (Setup and cleanup race probes covered guards that were since
removed per review, so they no longer apply.)
- **Normal runs:** passing and failing runs behave as before.
- **Static checks:** `pnpm typescript`, ESLint and Prettier pass. YAML
parsing passes, and a check of command positions confirms only final
commands use `exec`.
Not verified: how cancellation is delivered on native Windows runners,
and whether stdout writes can block on a stalled Windows pipe.
Reproduction attempt: I ran `app-action.test.ts` 12 times with the exact
webpack-dev/React 18 flags, 4 concurrent copies, and 4 CPU burners. 11
runs passed, one hit an unrelated assertion failure, and none hung.
<!-- NEXT_JS_LLM -->
<!-- fleet e96fa311-4ad1-4a9f-a6eb-3e538da5df83 -->
---------
Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>