fix(run): charge stray rejections in in-process runs like a worker process
Merged
OK
2mo ago+221+221+012345678901234567890123456789-9-9-0123456789
In-process runs (rawConfig, e2e explore) installed no unhandledRejection or uncaughtException handling, unlike the worker entry (packages/e2e/src/run/worker/entry.ts). A test body doing void Promise.reject(new Error('x')) was never charged to the test: Node's default handler killed the host process mid-run, so no report was written.
InProcessRunner(packages/e2e/src/run/in-process.ts) now adds both listeners when it starts and removes them inend(). They route the same way the worker entry does: abandoned work is ignored, a stray rejection goes toTargetWorker.strayRejection(fails the attempt in flight, orUNHANDLED_REJECTIONbetween tests), anything else is fatal.- A fatal now ends the in-process worker the way a process dies. The runner marks itself crashed, drops whatever the worker reports while it winds down, and interrupts the unit. On exit the scheduler synthesizes
WORKER_CRASHfor the test in flight and skips the rest of the file, the same as a worker process. Engine disposal errors (shutdown-done) still get through, since in-process the engine really is disposed. - Scope: the scheduler keeps at most one in-process runner alive, so nothing is charged twice, and the host's own handlers apply again after the run.
standalone.ts(e2e mcp) is unchanged because it has no test body to charge.
flowchart LR
R[unhandledRejection] --> A{abandoned?}
A -- yes --> X[ignore]
A -- no --> S{strayRejection}
S -- attempt in flight / last test --> T[charged to test or UNHANDLED_REJECTION]
S -- nothing to charge --> F[fatal]
U[uncaughtException] --> F
F --> C[run error + WORKER_CRASH in flight, rest skipped]
Verified
Ran it locally: yes
- Built dist. A host script calls
run()fromdist/run/runner.json a fixture project, once with a file config (worker process) and once withrawConfig(in-process). It prints results, run errors, exit code, and the process listener counts before and after the run. - New
tests/integration/in-process-strays.test.tsruns the same kind of host in a child process, because vitest's own handlers would otherwise catch the rejection first. It covers five cases: a body rejection, a rejection between tests, an uncaught exception, an uncaught exception with an engine whosedisposethrows, and a rejection before any test finished. All five fail on main (the host crashes) and pass here. I mutation-checked it: dropping theprocess.off, the crashed flag, or theshutdown-donepass-through fails the matching tests.
Body does void Promise.reject(new Error('x')), followed by a second test:
| worker process | main, in-process | this branch, in-process | |
|---|---|---|---|
| stray test | failed x | host crashes: Error: x on stderr, no report | failed x |
| next test | passed | - | passed |
| exit / listeners after | 1 / 0,0 | process exit 1 | 1 / 0,0 |
Body throws from a setTimeout, followed by a second test:
| worker process | main, in-process | this branch, in-process | |
|---|---|---|---|
| throwing test | failed WORKER_CRASH | host crashes | failed WORKER_CRASH |
| next test | skipped | - | skipped |
| run errors / exit | ERROR / 3 | - | ERROR / 3 |