Files
reverse-engineering-anything/tests/fixtures/runnerPostSpawnError.mjs
T
morluto b384e95417 test(boundaries): exercise producing owners and actionable errors (#10104)
* test(lifecycle): exercise producing handles and public runner

* test(native): verify initializer selection error attribution

* test(snapshot): prove unbound workflow history recomposition

* test(snapshot): require captured sources after parent admission failure
2026-11-11 21:34:29 +08:00

36 lines
1.2 KiB
JavaScript

import spawn from "cross-spawn";
import { existsSync } from "node:fs";
import { registerHooks } from "node:module";
const supervisor = new URL(
"../../scripts/run-exclusive-command.mjs",
import.meta.url,
).href;
// Replace only the supervisor's dependency, leaving its actual source and the
// public wrapper intact. Other imports still use the real implementation.
registerHooks({
resolve(specifier, context, nextResolve) {
if (specifier === "cross-spawn" && context.parentURL === supervisor)
return { url: import.meta.url, shortCircuit: true };
return nextResolve(specifier, context);
},
});
export default function spawnWithPostSpawnError(command, args, options) {
const child = spawn(command, args, options);
if (args.at(-1) !== "rea-runner-post-spawn-error") return child;
let timer;
child.once("close", () => clearInterval(timer));
child.once("spawn", () => {
timer = setInterval(() => {
if (!existsSync(process.env.REA_TEST_RUNNER_READY_PATH)) return;
clearInterval(timer);
process.stdout.write("controlled-post-spawn-error\n");
child.emit("error", new Error("controlled post-spawn child error"));
child.emit("error", new Error("controlled secondary child error"));
}, 5);
});
return child;
}