mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
* test: own temporary directories through createTestTempDirectory in remaining tests/ Give per-test directories in the remaining tests/ suites to createTestTempDirectory so onTestFinished removes them through removeTestWorkspace. Keep suite-scoped roots and child-process directories whose removal is the assertion. * test: drop empty cleanup callbacks and keep the capture skip reason visible Remove the no-op withVerifierCleanup steps left after directory removal moved to createTestTempDirectory. Put the native capture skip explanation in the Linux sample test name, because it.skipIf only tests truthiness. Co-authored-by: morluto <morluto@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
83 lines
3.3 KiB
TypeScript
83 lines
3.3 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { expect, it } from "vitest";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
it.each([
|
|
["initialization failure", "init", true],
|
|
["initialization and root cleanup failures", "init_close", false],
|
|
["command failure", "run", true],
|
|
["command cleanup failure", "close", false],
|
|
] as const)(
|
|
"retains the verifier root correctly after %s",
|
|
async (_name, failure, rootClosed) => {
|
|
const root = await createTestTempDirectory("rea-bun-owner-test-");
|
|
await mkdir(join(root, "scripts", "lib"), { recursive: true });
|
|
// VerifierFixture loads src/process/PrivateRuntimeRoot.ts beside its
|
|
// copied scripts/lib, so the stand-in root sits there.
|
|
await mkdir(join(root, "src", "process"), { recursive: true });
|
|
await mkdir(join(root, "dist", "domain"), { recursive: true });
|
|
await writeFile(
|
|
join(root, "scripts", "verify-bun-standalone.mjs"),
|
|
await readFile(
|
|
new URL("../../../scripts/verify-bun-standalone.mjs", import.meta.url),
|
|
),
|
|
);
|
|
for (const helper of [
|
|
"verifier-cleanup.mjs",
|
|
"verifier-fixture.mjs",
|
|
"canonical-temporary-directory.mjs",
|
|
"verifier-source-loader.mjs",
|
|
])
|
|
await writeFile(
|
|
join(root, "scripts", "lib", helper),
|
|
await readFile(
|
|
new URL(`../../../scripts/lib/${helper}`, import.meta.url),
|
|
),
|
|
);
|
|
await writeFile(
|
|
join(root, "scripts", "lib", "verify-commands.mjs"),
|
|
`export async function createVerifierCommands() {
|
|
if (process.env.FAULT.startsWith("init")) throw new Error("owner load refused");
|
|
return { async exec() { throw new Error("command refused"); }, async close() {
|
|
if (process.env.FAULT === "close") throw new Error("owner close refused");
|
|
} };
|
|
}`,
|
|
);
|
|
await writeFile(
|
|
join(root, "src", "process", "PrivateRuntimeRoot.ts"),
|
|
`import { writeFile } from "node:fs/promises";
|
|
export class PrivateRuntimeRoot { static async create() { return {
|
|
path: process.env.ROOT, async close() { if (process.env.FAULT === "init_close") throw new Error("root close refused"); await writeFile(process.env.CLOSED, "closed"); }
|
|
}; } }`,
|
|
);
|
|
await writeFile(
|
|
join(root, "dist", "domain", "evidence.js"),
|
|
`export function parseEvidence() { throw new Error("unexpected"); }`,
|
|
);
|
|
const marker = join(root, "closed");
|
|
const result = spawnSync(
|
|
process.execPath,
|
|
[join(root, "scripts", "verify-bun-standalone.mjs")],
|
|
{
|
|
encoding: "utf8",
|
|
timeout: 10_000,
|
|
env: { ...process.env, ROOT: root, CLOSED: marker, FAULT: failure },
|
|
},
|
|
);
|
|
expect(result.status).not.toBe(0);
|
|
expect(result.stderr).toContain(
|
|
failure.startsWith("init") ? "owner load refused" : "command refused",
|
|
);
|
|
if (failure === "close")
|
|
expect(result.stderr).toContain("owner close refused");
|
|
if (failure === "init_close")
|
|
expect(result.stderr).toContain("root close refused");
|
|
expect(await readFile(marker, "utf8").catch(() => null)).toBe(
|
|
rootClosed ? "closed" : null,
|
|
);
|
|
},
|
|
);
|