mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 11:01:11 +00:00
* fix(process): report denied inspection as typed cleanup failures Preserve the native ps diagnostic through owned-worker cleanup and finalize one-shot JavaScript analysis before Evidence delivery. Retain mandatory inspection and existing cleanup authority. Preserve the inspector diagnostic when the initial process-table read succeeds but pre-signal revalidation fails, and remove the unreachable typed-error branch so retained artifact retry failures project through the existing cleanup contract. * fix(resources): preserve independent close failure ownership * fix(cli): retain cleanup recovery and nested close evidence * refactor(providers): classify rejected closes at the shared boundary * test(cli): preserve bundle metadata and physical inspection failures * fix(cli): preserve the JavaScript failure envelope after finalization * test(cli): validate the JavaScript error envelope at its boundary * fix(providers): preserve unnamed close failure resources * fix(cli): retain invocation owners through outer cleanup * test(cli): distinguish reported cleanup failures from uncaught errors * fix(cli): compose each runtime’s declared cleanup owners * test(cli): preserve the original cleanup rejection * test(cli): allow cleanup retry recovery after a reported failure * fix(cli): report final cleanup after returned results * fix(cli): preserve launcher executable mode * test(cli): retain invocation cleanup in file sessions --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import childProcess from "node:child_process";
|
|
import { appendFileSync } from "node:fs";
|
|
import { syncBuiltinESMExports } from "node:module";
|
|
import { basename } from "node:path";
|
|
|
|
// Deny only post-analysis inspection. Startup and the real inert worker run normally.
|
|
let completed = false;
|
|
let interrupted = false;
|
|
const write = process.stderr.write.bind(process.stderr);
|
|
process.stderr.write = (chunk, ...args) => {
|
|
const text = String(chunk);
|
|
if (
|
|
text.includes('"phase":"analyze_javascript_application"') &&
|
|
text.includes('"terminal":true')
|
|
)
|
|
completed = true;
|
|
return write(chunk, ...args);
|
|
};
|
|
const spawn = childProcess.spawn;
|
|
childProcess.spawn = (command, ...args) => {
|
|
if (completed && basename(command) === "ps") {
|
|
if (process.env.REA_INSPECTION_MODE === "cancel" && !interrupted) {
|
|
interrupted = true;
|
|
process.emit("SIGINT");
|
|
}
|
|
if (process.env.REA_INSPECTION_MODE !== "deny")
|
|
return spawn(command, ...args);
|
|
appendFileSync(process.env.REA_INSPECTION_TRACE, '{"kind":"denied"}\n');
|
|
throw Object.assign(new Error("spawn EPERM"), {
|
|
code: "EPERM",
|
|
syscall: "spawn ps",
|
|
path: command,
|
|
});
|
|
}
|
|
const child = spawn(command, ...args);
|
|
const options = args.at(-1);
|
|
if (
|
|
options?.cwd?.includes("rea-javascript-analysis-") &&
|
|
options?.env?.REA_PROCESS_RUN_ID?.startsWith("rea-javascript-analysis-")
|
|
)
|
|
appendFileSync(
|
|
process.env.REA_INSPECTION_TRACE,
|
|
JSON.stringify({
|
|
kind: "worker",
|
|
root: options.cwd,
|
|
leaderPid: child.pid,
|
|
processGroupId: child.pid,
|
|
runId: options.env.REA_PROCESS_RUN_ID,
|
|
}) + "\n",
|
|
);
|
|
return child;
|
|
};
|
|
syncBuiltinESMExports();
|