mirror of
https://github.com/morluto/rea
synced 2026-10-28 06:46:47 -04:00
72ba1cd92b
Own operation results and exact rejections in withVerifierCleanup, including undefined, null and independent cleanup failures. Remove the optional-primary cleanup contract and migrate every caller, preserving returns, annotations, signal restoration and dependent cleanup order. Make Frida/JEB reporters fail on reasonless rejections and retain JEB fixture files while provider cleanup is incomplete. Own the nested packaged WASM verifier and expose its composite process/root cleanup capability for retry. Update runnable docs and isolated fixture dependencies. Validation: 547 focused cases in 20 files, eight isolated boundary unit checks, static/build/docs/discovery gates and duplication check (3.58%). Node process, SDK and descriptor cleanup are exercised; provider and packaging results in orchestration tests are simulated. Pack/install subprocess ownership remains with the existing shared package runner outside the nested-command change.
120 lines
3.5 KiB
JavaScript
120 lines
3.5 KiB
JavaScript
#!/usr/bin/env node
|
|
import { join } from "node:path";
|
|
import { mkdir } from "node:fs/promises";
|
|
import { randomUUID } from "node:crypto";
|
|
import { fileURLToPath } from "node:url";
|
|
import { PrivateRuntimeRoot } from "../dist/process/PrivateRuntimeRoot.js";
|
|
import {
|
|
OwnedCommandFailure,
|
|
runOwnedCommand,
|
|
} from "../dist/process/OwnedCommand.js";
|
|
import { withVerifierCleanup } from "./lib/verifier-cleanup.mjs";
|
|
import { execNpm } from "./lib/verify-package-core.mjs";
|
|
import { WABT_WORKFLOW_TIMEOUT_MS } from "./lib/wabt-verifier-timeouts.mjs";
|
|
import { verifyPackagePack } from "./verify-package-pack.mjs";
|
|
|
|
/** Preserve the actual dependent process/root owner across failed cleanup. */
|
|
class PackagedWasmCleanupFailure extends Error {
|
|
constructor(cause, cleanupOwner, runtimeRoot) {
|
|
super(
|
|
`Packaged WASM verifier cleanup incomplete; retained ${runtimeRoot.path}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
{ cause },
|
|
);
|
|
this.name = "PackagedWasmCleanupFailure";
|
|
this.cleanupOwner = cleanupOwner;
|
|
this.runtimeRoot = runtimeRoot;
|
|
}
|
|
}
|
|
|
|
const root = await PrivateRuntimeRoot.create({
|
|
prefix: "rea-wabt-package-verifier-",
|
|
});
|
|
let commandCleanupOwner;
|
|
let closing;
|
|
const cleanupOwner = {
|
|
close() {
|
|
if (closing !== undefined) return closing;
|
|
let attempt;
|
|
attempt = (async () => {
|
|
if (commandCleanupOwner !== undefined) {
|
|
const stopped = await commandCleanupOwner.stop();
|
|
if (stopped.status === "incomplete")
|
|
throw new Error(stopped.reason, { cause: stopped });
|
|
commandCleanupOwner = undefined;
|
|
}
|
|
await root.close();
|
|
})().catch((cause) => {
|
|
if (closing === attempt) closing = undefined;
|
|
throw new PackagedWasmCleanupFailure(cause, cleanupOwner, root);
|
|
});
|
|
closing = attempt;
|
|
return attempt;
|
|
},
|
|
};
|
|
const verifiedOutput = await withVerifierCleanup(async () => {
|
|
const { tarball } = await verifyPackagePack({
|
|
root: process.cwd(),
|
|
workspace: root.path,
|
|
});
|
|
const prefix = join(root.path, "prefix");
|
|
const home = join(root.path, "home");
|
|
await mkdir(home);
|
|
const environment = {
|
|
...process.env,
|
|
HOME: home,
|
|
USERPROFILE: home,
|
|
XDG_CONFIG_HOME: join(home, ".config"),
|
|
XDG_CACHE_HOME: join(home, ".cache"),
|
|
};
|
|
await execNpm(
|
|
[
|
|
"install",
|
|
"--global",
|
|
"--ignore-scripts",
|
|
"--omit=dev",
|
|
"--install-strategy=nested",
|
|
"--prefix",
|
|
prefix,
|
|
tarball,
|
|
],
|
|
{ env: environment, timeout: 120_000, maxBuffer: 4 * 1024 * 1024 },
|
|
);
|
|
const entrypoint = join(
|
|
prefix,
|
|
...(process.platform === "win32"
|
|
? ["node_modules"]
|
|
: ["lib", "node_modules"]),
|
|
"rea-agents",
|
|
"scripts",
|
|
"rea.mjs",
|
|
);
|
|
let verified;
|
|
try {
|
|
verified = await runOwnedCommand(
|
|
{
|
|
command: process.execPath,
|
|
arguments: [
|
|
fileURLToPath(new URL("./verify-wasm-artifact.mjs", import.meta.url)),
|
|
entrypoint,
|
|
"--require-tools",
|
|
],
|
|
cwd: process.cwd(),
|
|
hostEnvironment: environment,
|
|
expectedCommand: process.execPath,
|
|
runId: `rea-packaged-wabt-${randomUUID()}`,
|
|
sweepTokenOwnedProcesses: true,
|
|
},
|
|
{
|
|
timeoutMs: WABT_WORKFLOW_TIMEOUT_MS,
|
|
diagnosticBytes: 4 * 1024 * 1024,
|
|
},
|
|
);
|
|
} catch (cause) {
|
|
if (cause instanceof OwnedCommandFailure)
|
|
commandCleanupOwner = cause.cleanupOwner;
|
|
throw cause;
|
|
}
|
|
return verified.stdout.text;
|
|
}, [() => cleanupOwner.close()]);
|
|
process.stdout.write(verifiedOutput);
|