openclaw/scripts/lib/vitest-worker-bootstrap.mts
Peter Steinberger c904e712f9
fix(test): report one final failure per invocation (#134850)
* fix(test): report one final failure per invocation

Make public test CLIs own the final failure trailer after child execution, cleanup, and report publication. Internal execution entrypoints preserve process and signal lifetimes without duplicate reporting.

Closes #134841

* fix(test): register spawned test runners with Knip

* fix(test): classify spawned runners as development entries

* fix(test): include trailer helper in native wrapper closure

* test(pr): allow source directory in wrapper fixtures
2026-09-01 01:51:02 -07:00

33 lines
1.2 KiB
TypeScript

import { fileURLToPath, pathToFileURL } from "node:url";
import type { VitestWorkerDescriptor } from "./vitest-worker-artifacts.mts";
const descriptorKey = Symbol.for("openclaw.vitest.compiled-subprocess-descriptor");
const bootstrapProcess = process as NodeJS.Process & {
[descriptorKey]?: VitestWorkerDescriptor;
};
export function getVitestWorkerDescriptor(): VitestWorkerDescriptor | undefined {
return bootstrapProcess[descriptorKey];
}
// Private argv keeps the generation out of config hashes and inherited Node
// preloads. Vitest itself still parses the original CLI arguments.
if (import.meta.main) {
// Configs import the descriptor getter; do not hold this module's evaluation
// open while the CLI loads those configs.
void (async () => {
try {
const [directory, cli, ...args] = process.argv.slice(2);
if (!directory || !cli) {
throw new Error("Compiled subprocess bootstrap requires a directory and Vitest CLI");
}
bootstrapProcess[descriptorKey] = { directory };
const cliUrl = pathToFileURL(cli);
process.argv = [process.argv[0]!, fileURLToPath(cliUrl), ...args];
await import(cliUrl.href);
} catch (error) {
console.error(error);
process.exitCode = 1;
}
})();
}