test: own temporary directories through createTestTempDirectory in remaining tests/ (#12727)

* 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>
This commit is contained in:
authored and GitHub committed 2026-11-19 23:22:53 -05:00
1 parent e58c60b36e
commit 385e5d228f
46 files changed
+1487 -1738

No files matched your search

@@ -286,8 +286,7 @@ it("excludes declared binary lengths through CLI, MCP and retained capture pages
});
it("reads actual upstream HAR packages in an owned process and retains selected producer order", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-history-har-"));
onTestFinished(() => rm(root, { recursive: true, force: true }));
const root = await createTestTempDirectory("rea-history-har-");
const fixture = historicalHar();
const first = fixture.log.entries[0];
if (first === undefined) throw new Error("fixture missing");
@@ -314,8 +313,7 @@ it("reads actual upstream HAR packages in an owned process and retains selected
});
it("keeps malformed JSON separate from absent external mitmproxy capability", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-history-errors-"));
onTestFinished(() => rm(root, { recursive: true, force: true }));
const root = await createTestTempDirectory("rea-history-errors-");
const path = join(root, "capture.har");
await writeFile(path, "{malformed-private-json");
const malformed = await cli(path, "har");
@@ -333,8 +331,7 @@ it("keeps malformed JSON separate from absent external mitmproxy capability", as
});
it("reports the actual HAR decoder nesting constraint as a typed selected-input issue", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-history-depth-"));
onTestFinished(() => rm(root, { recursive: true, force: true }));
const root = await createTestTempDirectory("rea-history-depth-");
let extension: unknown = "leaf";
for (let depth = 0; depth < 66; depth++) extension = { child: extension };
const path = join(root, "deep.har");
+3 -4
View File
@@ -27,6 +27,7 @@ import {
analysisViewJavaScriptEvidence,
analysisViewLayoutEvidence,
} from "../../fixtures/analysisView.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const providerIdentity = {
id: "test.path-boundary",
@@ -53,7 +54,7 @@ const serveJson = async (
it.skipIf(process.platform === "win32")(
"keeps caller-selected JSON paths through the public CLI and provider boundaries",
async () => {
const root = await mkdtemp(join(tmpdir(), "rea-cli-json-path-"));
const root = await createTestTempDirectory("rea-cli-json-path-");
const originalCwd = process.cwd();
const originalExitCode = process.exitCode;
try {
@@ -167,7 +168,6 @@ it.skipIf(process.platform === "win32")(
} finally {
process.chdir(originalCwd);
process.exitCode = originalExitCode;
await rm(root, { recursive: true, force: true });
}
},
);
@@ -175,7 +175,7 @@ it.skipIf(process.platform === "win32")(
it.skipIf(process.platform === "win32")(
"reads the caller-selected Evidence file through the registered CLI",
async () => {
const root = await mkdtemp(join(tmpdir(), "rea-cli-evidence-path-"));
const root = await createTestTempDirectory("rea-cli-evidence-path-");
const originalCwd = process.cwd();
const originalExitCode = process.exitCode;
try {
@@ -220,7 +220,6 @@ it.skipIf(process.platform === "win32")(
} finally {
process.chdir(originalCwd);
process.exitCode = originalExitCode;
await rm(root, { recursive: true, force: true });
}
},
);
+5 -10
View File
@@ -12,6 +12,7 @@ import {
spawnOwnedProviderProcess,
ProviderProcessSupervisor,
} from "../../../src/process/ProviderProcess.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const SESSION_ID = "27d3e3f1-f1e5-49ae-91ec-95af1f343a5a";
const listen = async (
@@ -31,14 +32,11 @@ describe("Cutter CLI commands", () => {
afterEach(async () => {
if (server !== undefined)
await new Promise<void>((resolve) => server?.close(() => resolve()));
if (directory !== undefined)
await rm(directory, { recursive: true, force: true });
directory = undefined;
server = undefined;
});
it("lists sessions from the selected bridge directory", async () => {
directory = await mkdtemp(join(tmpdir(), "rea-cutter-cli-test-"));
directory = await createTestTempDirectory("rea-cutter-cli-test-");
const result = await serveCli(["list-cutter-sessions", "--json"], {
REA_CUTTER_BRIDGE_DIR: directory,
@@ -59,7 +57,7 @@ describe("Cutter CLI commands", () => {
it.skipIf(process.platform === "win32")(
"awaits discovery cancellation on SIGINT and returns its typed outcome with exit130",
async () => {
directory = await mkdtemp(join(tmpdir(), "rea-cutter-cli-cancel-"));
directory = await createTestTempDirectory("rea-cutter-cli-cancel-");
const sockets = new Set<import("node:net").Socket>();
let accepted = 0;
server = createServer((socket) => {
@@ -125,7 +123,7 @@ describe("Cutter CLI commands", () => {
);
it("reports an unavailable selected session for a command", async () => {
directory = await mkdtemp(join(tmpdir(), "rea-cutter-cli-test-"));
directory = await createTestTempDirectory("rea-cutter-cli-test-");
const result = await serveCli(
["cutter-command", SESSION_ID, "0", "pdi", "--json"],
@@ -157,14 +155,11 @@ describe("Cutter CLI command output flags", () => {
afterEach(async () => {
if (server !== undefined)
await new Promise<void>((resolve) => server?.close(() => resolve()));
if (directory !== undefined)
await rm(directory, { recursive: true, force: true });
directory = undefined;
server = undefined;
});
it("returns Evidence when the selected Cutter session completes a command", async () => {
directory = await mkdtemp(join(tmpdir(), "rea-cutter-cli-test-"));
directory = await createTestTempDirectory("rea-cutter-cli-test-");
const token = "synthetic-cutter-cli-token-for-test";
let nextConnectionOrdinal = 0;
const commandJsonModes: boolean[] = [];
+141 -154
View File
@@ -10,6 +10,7 @@ import { FRIDA_TOOL_CONTRACTS } from "../../../src/contracts/fridaToolContracts.
import type { FridaInstrumentationPort } from "../../../src/ports/frida/FridaInstrumentationPort.js";
import { AnalysisCapabilityUnavailableError } from "../../../src/domain/analysisErrorCore.js";
import { FridaInstrumentationManager } from "../../../src/frida/FridaInstrumentationManager.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it.each([
{
@@ -414,7 +415,7 @@ it("forwards every selected spawn argument through the CLI and shared service",
});
it("keeps Frida script-file identity in original bytes when UTF-8 decoding replaces invalid bytes", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-frida-script-identity-"));
const directory = await createTestTempDirectory("rea-frida-script-identity-");
const files = [
{
name: "ff.js",
@@ -436,118 +437,114 @@ it("keeps Frida script-file identity in original bytes when UTF-8 decoding repla
bytes: Buffer.from("// ordinary ASCII\nsend(1);", "ascii"),
},
];
try {
await Promise.all(
files.map(({ name, bytes }) => writeFile(join(directory, name), bytes)),
);
const loadedSources: string[] = [];
const deviceManager = {
async getDeviceById() {
return {
id: "local",
name: "Fixture device",
type: "local",
async getProcessByPid(pid: number) {
return { pid, name: "fixture" };
},
async attach() {
let detached = false;
return {
pid: 71,
detached: { connect() {}, disconnect() {} },
isDetached: () => detached,
async detach() {
detached = true;
},
async createScript(source: string) {
loadedSources.push(source);
return {
message: { connect() {}, disconnect() {} },
async load() {},
async unload() {},
};
},
};
},
};
},
} as unknown as DeviceManager;
await Promise.all(
files.map(({ name, bytes }) => writeFile(join(directory, name), bytes)),
);
const loadedSources: string[] = [];
const deviceManager = {
async getDeviceById() {
return {
id: "local",
name: "Fixture device",
type: "local",
async getProcessByPid(pid: number) {
return { pid, name: "fixture" };
},
async attach() {
let detached = false;
return {
pid: 71,
detached: { connect() {}, disconnect() {} },
isDetached: () => detached,
async detach() {
detached = true;
},
async createScript(source: string) {
loadedSources.push(source);
return {
message: { connect() {}, disconnect() {} },
async load() {},
async unload() {},
};
},
};
},
};
},
} as unknown as DeviceManager;
for (const { name } of files) {
// The CLI resolves a relative script file against its working
// directory; the contract admits only the absolute path. A Windows
// temporary directory on another drive than the checkout has no
// relative spelling, so only there the absolute path is passed.
const relativeSpelling = relative(process.cwd(), join(directory, name));
if (name === "ascii.js" && process.platform !== "win32")
expect(isAbsolute(relativeSpelling)).toBe(false);
const scriptFile =
name === "ascii.js" && !isAbsolute(relativeSpelling)
? relativeSpelling
: join(directory, name);
const provider = new FridaInstrumentationManager({ deviceManager });
let stdout = "";
let exitCode = 0;
await createCli({}, undefined, provider).serve(
[
"instrument-with-frida",
"attach",
"71",
"--script-file",
scriptFile,
"--duration-ms",
"0",
"--json",
],
{
env: {},
exit: (code) => {
exitCode = code;
},
stdout: (text) => {
stdout += text;
for (const { name } of files) {
// The CLI resolves a relative script file against its working
// directory; the contract admits only the absolute path. A Windows
// temporary directory on another drive than the checkout has no
// relative spelling, so only there the absolute path is passed.
const relativeSpelling = relative(process.cwd(), join(directory, name));
if (name === "ascii.js" && process.platform !== "win32")
expect(isAbsolute(relativeSpelling)).toBe(false);
const scriptFile =
name === "ascii.js" && !isAbsolute(relativeSpelling)
? relativeSpelling
: join(directory, name);
const provider = new FridaInstrumentationManager({ deviceManager });
let stdout = "";
let exitCode = 0;
await createCli({}, undefined, provider).serve(
[
"instrument-with-frida",
"attach",
"71",
"--script-file",
scriptFile,
"--duration-ms",
"0",
"--json",
],
{
env: {},
exit: (code) => {
exitCode = code;
},
stdout: (text) => {
stdout += text;
},
},
);
expect(exitCode).toBe(0);
const output = JSON.parse(stdout) as {
readonly normalized_result: { readonly source_path: string };
};
expect(isAbsolute(output.normalized_result.source_path)).toBe(true);
const bytes = files.find((file) => file.name === name)?.bytes;
if (bytes === undefined) throw new Error(`Missing fixture ${name}`);
const decodedSource = bytes.toString("utf8");
expect(loadedSources.at(-1)).toBe(decodedSource);
const rawDigest = createHash("sha256").update(bytes).digest("hex");
const loadedSourceDigest = createHash("sha256")
.update(decodedSource, "utf8")
.digest("hex");
const outputText = JSON.stringify(output);
if (name === "ff.js" || name === "fe.js") {
expect(rawDigest).not.toBe(loadedSourceDigest);
expect(output).toMatchObject({
normalized_result: { source_sha256: rawDigest },
raw_result: {
source_representation: {
encoding: "utf8",
decoding: "replacement",
loaded_source_sha256: loadedSourceDigest,
},
},
);
expect(exitCode).toBe(0);
const output = JSON.parse(stdout) as {
readonly normalized_result: { readonly source_path: string };
};
expect(isAbsolute(output.normalized_result.source_path)).toBe(true);
const bytes = files.find((file) => file.name === name)?.bytes;
if (bytes === undefined) throw new Error(`Missing fixture ${name}`);
const decodedSource = bytes.toString("utf8");
expect(loadedSources.at(-1)).toBe(decodedSource);
const rawDigest = createHash("sha256").update(bytes).digest("hex");
const loadedSourceDigest = createHash("sha256")
.update(decodedSource, "utf8")
.digest("hex");
const outputText = JSON.stringify(output);
if (name === "ff.js" || name === "fe.js") {
expect(rawDigest).not.toBe(loadedSourceDigest);
expect(output).toMatchObject({
normalized_result: { source_sha256: rawDigest },
raw_result: {
source_representation: {
encoding: "utf8",
decoding: "replacement",
loaded_source_sha256: loadedSourceDigest,
},
},
limitations: expect.arrayContaining([
expect.stringMatching(/replacement|original bytes/iu),
]),
});
} else {
expect(output).toMatchObject({
normalized_result: { source_sha256: rawDigest },
});
expect(outputText).not.toContain("source_representation");
}
await provider.closeAll();
limitations: expect.arrayContaining([
expect.stringMatching(/replacement|original bytes/iu),
]),
});
} else {
expect(output).toMatchObject({
normalized_result: { source_sha256: rawDigest },
});
expect(outputText).not.toContain("source_representation");
}
} finally {
await rm(directory, { recursive: true, force: true });
await provider.closeAll();
}
});
@@ -705,53 +702,43 @@ it.each([
);
it("advances each Frida script source to the attach target error without attaching or spawning", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-frida-script-source-"));
const directory = await createTestTempDirectory("rea-frida-script-source-");
const scriptPath = join(directory, "source.js");
try {
await writeFile(scriptPath, "send(1);\n");
for (const scriptArguments of [
["--script", "send(1)"],
["--script-file", scriptPath],
]) {
let starts = 0;
const provider = {
async startSession() {
starts += 1;
throw new Error("Frida must not attach or spawn for an invalid PID");
await writeFile(scriptPath, "send(1);\n");
for (const scriptArguments of [
["--script", "send(1)"],
["--script-file", scriptPath],
]) {
let starts = 0;
const provider = {
async startSession() {
starts += 1;
throw new Error("Frida must not attach or spawn for an invalid PID");
},
} as unknown as FridaInstrumentationPort;
let stdout = "";
await createCli({}, undefined, provider).serve(
["instrument-with-frida", "attach", "abc", ...scriptArguments, "--json"],
{
env: {},
exit: () => undefined,
stdout: (text) => {
stdout += text;
},
} as unknown as FridaInstrumentationPort;
let stdout = "";
await createCli({}, undefined, provider).serve(
[
"instrument-with-frida",
"attach",
"abc",
...scriptArguments,
"--json",
],
{
env: {},
exit: () => undefined,
stdout: (text) => {
stdout += text;
},
);
expect(JSON.parse(stdout)).toMatchObject({
code: "invalid_request",
details: {
issues: [
{
path: ["target"],
reason: "invalid_value",
message: "attach mode needs a positive integer process ID.",
},
},
);
expect(JSON.parse(stdout)).toMatchObject({
code: "invalid_request",
details: {
issues: [
{
path: ["target"],
reason: "invalid_value",
message: "attach mode needs a positive integer process ID.",
},
],
},
});
expect(starts).toBe(0);
}
} finally {
await rm(directory, { recursive: true, force: true });
],
},
});
expect(starts).toBe(0);
}
});
+15 -25
View File
@@ -62,6 +62,7 @@ import { projectAnalysisError } from "../../../src/domain/analysisErrorProjectio
import { waitForProviderProcessReady } from "../../fixtures/providerProcess.js";
import { EvmInterfaceService } from "../../../src/application/evm/EvmInterfaceService.js";
import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
let limitsWorkspace = "";
beforeAll(async () => {
@@ -132,7 +133,7 @@ it.each(["completed", "invalid", "cancelled"] as const)(
it.each(["pre-aborted", "admission", "close"] as const)(
"preserves opaque caller reasons through service cancellation at %s",
async (stage) => {
const workspace = await mkdtemp(join(tmpdir(), "rea-evm-artifact-cancel-"));
const workspace = await createTestTempDirectory("rea-evm-artifact-cancel-");
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
const createRuntime = vi.fn(async () => {
@@ -181,7 +182,6 @@ it.each(["pre-aborted", "admission", "close"] as const)(
closeState.onClosed = undefined;
closeState.onLimits = undefined;
await provider.close();
await rm(workspace, { recursive: true, force: true });
}
},
);
@@ -194,7 +194,7 @@ it.each([
] as const)(
"updates a returned cleanup error after later root release: %s",
async (scenario) => {
const workspace = await mkdtemp(join(tmpdir(), "rea-evm-cleanup-retry-"));
const workspace = await createTestTempDirectory("rea-evm-cleanup-retry-");
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
let rootPath = "";
@@ -318,13 +318,12 @@ it.each([
} catch {
// Preserve the assertion's original failure; the workspace cleanup follows.
}
await rm(workspace, { recursive: true, force: true });
}
},
);
it("keeps descriptor cleanup in close aggregates until the exact file lease releases", async () => {
const workspace = await mkdtemp(join(tmpdir(), "rea-evm-descriptor-retry-"));
const workspace = await createTestTempDirectory("rea-evm-descriptor-retry-");
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
closeState.path = input;
@@ -372,12 +371,11 @@ it("keeps descriptor cleanup in close aggregates until the exact file lease rele
} catch {
// Preserve the assertion's original failure while releasing test files.
}
await rm(workspace, { recursive: true, force: true });
}
});
it("keeps a mixed root and reply-descriptor aggregate pending until both owners release", async () => {
const workspace = await mkdtemp(join(tmpdir(), "rea-evm-mixed-owners-"));
const workspace = await createTestTempDirectory("rea-evm-mixed-owners-");
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
closeState.path = "";
@@ -462,13 +460,12 @@ it("keeps a mixed root and reply-descriptor aggregate pending until both owners
} catch {
// Preserve the assertion's original failure while releasing test files.
}
await rm(workspace, { recursive: true, force: true });
}
});
it("releases a retained process independently while a root cleanup retry remains pending", async () => {
const workspace = await mkdtemp(
join(tmpdir(), "rea-evm-process-root-retry-"),
const workspace = await createTestTempDirectory(
"rea-evm-process-root-retry-",
);
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
@@ -575,12 +572,11 @@ it("releases a retained process independently while a root cleanup retry remains
} catch {
// Preserve the assertion's original failure while releasing test files.
}
await rm(workspace, { recursive: true, force: true });
}
});
it("preserves an active cancellation through denied owned-group cleanup and later retry", async () => {
const workspace = await mkdtemp(join(tmpdir(), "rea-evm-cancel-process-"));
const workspace = await createTestTempDirectory("rea-evm-cancel-process-");
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
const controller = new AbortController();
@@ -675,7 +671,6 @@ it("preserves an active cancellation through denied owned-group cleanup and late
} catch {
// Preserve the assertion's original failure while releasing test files.
}
await rm(workspace, { recursive: true, force: true });
}
});
@@ -691,8 +686,8 @@ it.each([
] as const)(
"retains validated reply ownership through finalization: %s",
async (scenario) => {
const workspace = await mkdtemp(
join(tmpdir(), "rea-evm-reply-finalization-"),
const workspace = await createTestTempDirectory(
"rea-evm-reply-finalization-",
);
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
@@ -825,7 +820,6 @@ it.each([
closeState.onClosing = undefined;
closeState.readFailure = undefined;
await provider.close();
await rm(workspace, { recursive: true, force: true });
}
},
);
@@ -833,8 +827,8 @@ it.each([
it.each(["physical-read", "completed-late-cancel"] as const)(
"retains only completed caller carrier identity: %s",
async (scenario) => {
const workspace = await mkdtemp(
join(tmpdir(), "rea-evm-carrier-finalization-"),
const workspace = await createTestTempDirectory(
"rea-evm-carrier-finalization-",
);
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
@@ -894,7 +888,6 @@ it.each(["physical-read", "completed-late-cancel"] as const)(
closeState.onClosing = undefined;
closeState.readFailure = undefined;
await provider.close();
await rm(workspace, { recursive: true, force: true });
}
},
);
@@ -910,7 +903,7 @@ it.each([
] as const)(
"preserves exact reserved-exit marker receipt and cleanup: %s",
async (scenario) => {
const workspace = await mkdtemp(join(tmpdir(), "rea-evm-marker-receipt-"));
const workspace = await createTestTempDirectory("rea-evm-marker-receipt-");
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
let markerPath = "";
@@ -1009,13 +1002,12 @@ it.each([
closeState.onClosing = undefined;
closeState.readFailure = undefined;
await provider.close();
await rm(workspace, { recursive: true, force: true });
}
},
);
it("keeps the selected limiter and child environment together while later inspections reconfigure", async () => {
const workspace = await mkdtemp(join(tmpdir(), "rea-evm-environment-"));
const workspace = await createTestTempDirectory("rea-evm-environment-");
const input = join(workspace, "selected.hex");
const limiter = join(workspace, "selected-limiter");
const { symlink } = await import("node:fs/promises");
@@ -1060,7 +1052,6 @@ it("keeps the selected limiter and child environment together while later inspec
} finally {
closeState.onLimits = undefined;
await provider.close();
await rm(workspace, { recursive: true, force: true });
}
});
@@ -1071,7 +1062,7 @@ it.each([
] as const)(
"counts %s from the worker launch as cancellation: %s",
async (_label, thrown, cancelled) => {
const workspace = await mkdtemp(join(tmpdir(), "rea-evm-abort-owner-"));
const workspace = await createTestTempDirectory("rea-evm-abort-owner-");
const input = join(workspace, "selected.hex");
await writeFile(input, "0x60006000f3\n");
const controller = new AbortController();
@@ -1107,7 +1098,6 @@ it.each([
} else expect(result.error).not.toBeInstanceOf(AnalysisCancelledError);
} finally {
await provider.close();
await rm(workspace, { recursive: true, force: true });
}
},
);
@@ -16,6 +16,7 @@ import {
AdbInputSnapshotFailure,
snapshotAdbInput,
} from "../../../src/adb/AdbInputSnapshot.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
vi.mock("node:fs/promises", async (importOriginal) => {
const actual = await importOriginal<typeof import("node:fs/promises")>();
@@ -27,7 +28,7 @@ it("retains and retries a source handle that fails close during admission", asyn
await vi.importActual<typeof import("node:fs/promises")>(
"node:fs/promises",
);
const parent = await mkdtemp(join(tmpdir(), "rea-adb-snapshot-test-"));
const parent = await createTestTempDirectory("rea-adb-snapshot-test-");
const root = await PrivateRuntimeRoot.create({ parent });
const resources = new ArtifactResourceScope();
const sourcePath = join(parent, "selected.apk");
@@ -75,6 +76,5 @@ it("retains and retries a source handle that fails close during admission", asyn
if (source !== undefined && source.fd !== -1) await source.close();
vi.restoreAllMocks();
await root.close();
await rm(parent, { recursive: true, force: true });
}
});
@@ -11,6 +11,7 @@ import {
selectNpmDownloadDuplicateDeletions,
selectPrefixDeletions,
} from "../../../scripts/ci/cache-retention.mjs";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const cache = (
id: number,
@@ -532,7 +533,7 @@ describe("repeated cache ids", () => {
});
it("runs retention from the command line without deleting on an unsafe prefix", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-cache-retention-"));
const root = await createTestTempDirectory("rea-cache-retention-");
const log = join(root, "gh.log");
const gh = join(root, "gh");
await writeFile(
@@ -20,18 +20,10 @@ import {
} from "../../../src/application/MacHopper.js";
import { SetupCleanupOwner } from "../../../src/application/SetupCleanupOwner.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
const roots: string[] = [];
afterEach(async () => {
await Promise.all(
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
);
});
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const temporaryRoot = async (): Promise<string> => {
const root = await mkdtemp(join(tmpdir(), "rea-hopper-owned-stage-test-"));
roots.push(root);
const root = await createTestTempDirectory("rea-hopper-owned-stage-test-");
return root;
};
@@ -18,6 +18,7 @@ import { ok as resultOk, err } from "../../../src/domain/result.js";
import { AnalysisCapabilityUnavailableError } from "../../../src/domain/analysisErrorCore.js";
import { nativeDispatchMetadataResultSchema } from "../../../src/domain/native/objcSwiftMetadata.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const targetObservation = (value: unknown) =>
resultOk(
@@ -218,16 +219,10 @@ const fixturePort = (): AnalysisOperationPort => ({
});
const resources: Array<{ close(): Promise<void> }> = [];
let decompileOutput: string | undefined;
afterEach(async () => {
await Promise.all(
resources.splice(0).map(async (resource) => resource.close()),
);
if (decompileOutput !== undefined) {
await rm(decompileOutput, { recursive: true, force: true });
decompileOutput = undefined;
}
});
const connect = async (analysis: AnalysisOperationPort = fixturePort()) => {
@@ -268,8 +263,7 @@ describe("enhanced MCP tools", () => {
// oxlint-disable-next-line max-lines-per-function -- one exhaustive registration test guards the public tool catalog.
it("executes all enhanced tools through production registration", async () => {
const client = await connect();
const outputParent = await mkdtemp(join(tmpdir(), "rea-decompile-all-"));
decompileOutput = outputParent;
const outputParent = await createTestTempDirectory("rea-decompile-all-");
const calls = [
["get_objc_classes", { pattern: "Fixture" }],
["get_objc_protocols", {}],
+2 -2
View File
@@ -47,6 +47,7 @@ import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { phaseGate } from "../../support/lifecycleHarness.js";
import { waitFor } from "../../support/testWait.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const nativeFixture = () => {
const created: string[] = [];
@@ -1141,8 +1142,7 @@ it("retains cancellation source facts without claiming native creation when no s
it("retains original malformed file identity and decoded representation through a rejected cancelled MCP load", async () => {
const { fixture, id, held } = await scriptLoadFixture();
const directory = await mkdtemp(join(tmpdir(), "rea-frida-file-cancel-"));
onTestFinished(() => rm(directory, { recursive: true, force: true }));
const directory = await createTestTempDirectory("rea-frida-file-cancel-");
const path = join(directory, "script.js");
const bytes = Buffer.from([0x2f, 0x2f, 0xff, 0x0a]);
await writeFile(path, bytes);
+8 -20
View File
@@ -40,11 +40,12 @@ import {
fakeGdbStartupPreamble,
} from "../providers/gdbTestHelpers.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it.skipIf(process.platform === "win32")(
"keeps a failed GDB startup closed through MCP and retries its retained owner before console admission",
async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-gdb-mcp-startup-"));
const directory = await createTestTempDirectory("rea-gdb-mcp-startup-");
const provider = join(directory, "fake-gdb.mjs");
await writeFile(
provider,
@@ -135,11 +136,7 @@ process.stdin.on("data", (chunk) => {
() => server.close(),
async () => {
await manager.closeAll();
try {
await expectNoUnmodeledGdbCommands(join(directory, "unmodeled"));
} finally {
await rm(directory, { recursive: true, force: true });
}
await expectNoUnmodeledGdbCommands(join(directory, "unmodeled"));
},
]);
}
@@ -149,7 +146,7 @@ process.stdin.on("data", (chunk) => {
it.skipIf(process.platform === "win32")(
"propagates MCP cancellation into a running GDB command",
async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-gdb-mcp-cancel-"));
const directory = await createTestTempDirectory("rea-gdb-mcp-cancel-");
const provider = join(directory, "fake-gdb.mjs");
const commandPath = join(directory, "command-started");
await writeFile(
@@ -262,7 +259,6 @@ process.stdin.on("data", async (chunk) => {
() => server.close(),
async () => {
await manager.closeAll();
await rm(directory, { recursive: true, force: true });
},
]);
}
@@ -272,7 +268,7 @@ process.stdin.on("data", async (chunk) => {
it.skipIf(process.platform === "win32")(
"accepts caller-selected inferior_tty and exposes verified sink status through MCP",
async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-gdb-mcp-tty-"));
const directory = await createTestTempDirectory("rea-gdb-mcp-tty-");
const provider = join(directory, "fake-gdb.mjs");
const tty = `${directory}/inferior-"terminal-Ω"`;
await writeFile(
@@ -347,11 +343,7 @@ process.stdin.on("data", (chunk) => {
() => server.close(),
async () => {
await manager.closeAll();
try {
await expectNoUnmodeledGdbCommands(join(directory, "unmodeled"));
} finally {
await rm(directory, { recursive: true, force: true });
}
await expectNoUnmodeledGdbCommands(join(directory, "unmodeled"));
},
]);
}
@@ -361,7 +353,7 @@ process.stdin.on("data", (chunk) => {
it.skipIf(process.platform === "win32")(
"exposes lossy GDB MI decoding through the strict status MCP contract",
async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-gdb-mcp-mi-utf8-"));
const directory = await createTestTempDirectory("rea-gdb-mcp-mi-utf8-");
const provider = join(directory, "fake-gdb.mjs");
await writeFile(
provider,
@@ -419,11 +411,7 @@ process.stdin.on("data", (chunk) => {
() => server.close(),
async () => {
await manager.closeAll();
try {
await expectNoUnmodeledGdbCommands(join(directory, "unmodeled"));
} finally {
await rm(directory, { recursive: true, force: true });
}
await expectNoUnmodeledGdbCommands(join(directory, "unmodeled"));
},
]);
}
@@ -29,6 +29,7 @@ import {
fakeGdbModeledReplies,
fakeGdbStartupPreamble,
} from "../providers/gdbTestHelpers.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const selectedBytes = Buffer.from("caller-selected executable bytes\n");
const selectedDigest = createHash("sha256").update(selectedBytes).digest("hex");
@@ -141,7 +142,7 @@ const fixture = async (
"stopProcess"
> = {},
) => {
const root = await mkdtemp(join(tmpdir(), "rea-gdb-selected-file-"));
const root = await createTestTempDirectory("rea-gdb-selected-file-");
const owner = createGdbFixtureOwner();
const managers: GdbSessionManager[] = [];
const connections: Array<() => void | Promise<void>> = [];
@@ -151,11 +152,7 @@ const fixture = async (
...connections,
() =>
owner.cleanup(managers, async () => {
try {
await expectNoUnmodeledGdbCommands(unmodeled);
} finally {
await rm(root, { recursive: true, force: true });
}
await expectNoUnmodeledGdbCommands(unmodeled);
}),
]),
);
@@ -13,12 +13,13 @@ import { createServer } from "../../../src/server/createServer.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { ghidraInstallationHost } from "./ghidraMcpHarness.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const REFUSAL =
"Processor or compiler specification overrides cannot replace the admitted raw-binary import.";
const openRawArm = async (languageId: string | undefined) => {
const directory = await mkdtemp(join(tmpdir(), "rea-profile-refusal-"));
const directory = await createTestTempDirectory("rea-profile-refusal-");
const path = join(directory, "image.bin");
await writeFile(path, Buffer.from([0, 0, 160, 225]));
const config = parseConfig({
@@ -67,7 +68,6 @@ const openRawArm = async (languageId: string | undefined) => {
} finally {
await Promise.allSettled([mcp.close(), server.close()]);
await session.close();
await rm(directory, { recursive: true, force: true });
}
};
@@ -28,6 +28,7 @@ import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarnes
import { createTestBinarySession } from "../../fixtures/binarySession.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const reference = (source: Evidence) => ({
kind: "retained-evidence" as const,
@@ -256,8 +257,7 @@ it("reports missing sources for a retained dossier with a large link set", async
evidenceLinks: links,
},
);
const directory = await mkdtemp(join(tmpdir(), "rea-large-links-"));
onTestFinished(() => rm(directory, { recursive: true, force: true }));
const directory = await createTestTempDirectory("rea-large-links-");
const path = join(directory, "bundle.json");
await writeFile(path, JSON.stringify(createEvidenceBundle([source])));
const imported = await client.callTool({
@@ -24,9 +24,10 @@ import { silentLogger } from "../../../src/logger.js";
import { createServer } from "../../../src/server/createServer.js";
import { ToolResultDelivery } from "../../../src/server/ToolResultDelivery.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const createTemporaryRoot = (): Promise<string> =>
mkdtemp(join(tmpdir(), "rea-mcp-process-cleanup-retry-"));
createTestTempDirectory("rea-mcp-process-cleanup-retry-");
const cleanupOptions = (
root: string,
@@ -166,9 +167,6 @@ it("projects the retained process root through close_binary and resolves its ret
async () => {
await closeSession(resources);
},
async () => {
await rm(root, { recursive: true, force: true });
},
]);
});
@@ -269,9 +267,6 @@ it.each(["returned", "thrown", "synchronous"] as const)(
async () => {
await closeSession(resources);
},
async () => {
await rm(root, { recursive: true, force: true });
},
]);
},
);
@@ -6,12 +6,13 @@ import { McpServer } from "@modelcontextprotocol/server";
import { expect, it, onTestFinished, vi } from "vitest";
import { createProviderEnvironmentMcpHarness } from "../../support/reverseDebuggerMcpTestHelpers.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const providerSource = `#!${process.execPath}\nprocess.stdout.write("selected provider\\n");\n`;
const inputSource = "selected input bytes\n";
const selectedProviderFiles = async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-provider-owner-"));
const directory = await createTestTempDirectory("rea-provider-owner-");
const provider = join(directory, "selected-rizin");
const input = join(directory, "fixture.bin");
await Promise.all([
@@ -10,6 +10,7 @@ import { REVERSE_ENGINEERING_TOOL_CONTRACTS } from "../../../src/contracts/rever
import { rizinCommandLimitations } from "../../../src/rizin/RizinCommand.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { createProviderEnvironmentMcpHarness } from "../../support/reverseDebuggerMcpTestHelpers.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const writeProvider = async (path: string, output: string): Promise<void> => {
await writeFile(
@@ -49,7 +50,7 @@ const executeRizinCommand = async (
};
it("uses the captured server environment to resolve reverse-engineering providers", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-provider-environment-"));
const directory = await createTestTempDirectory("rea-provider-environment-");
const provider = join(directory, "selected-rizin");
const artifact = join(directory, "fixture.bin");
await writeFile(artifact, "fixture");
@@ -67,7 +68,7 @@ it("uses the captured server environment to resolve reverse-engineering provider
});
it("prefers an explicit provider environment over the captured server environment", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-provider-override-"));
const directory = await createTestTempDirectory("rea-provider-override-");
const configured = join(directory, "captured-rizin");
const override = join(directory, "override-rizin");
const artifact = join(directory, "fixture.bin");
@@ -95,7 +96,7 @@ it("prefers an explicit provider environment over the captured server environmen
});
it("snapshots an explicit provider environment when the server is created", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-provider-snapshot-"));
const directory = await createTestTempDirectory("rea-provider-snapshot-");
const configured = join(directory, "captured-rizin");
const override = join(directory, "explicit-rizin");
const artifact = join(directory, "fixture.bin");
@@ -125,7 +126,7 @@ it("snapshots an explicit provider environment when the server is created", asyn
});
it("passes Rizin decoder and map inputs as flags before the artifact", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-rizin-load-mcp-"));
const directory = await createTestTempDirectory("rea-rizin-load-mcp-");
const provider = join(directory, "argv-rizin");
const artifact = join(directory, "flash.bin");
await writeFile(artifact, "flash");
@@ -9,6 +9,7 @@ import { createServer } from "../../../src/server/createServer.js";
import { createAnalysisExecution } from "../../../src/ports/AnalysisProvider.js";
import { ok } from "../../../src/domain/result.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const analysis = {
execute: async () =>
@@ -24,7 +25,7 @@ const writeRizin = async (directory: string, output: string): Promise<void> => {
};
it("uses the server-selected environment unless a provider environment overrides it", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-reverse-env-"));
const directory = await createTestTempDirectory("rea-reverse-env-");
const selectedPath = join(directory, "selected");
const overridePath = join(directory, "override");
const artifactPath = join(directory, "sample.bin");
@@ -35,54 +36,50 @@ it("uses the server-selected environment unless a provider environment overrides
writeFile(artifactPath, "fixture"),
]);
try {
for (const scenario of [
for (const scenario of [
{
environment: selectedPath,
expected: "selected environment",
},
{
environment: selectedPath,
provider: overridePath,
expected: "provider override",
},
]) {
const server = createServer(
{ kind: "fixed", analysis },
{
environment: selectedPath,
expected: "selected environment",
environment: { ...process.env, PATH: scenario.environment },
...(scenario.provider === undefined
? {}
: {
providerEnvironment: {
...process.env,
PATH: scenario.provider,
},
}),
},
{
environment: selectedPath,
provider: overridePath,
expected: "provider override",
},
]) {
const server = createServer(
{ kind: "fixed", analysis },
{
environment: { ...process.env, PATH: scenario.environment },
...(scenario.provider === undefined
? {}
: {
providerEnvironment: {
...process.env,
PATH: scenario.provider,
},
}),
},
);
const client = new Client(
{ name: "reverse-env-test", version: "1" },
{ jsonSchemaValidator: createMcpSchemaValidation() },
);
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
try {
await server.connect(serverTransport);
await client.connect(clientTransport);
const result = await client.callTool({
name: "execute_rizin_command",
arguments: { path: artifactPath, command: "iI" },
});
expect(result.isError).not.toBe(true);
expect(result.structuredContent).toMatchObject({
raw_result: { stdout: `${scenario.expected}\n` },
});
} finally {
await Promise.all([client.close(), server.close()]);
}
);
const client = new Client(
{ name: "reverse-env-test", version: "1" },
{ jsonSchemaValidator: createMcpSchemaValidation() },
);
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
try {
await server.connect(serverTransport);
await client.connect(clientTransport);
const result = await client.callTool({
name: "execute_rizin_command",
arguments: { path: artifactPath, command: "iI" },
});
expect(result.isError).not.toBe(true);
expect(result.structuredContent).toMatchObject({
raw_result: { stdout: `${scenario.expected}\n` },
});
} finally {
await Promise.all([client.close(), server.close()]);
}
} finally {
await rm(directory, { recursive: true, force: true });
}
});
@@ -30,11 +30,12 @@ import {
waitForStartedFile,
} from "../../support/reverseDebuggerMcpTestHelpers.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it.skipIf(process.platform === "win32")(
"reports Rizin launch provenance and lossy frame decoding through MCP",
async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-rizin-provenance-"));
const directory = await createTestTempDirectory("rea-rizin-provenance-");
const provider = join(directory, "fake-rizin-provenance.mjs");
await writeFile(
provider,
@@ -113,7 +114,6 @@ process.stdin.on("data", (chunk) => {
() => server.close(),
async () => {
await manager.closeAll();
await rm(directory, { recursive: true, force: true });
},
]);
}
@@ -190,7 +190,7 @@ it("admits Rizin startup across a bound analysis session", async () => {
it.skipIf(process.platform === "win32")(
"propagates MCP cancellation into a running Rizin debugger command",
async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-rizin-mcp-cancel-"));
const directory = await createTestTempDirectory("rea-rizin-mcp-cancel-");
const provider = join(directory, "fake-rizin.mjs");
const commandPath = join(directory, "command-started");
await writeFile(
@@ -254,7 +254,6 @@ process.stdin.on("data", async (chunk) => {
() => server.close(),
async () => {
await manager.closeAll();
await rm(directory, { recursive: true, force: true });
},
]);
}
@@ -9,10 +9,10 @@ import { z } from "zod";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it("delivers typed tool failures without violating the advertised success schema over stdio", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-tool-error-schema-"));
onTestFinished(() => rm(root, { recursive: true, force: true }));
const root = await createTestTempDirectory("rea-tool-error-schema-");
const missing = join(root, "not-present.bin");
const { client, call } = await connectLocalToolsMcp();
const tools = (await client.listTools()).tools;
@@ -6,6 +6,7 @@ import { ModelArtifactProvider } from "../../../src/model/ModelArtifactProvider.
import { parseEvidence } from "../../../src/domain/evidence.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { ggufFixture, safetensorsFixture } from "../../fixtures/model/model.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const cancelledArrayFixture = (alignment?: number) => {
const seed = ggufFixture();
@@ -38,7 +39,7 @@ const cancelledArrayFixture = (alignment?: number) => {
it.each([undefined, 64])(
"retains completed GGUF facts when cancellation interrupts a later value (alignment=%s)",
async (alignment) => {
const root = await mkdtemp(join(tmpdir(), "rea-model-partial-cancel-"));
const root = await createTestTempDirectory("rea-model-partial-cancel-");
const path = join(root, "model.gguf");
const { fixture, count, arrayStart } = cancelledArrayFixture(alignment);
await writeFile(path, fixture.bytes);
@@ -126,13 +127,12 @@ it.each([undefined, 64])(
} finally {
readSpy.mockRestore();
await provider.close();
await rm(root, { recursive: true, force: true });
}
},
);
it("retains GGUF tensor declarations and layout limitations before later tensor bytes cancel", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-model-tensor-partial-"));
const root = await createTestTempDirectory("rea-model-tensor-partial-");
const path = join(root, "model.gguf");
const tensorCount = 4000;
const fixture = ggufFixture({
@@ -231,7 +231,6 @@ it("retains GGUF tensor declarations and layout limitations before later tensor
} finally {
readSpy.mockRestore();
await provider.close();
await rm(root, { recursive: true, force: true });
}
});
@@ -242,7 +241,7 @@ it.each([
])(
"retains parsed $format facts with alignment $alignment when full hashing is cancelled",
async ({ format, alignment }) => {
const root = await mkdtemp(join(tmpdir(), "rea-model-hash-cancel-"));
const root = await createTestTempDirectory("rea-model-hash-cancel-");
const path = join(root, `model.${format}`);
const fixture =
format === "safetensors"
@@ -347,7 +346,6 @@ it.each([
} finally {
readSpy.mockRestore();
await provider.close();
await rm(root, { recursive: true, force: true });
}
},
);
@@ -58,6 +58,7 @@ import { binaryLayoutFixture } from "../../fixtures/binaryDiagnostics/layout.js"
import { PwntoolsDecoder } from "../../../src/native/pwntools/PwntoolsDecoder.js";
import { PWNTOOLS_PROVIDER_IDENTITY } from "../../../src/native/pwntools/PwntoolsProviderIdentity.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const makeDecoder = () =>
new PwntoolsDecoder(
@@ -79,7 +80,7 @@ const makeDecoder = () =>
);
it("reports the read failure without stale incomplete-cleanup state when close retry succeeds", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-pwntools-close-retry-"));
const root = await createTestTempDirectory("rea-pwntools-close-retry-");
const path = join(root, "selected.bin");
await writeFile(path, "selected evidence");
closeState.fail = false;
@@ -113,12 +114,11 @@ it("reports the read failure without stale incomplete-cleanup state when close r
closeState.fail = false;
closeState.failOnce = false;
await decoder.close();
await rm(root, { recursive: true, force: true });
}
});
it("retains a persistent failed input descriptor and refuses the next acquisition", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-pwntools-held-close-"));
const root = await createTestTempDirectory("rea-pwntools-held-close-");
const path = join(root, "selected.bin");
await writeFile(path, "selected evidence");
closeState.fail = true;
@@ -151,12 +151,11 @@ it("retains a persistent failed input descriptor and refuses the next acquisitio
} catch {
// The test already asserts persistent cleanup failure before releasing it.
}
await rm(root, { recursive: true, force: true });
}
});
it("retains selected target identity when cancellation arrives after its completed read", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-pwntools-input-cancel-"));
const root = await createTestTempDirectory("rea-pwntools-input-cancel-");
const path = join(root, "selected.bin");
await writeFile(path, "selected evidence");
closeState.inputAbort = new AbortController();
@@ -179,14 +178,13 @@ it("retains selected target identity when cancellation arrives after its complet
} finally {
closeState.inputAbort = undefined;
await decoder.close();
await rm(root, { recursive: true, force: true });
}
});
// Simulated decoder writes a reply; the selected object is never executed.
it("retains admitted layout through reply close failure and cancellation, then resolves cleanup", async () => {
await prepareProcessOwnershipInspection();
const root = await mkdtemp(join(tmpdir(), "rea-pwntools-reply-close-"));
const root = await createTestTempDirectory("rea-pwntools-reply-close-");
const path = join(root, "selected.bin");
await writeFile(path, Buffer.alloc(128));
const runtime = await PrivateRuntimeRoot.create({
@@ -248,7 +246,6 @@ it("retains admitted layout through reply close failure and cancellation, then r
closeState.replyFail = false;
closeState.abort = undefined;
await provider.close();
await rm(root, { recursive: true, force: true });
}
});
@@ -266,7 +263,7 @@ it.each([
"admits base core facts before optional debugger enrichment: %s",
async (scenario) => {
await prepareProcessOwnershipInspection();
const root = await mkdtemp(join(tmpdir(), "rea-pwntools-core-reply-"));
const root = await createTestTempDirectory("rea-pwntools-core-reply-");
const path = join(root, "selected.core");
const value = recordedCrashFixture(path);
await writeFile(path, recordedCrashFixtureBytes(value));
@@ -402,7 +399,6 @@ it.each([
closeState.replyFail = false;
closeState.abort = undefined;
await provider.close();
await rm(root, { recursive: true, force: true });
}
},
);
@@ -13,13 +13,7 @@ import { join } from "node:path";
import { afterEach, expect, it } from "vitest";
import { copyScriptsWithImports } from "../../support/scriptImportClosure.js";
const roots: string[] = [];
afterEach(async () => {
await Promise.all(
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
);
});
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const runVerifier = async (
settings: {
@@ -30,8 +24,7 @@ const runVerifier = async (
pull?: "error" | "throw";
} = {},
) => {
const root = await mkdtemp(join(tmpdir(), "rea-adb-verifier-test-"));
roots.push(root);
const root = await createTestTempDirectory("rea-adb-verifier-test-");
await mkdir(join(root, "dist", "application", "adb"), { recursive: true });
await mkdir(join(root, "dist", "composition"), { recursive: true });
await copyScriptsWithImports(["scripts/verify-adb.mjs"], root);
@@ -8,9 +8,10 @@ import { createPackageVerifierCommands } from "../../../scripts/lib/verify-packa
import { OwnedMcpStdioTransport } from "../../../src/process/OwnedMcpStdioTransport.js";
import { resolveSwiftcCompileTimeoutMs } from "../../../src/process/DarwinProcessRunTokenReader.js";
import { processHasStopped } from "../../support/process/observePosixProcess.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it("retains the workspace until an owned protocol cleanup can be retried", async () => {
const path = await mkdtemp(join(tmpdir(), "rea-verifier-transport-"));
const path = await createTestTempDirectory("rea-verifier-transport-");
const process = Object.assign(new EventEmitter(), {
pid: 1,
stdout: new PassThrough(),
@@ -50,21 +51,17 @@ it("retains the workspace until an owned protocol cleanup can be retried", async
},
});
commands.adopt(transport, "protocol child");
try {
await transport.start();
// The group can still contain work after the leader's exit.
process.emit("exit", 0, null);
await expect(commands.close()).rejects.toMatchObject({
path,
cleanupOwner: commands,
});
await expect(access(path)).resolves.toBeUndefined();
refuse = false;
await commands.close();
await expect(access(path)).rejects.toMatchObject({ code: "ENOENT" });
} finally {
await rm(path, { recursive: true, force: true });
}
await transport.start();
// The group can still contain work after the leader's exit.
process.emit("exit", 0, null);
await expect(commands.close()).rejects.toMatchObject({
path,
cleanupOwner: commands,
});
await expect(access(path)).resolves.toBeUndefined();
refuse = false;
await commands.close();
await expect(access(path)).rejects.toMatchObject({ code: "ENOENT" });
});
it(
@@ -73,7 +70,7 @@ it(
const { writeFile, readFile } = await import("node:fs/promises");
const { createOwnedMcpStdioTransport } =
await import("../../../scripts/lib/owned-mcp-stdio.mjs");
const path = await mkdtemp(join(tmpdir(), "rea-verifier-real-transport-"));
const path = await createTestTempDirectory("rea-verifier-real-transport-");
const fixture = join(path, "child.cjs");
const marker = join(path, "pids.json");
await writeFile(
@@ -110,7 +107,6 @@ setInterval(()=>{},1000);`,
for (const pid of pids) expect(await processHasStopped(pid)).toBe(true);
} finally {
await transport.close();
await rm(path, { recursive: true, force: true });
}
},
Math.min(
@@ -3,6 +3,7 @@ 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],
@@ -12,77 +13,70 @@ it.each([
] as const)(
"retains the verifier root correctly after %s",
async (_name, failure, rootClosed) => {
const root = await mkdtemp(join(tmpdir(), "rea-bun-owner-test-"));
try {
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 });
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", "verify-bun-standalone.mjs"),
join(root, "scripts", "lib", helper),
await readFile(
new URL(
"../../../scripts/verify-bun-standalone.mjs",
import.meta.url,
),
new URL(`../../../scripts/lib/${helper}`, 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() {
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";
);
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,
);
} finally {
await rm(root, { recursive: true, force: true });
}
);
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,
);
},
);
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it.each(
(
@@ -21,14 +22,13 @@ it.each(
)(
"%s checks a %s setup-plan target before writing",
async (client, kind, allowed) => {
const state = await mkdtemp(join(tmpdir(), "rea-claude-plan-"));
try {
const commands = join(state, "commands.mjs");
const fixture = join(state, "fixture.mjs");
const hook = join(state, "hook.mjs");
await writeFile(
commands,
`import { writeFile } from 'node:fs/promises';
const state = await createTestTempDirectory("rea-claude-plan-");
const commands = join(state, "commands.mjs");
const fixture = join(state, "fixture.mjs");
const hook = join(state, "hook.mjs");
await writeFile(
commands,
`import { writeFile } from 'node:fs/promises';
import { isAbsolute, join, relative } from 'node:path';
export async function createVerifierCommands(){return {
async exec(command,args,options={}){
@@ -42,57 +42,51 @@ export async function createVerifierCommands(){return {
}
await writeFile(process.env.STATE+'/setup-advanced','yes'); throw Error('intentional stop before setup mutation');
}, async close(){} };}`,
);
await writeFile(
fixture,
`export async function createAnthropicModelFixture(){return {baseUrl:'http://127.0.0.1:1',async close(){}};} export const createOpenAiModelFixture=createAnthropicModelFixture;`,
);
await writeFile(
hook,
`import {registerHooks} from 'node:module';import{pathToFileURL}from'node:url';
);
await writeFile(
fixture,
`export async function createAnthropicModelFixture(){return {baseUrl:'http://127.0.0.1:1',async close(){}};} export const createOpenAiModelFixture=createAnthropicModelFixture;`,
);
await writeFile(
hook,
`import {registerHooks} from 'node:module';import{pathToFileURL}from'node:url';
registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-'+process.env.CLIENT+'-client.mjs')){let f;if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/anthropic-model-fixture.mjs'||specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});`,
);
const result = spawnSync(
process.execPath,
[
"--import",
hook,
fileURLToPath(
new URL(
`../../../scripts/verify-${client}-client.mjs`,
import.meta.url,
),
);
const result = spawnSync(
process.execPath,
[
"--import",
hook,
fileURLToPath(
new URL(
`../../../scripts/verify-${client}-client.mjs`,
import.meta.url,
),
],
{
encoding: "utf8",
cwd: state,
timeout: 10_000,
env: {
...process.env,
STATE: state,
KIND: kind,
CLIENT: client,
TMPDIR: state,
TMP: state,
TEMP: state,
},
),
],
{
encoding: "utf8",
cwd: state,
timeout: 10_000,
env: {
...process.env,
STATE: state,
KIND: kind,
CLIENT: client,
TMPDIR: state,
TMP: state,
TEMP: state,
},
);
expect(result.status).not.toBe(0);
const advanced = await readFile(
join(state, "setup-advanced"),
"utf8",
).then(
() => true,
() => false,
);
expect(advanced).toBe(allowed);
expect(result.stderr).toContain(
allowed ? "intentional stop before setup mutation" : "AssertionError",
);
} finally {
await rm(state, { recursive: true, force: true });
}
},
);
expect(result.status).not.toBe(0);
const advanced = await readFile(join(state, "setup-advanced"), "utf8").then(
() => true,
() => false,
);
expect(advanced).toBe(allowed);
expect(result.stderr).toContain(
allowed ? "intentional stop before setup mutation" : "AssertionError",
);
},
);
@@ -10,6 +10,7 @@ import { createDirectAnalysis } from "../../../src/composition/directAnalysis.js
import { probeProcessCaptureCapability } from "../../../src/process/capture/ProcessCaptureCapability.js";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { parseProcessCapture } from "../../../src/domain/process/processCaptureParsing.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
describe("the CLI takes its environment as an input", () => {
it("resolves from injected PATH and inherits injected env with scenario overrides", async ({
@@ -21,46 +22,42 @@ describe("the CLI takes its environment as an input", () => {
return;
}
const root = await mkdtemp(join(tmpdir(), "rea-cli-env-process-"));
const root = await createTestTempDirectory("rea-cli-env-process-");
const bin = join(root, "bin");
const executable = join(bin, "rea-injected-process-probe");
const scenarioPath = join(root, "scenario.json");
try {
await mkdir(bin);
await writeFile(
executable,
[
"#!/bin/sh",
'printf "%s|%s\\n" "$REA_CAPTURE_INJECTED_MARKER" "$REA_CAPTURE_SCENARIO_OVERRIDE"',
].join("\n"),
);
await chmod(executable, 0o755);
await writeFile(
scenarioPath,
JSON.stringify({
executable: "rea-injected-process-probe",
working_directory: root,
environment: { REA_CAPTURE_SCENARIO_OVERRIDE: "scenario-value" },
}),
);
await mkdir(bin);
await writeFile(
executable,
[
"#!/bin/sh",
'printf "%s|%s\\n" "$REA_CAPTURE_INJECTED_MARKER" "$REA_CAPTURE_SCENARIO_OVERRIDE"',
].join("\n"),
);
await chmod(executable, 0o755);
await writeFile(
scenarioPath,
JSON.stringify({
executable: "rea-injected-process-probe",
working_directory: root,
environment: { REA_CAPTURE_SCENARIO_OVERRIDE: "scenario-value" },
}),
);
const result = await captureProcessScenarioFile(scenarioPath, {
PATH: bin,
REA_CAPTURE_INJECTED_MARKER: "injected-value",
REA_CAPTURE_SCENARIO_OVERRIDE: "host-value",
});
if (isCliOperationFailure(result))
throw new Error(
`Process capture returned an error: ${JSON.stringify(result)}`,
);
const evidence = parseEvidence(result);
const capture = parseProcessCapture(evidence.normalized_result);
expect(capture.frames.map(({ data }) => data).join("")).toContain(
"injected-value|scenario-value",
const result = await captureProcessScenarioFile(scenarioPath, {
PATH: bin,
REA_CAPTURE_INJECTED_MARKER: "injected-value",
REA_CAPTURE_SCENARIO_OVERRIDE: "host-value",
});
if (isCliOperationFailure(result))
throw new Error(
`Process capture returned an error: ${JSON.stringify(result)}`,
);
} finally {
await rm(root, { recursive: true, force: true });
}
const evidence = parseEvidence(result);
const capture = parseProcessCapture(evidence.normalized_result);
expect(capture.frames.map(({ data }) => data).join("")).toContain(
"injected-value|scenario-value",
);
});
it("reports session status from a supplied environment", async () => {
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it.each(
(
@@ -30,14 +31,13 @@ it.each(
)(
"%s checks %s setup-plan targets before writing",
async (client, kind, allowed) => {
const state = await mkdtemp(join(tmpdir(), "rea-client-plan-"));
try {
const commands = join(state, "commands.mjs");
const fixture = join(state, "fixture.mjs");
const hook = join(state, "hook.mjs");
await writeFile(
commands,
`import {writeFile} from 'node:fs/promises'; import {join} from 'node:path';
const state = await createTestTempDirectory("rea-client-plan-");
const commands = join(state, "commands.mjs");
const fixture = join(state, "fixture.mjs");
const hook = join(state, "hook.mjs");
await writeFile(
commands,
`import {writeFile} from 'node:fs/promises'; import {join} from 'node:path';
export async function createVerifierCommands(){return {
async exec(command,args,options={}){
if(command==='git')return {stdout:'',stderr:''};
@@ -55,49 +55,40 @@ export async function createVerifierCommands(){return {
}
await writeFile(process.env.STATE+'/setup-advanced','yes'); throw Error('intentional stop before setup mutation');
}, async close(){} };}`,
);
await writeFile(
fixture,
`export async function createOpenAiModelFixture(){return {baseUrl:'http://127.0.0.1:1',async close(){}};}`,
);
await writeFile(
hook,
`import {registerHooks} from 'node:module';import{pathToFileURL}from'node:url';
);
await writeFile(
fixture,
`export async function createOpenAiModelFixture(){return {baseUrl:'http://127.0.0.1:1',async close(){}};}`,
);
await writeFile(
hook,
`import {registerHooks} from 'node:module';import{pathToFileURL}from'node:url';
registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-'+process.env.CLIENT+'-client.mjs')){let f;if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});`,
);
const script = fileURLToPath(
new URL(
`../../../scripts/verify-${client}-client.mjs`,
import.meta.url,
),
);
const result = spawnSync(process.execPath, ["--import", hook, script], {
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
CLIENT: client,
KIND: kind,
TMPDIR: state,
TMP: state,
TEMP: state,
},
});
expect(result.status).not.toBe(0);
const advanced = await readFile(
join(state, "setup-advanced"),
"utf8",
).then(
() => true,
() => false,
);
expect(advanced).toBe(allowed);
expect(result.stderr).toContain(
allowed ? "intentional stop before setup mutation" : "AssertionError",
);
} finally {
await rm(state, { recursive: true, force: true });
}
);
const script = fileURLToPath(
new URL(`../../../scripts/verify-${client}-client.mjs`, import.meta.url),
);
const result = spawnSync(process.execPath, ["--import", hook, script], {
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
CLIENT: client,
KIND: kind,
TMPDIR: state,
TMP: state,
TEMP: state,
},
});
expect(result.status).not.toBe(0);
const advanced = await readFile(join(state, "setup-advanced"), "utf8").then(
() => true,
() => false,
);
expect(advanced).toBe(allowed);
expect(result.stderr).toContain(
allowed ? "intentional stop before setup mutation" : "AssertionError",
);
},
);
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const posix = it.skipIf(process.platform === "win32");
posix.each([
@@ -16,15 +17,14 @@ posix.each([
] as const)(
"requires CommandCode skill proof for %s",
async (mode, allowed) => {
const state = await mkdtemp(join(tmpdir(), "rea-commandcode-skill-"));
try {
const account = join(state, "account");
await mkdir(account);
await writeFile(
join(account, ".rea-client-verification"),
"Disposable REA client verification account\n",
);
const commands = String.raw`
const state = await createTestTempDirectory("rea-commandcode-skill-");
const account = join(state, "account");
await mkdir(account);
await writeFile(
join(account, ".rea-client-verification"),
"Disposable REA client verification account\n",
);
const commands = String.raw`
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { TOOL_CONTRACTS } from REPLACE_CONTRACTS;
@@ -74,66 +74,61 @@ export async function createVerifierCommands() {
};
}
`.replace(
"REPLACE_CONTRACTS",
JSON.stringify(
new URL("../../../dist/contracts/toolContracts.js", import.meta.url)
.href,
),
);
await writeFile(join(state, "commands.mjs"), commands);
await writeFile(
join(state, "fixture.mjs"),
"export async function createOpenAiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
);
await writeFile(
join(state, "hook.mjs"),
"import{registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-commandcode-client.mjs')){let f;if(specifier==='node:os')f='os.mjs';if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
);
await writeFile(
join(state, "os.mjs"),
"export * from 'node:os';export function homedir(){return process.env.REA_VERIFY_COMMANDCODE_ACCOUNT_HOME;}\n",
);
const script = fileURLToPath(
new URL(
"../../../scripts/verify-commandcode-client.mjs",
import.meta.url,
),
);
const result = spawnSync(
process.execPath,
["--import", join(state, "hook.mjs"), script],
{
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
MODE: mode,
REA_VERIFY_COMMANDCODE_ACCOUNT_HOME: account,
},
"REPLACE_CONTRACTS",
JSON.stringify(
new URL("../../../dist/contracts/toolContracts.js", import.meta.url)
.href,
),
);
await writeFile(join(state, "commands.mjs"), commands);
await writeFile(
join(state, "fixture.mjs"),
"export async function createOpenAiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
);
await writeFile(
join(state, "hook.mjs"),
"import{registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-commandcode-client.mjs')){let f;if(specifier==='node:os')f='os.mjs';if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
);
await writeFile(
join(state, "os.mjs"),
"export * from 'node:os';export function homedir(){return process.env.REA_VERIFY_COMMANDCODE_ACCOUNT_HOME;}\n",
);
const script = fileURLToPath(
new URL(
"../../../scripts/verify-commandcode-client.mjs",
import.meta.url,
),
);
const result = spawnSync(
process.execPath,
["--import", join(state, "hook.mjs"), script],
{
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
MODE: mode,
REA_VERIFY_COMMANDCODE_ACCOUNT_HOME: account,
},
);
expect(result.status).not.toBe(0);
const observed = await readFile(
join(state, "observed.json"),
"utf8",
).then(JSON.parse, () => null);
expect(observed !== null).toBe(allowed);
if (allowed)
expect(observed.second.tool_calls[0].function.name).toBe(
"search_tools",
);
expect(result.stderr).toContain(
allowed
? "intentional stop before client output"
: mode === "empty"
? "Installed skill must have authored frontmatter"
: mode === "empty body"
? "Installed skill body must not be empty"
: "The model must receive the complete activated skill body",
);
} finally {
await rm(state, { recursive: true, force: true });
}
},
);
expect(result.status).not.toBe(0);
const observed = await readFile(join(state, "observed.json"), "utf8").then(
JSON.parse,
() => null,
);
expect(observed !== null).toBe(allowed);
if (allowed)
expect(observed.second.tool_calls[0].function.name).toBe("search_tools");
expect(result.stderr).toContain(
allowed
? "intentional stop before client output"
: mode === "empty"
? "Installed skill must have authored frontmatter"
: mode === "empty body"
? "Installed skill body must not be empty"
: "The model must receive the complete activated skill body",
);
},
);
@@ -850,8 +850,8 @@ it.skipIf(!onDarwin)(
it.skipIf(process.platform === "win32")(
"rethrows compile cancellation, removes its temporary root, and permits retry",
async () => {
const directory = await mkdtemp(
join(tmpdir(), "rea-process-token-abort-test-"),
const directory = await createTestTempDirectory(
"rea-process-token-abort-test-",
);
const fakeCompiler = await writeBlockingCompiler(directory);
const reader = createDarwinProcessRunTokenReader({
@@ -894,7 +894,6 @@ it.skipIf(process.platform === "win32")(
if (!controller.signal.aborted) controller.abort();
await compilation;
await reader.close();
await rm(directory, { recursive: true, force: true });
}
},
);
@@ -994,8 +993,8 @@ it.skipIf(process.platform === "win32")(
it.skipIf(process.platform === "win32").each(["first", "second"] as const)(
"keeps shared compilation alive when the %s waiter cancels",
async (cancelledWaiter) => {
const directory = await mkdtemp(
join(tmpdir(), "rea-process-token-shared-compile-test-"),
const directory = await createTestTempDirectory(
"rea-process-token-shared-compile-test-",
);
const fakeCompiler = await writeBlockingCompiler(directory);
const reader = createDarwinProcessRunTokenReader({
@@ -1048,7 +1047,6 @@ it.skipIf(process.platform === "win32").each(["first", "second"] as const)(
if (!secondController.signal.aborted) secondController.abort();
await Promise.allSettled([firstWaiter, secondWaiterPromise]);
await reader.close();
await rm(directory, { recursive: true, force: true });
}
},
);
@@ -1058,8 +1056,8 @@ it
.each(["reader-close", "exact-root"] as const)(
"retains a failed compilation cleanup for a later %s retry",
async (retry) => {
const directory = await mkdtemp(
join(tmpdir(), "rea-process-token-cleanup-retry-test-"),
const directory = await createTestTempDirectory(
"rea-process-token-cleanup-retry-test-",
);
const fakeCompiler = await writeBlockingCompiler(directory);
const reader = createDarwinProcessRunTokenReader({
@@ -1118,7 +1116,6 @@ it
if (compilationRoot !== undefined)
await chmod(compilationRoot, 0o700).catch(() => undefined);
await reader.close();
await rm(directory, { recursive: true, force: true });
}
},
);
@@ -1126,8 +1123,8 @@ it
it.skipIf(process.platform === "win32")(
"aborts and cleans an active compilation when the reader closes",
async () => {
const directory = await mkdtemp(
join(tmpdir(), "rea-process-token-close-compile-test-"),
const directory = await createTestTempDirectory(
"rea-process-token-close-compile-test-",
);
const fakeCompiler = await writeBlockingCompiler(directory);
const reader = createDarwinProcessRunTokenReader({
@@ -1160,7 +1157,6 @@ it.skipIf(process.platform === "win32")(
} finally {
await Promise.allSettled([preparation]);
await reader.close();
await rm(directory, { recursive: true, force: true });
}
},
);
@@ -1168,8 +1164,8 @@ it.skipIf(process.platform === "win32")(
it.skipIf(process.platform === "win32")(
"maps cancellation during native preparation before Electron launch",
async () => {
const directory = await mkdtemp(
join(tmpdir(), "rea-electron-token-abort-test-"),
const directory = await createTestTempDirectory(
"rea-electron-token-abort-test-",
);
const fakeCompiler = await writeBlockingCompiler(directory);
const reader = createDarwinProcessRunTokenReader({
@@ -1215,7 +1211,6 @@ it.skipIf(process.platform === "win32")(
prepareSpy.mockRestore();
launchSpy.mockRestore();
await reader.close();
await rm(directory, { recursive: true, force: true });
}
},
);
@@ -1223,8 +1218,8 @@ it.skipIf(process.platform === "win32")(
it.skipIf(process.platform === "win32").each(["baseline", "tokens"] as const)(
"preserves cancellation through system-host %s inspection",
async (kind) => {
const directory = await mkdtemp(
join(tmpdir(), "rea-process-baseline-abort-test-"),
const directory = await createTestTempDirectory(
"rea-process-baseline-abort-test-",
);
const fakeCompiler = await writeBlockingIdentityCompiler(directory);
const host = createSystemProcessOwnershipHost("darwin", process.env, {
@@ -1269,7 +1264,6 @@ it.skipIf(process.platform === "win32").each(["baseline", "tokens"] as const)(
await host.close?.();
if (helperRoot !== undefined)
await expect(access(helperRoot)).rejects.toThrow();
await rm(directory, { recursive: true, force: true });
}
},
);
@@ -1277,8 +1271,8 @@ it.skipIf(process.platform === "win32").each(["baseline", "tokens"] as const)(
it.skipIf(process.platform === "win32")(
"passes Electron cancellation into capture-local baseline inspection",
async () => {
const directory = await mkdtemp(
join(tmpdir(), "rea-electron-baseline-abort-test-"),
const directory = await createTestTempDirectory(
"rea-electron-baseline-abort-test-",
);
const fakeCompiler = await writeBlockingIdentityCompiler(directory);
const reader = createDarwinProcessRunTokenReader({
@@ -1343,7 +1337,6 @@ it.skipIf(process.platform === "win32")(
baselineSpy.mockRestore();
launchSpy.mockRestore();
await reader.close();
await rm(directory, { recursive: true, force: true });
}
},
);
@@ -1352,8 +1345,8 @@ it.skipIf(!onDarwin)(
"parses exact NUL-delimited token records and rejects truncated argv",
{ tags: ["long-running"] },
async () => {
const root = await mkdtemp(
join(tmpdir(), "rea-process-token-parser-test-"),
const root = await createTestTempDirectory(
"rea-process-token-parser-test-",
);
const executable = join(root, "parser-test");
const core = fileURLToPath(
@@ -1368,116 +1361,112 @@ it.skipIf(!onDarwin)(
import.meta.url,
),
);
try {
await execFileOutput(
"/usr/bin/xcrun",
["swiftc", core, fixture, "-o", executable],
{ timeout: 120_000, stopSignal: SWIFTC_INTERRUPT },
);
const { stdout } = await execFileAsync(executable, [], {
encoding: "utf8",
timeout: 10_000,
});
expect(JSON.parse(stdout)).toEqual({
argvDecoyFailsClosed: true,
readableEnvironmentWithoutToken: {
runId: null,
environmentEntryCount: 1,
},
restrictedReadableEnvironmentWithoutToken: {
state: "readable",
reason: null,
},
restrictedEmptyEnvironment: {
state: "unavailable",
reason: "restricted_process_environment_withheld",
},
platformEmptyEnvironment: {
await execFileOutput(
"/usr/bin/xcrun",
["swiftc", core, fixture, "-o", executable],
{ timeout: 120_000, stopSignal: SWIFTC_INTERRUPT },
);
const { stdout } = await execFileAsync(executable, [], {
encoding: "utf8",
timeout: 10_000,
});
expect(JSON.parse(stdout)).toEqual({
argvDecoyFailsClosed: true,
readableEnvironmentWithoutToken: {
runId: null,
environmentEntryCount: 1,
},
restrictedReadableEnvironmentWithoutToken: {
state: "readable",
reason: null,
},
restrictedEmptyEnvironment: {
state: "unavailable",
reason: "restricted_process_environment_withheld",
},
platformEmptyEnvironment: {
state: "unavailable",
reason: "platform_binary_environment_withheld",
},
restrictedUnavailableEnvironment: {
state: "unavailable",
reason: "restricted_process_environment_withheld",
},
restrictedAmbiguousEnvironment: {
state: "unavailable",
reason: "restricted_process_environment_withheld",
},
ordinaryAmbiguousEnvironment: {
state: "unavailable",
reason: "ambiguous_environment_boundary",
},
ordinaryUnavailableEnvironment: {
state: "unavailable",
reason: "environment_unavailable",
},
alternatePaddingRead: true,
appleVectorTokenFailsClosed: true,
clearedAppleVectorTokenFailsClosed: true,
callerPfzBeforeTokenRead: true,
emptyLaterArgumentRead: true,
emptyArgv0Read: true,
emptyEnvironmentRecordsBeforeTokenFailClosed: true,
duplicateTokenFailsClosed: true,
invalidTokenEncodingFailsClosed: true,
finalAssignmentArgumentRead: true,
missingAppleBoundaryFailsClosed: true,
malformedBuffersRejected: true,
invalidPointerSizeFailsClosed: true,
incompleteRestrictedArguments: [
"malformed_procargs_path_padding",
"malformed_procargs_arguments",
"apple_vector_unavailable",
].map((reason) => [
{
state: "unavailable",
reason: "platform_binary_environment_withheld",
},
restrictedUnavailableEnvironment: {
{
state: "unavailable",
reason: "restricted_process_environment_withheld",
},
restrictedAmbiguousEnvironment: {
{ state: "unavailable", reason },
]),
signedReadableTokens: [true, true],
signedInvalidTokens: [
"duplicate_run_token",
"invalid_run_token_encoding",
].map((reason) => [
{ state: "unavailable", reason },
{ state: "unavailable", reason },
]),
malformedStages: [
{ state: "unavailable", reason: "malformed_procargs_header" },
{ state: "unavailable", reason: "malformed_procargs_argument_count" },
{
state: "unavailable",
reason: "restricted_process_environment_withheld",
reason: "malformed_procargs_executable_path",
},
ordinaryAmbiguousEnvironment: {
{ state: "unavailable", reason: "malformed_procargs_pointer_size" },
{ state: "unavailable", reason: "malformed_procargs_path_padding" },
{ state: "unavailable", reason: "malformed_procargs_arguments" },
{ state: "unavailable", reason: "malformed_procargs_terminator" },
{
state: "unavailable",
reason: "ambiguous_environment_boundary",
reason: "malformed_procargs_trailing_entries",
},
ordinaryUnavailableEnvironment: {
state: "unavailable",
reason: "environment_unavailable",
},
alternatePaddingRead: true,
appleVectorTokenFailsClosed: true,
clearedAppleVectorTokenFailsClosed: true,
callerPfzBeforeTokenRead: true,
emptyLaterArgumentRead: true,
emptyArgv0Read: true,
emptyEnvironmentRecordsBeforeTokenFailClosed: true,
duplicateTokenFailsClosed: true,
invalidTokenEncodingFailsClosed: true,
finalAssignmentArgumentRead: true,
missingAppleBoundaryFailsClosed: true,
malformedBuffersRejected: true,
invalidPointerSizeFailsClosed: true,
incompleteRestrictedArguments: [
"malformed_procargs_path_padding",
"malformed_procargs_arguments",
"apple_vector_unavailable",
].map((reason) => [
{
state: "unavailable",
reason: "platform_binary_environment_withheld",
},
{
state: "unavailable",
reason: "restricted_process_environment_withheld",
},
{ state: "unavailable", reason },
]),
signedReadableTokens: [true, true],
signedInvalidTokens: [
"duplicate_run_token",
"invalid_run_token_encoding",
].map((reason) => [
{ state: "unavailable", reason },
{ state: "unavailable", reason },
]),
malformedStages: [
{ state: "unavailable", reason: "malformed_procargs_header" },
{ state: "unavailable", reason: "malformed_procargs_argument_count" },
{
state: "unavailable",
reason: "malformed_procargs_executable_path",
},
{ state: "unavailable", reason: "malformed_procargs_pointer_size" },
{ state: "unavailable", reason: "malformed_procargs_path_padding" },
{ state: "unavailable", reason: "malformed_procargs_arguments" },
{ state: "unavailable", reason: "malformed_procargs_terminator" },
{
state: "unavailable",
reason: "malformed_procargs_trailing_entries",
},
],
malformedObservation: {
state: "unavailable",
reason: "malformed_procargs",
},
nonAsciiPathRead: true,
realTokenRead: true,
reservedArgumentWithRealTokenFailsClosed: true,
titleOverwriteFailsClosed: true,
truncatedArgvFailsClosed: true,
zeroArgumentsRead: true,
});
} finally {
await rm(root, { recursive: true, force: true });
}
],
malformedObservation: {
state: "unavailable",
reason: "malformed_procargs",
},
nonAsciiPathRead: true,
realTokenRead: true,
reservedArgumentWithRealTokenFailsClosed: true,
titleOverwriteFailsClosed: true,
truncatedArgvFailsClosed: true,
zeroArgumentsRead: true,
});
},
);
@@ -1485,8 +1474,8 @@ it.skipIf(!onDarwin)(
"preserves process-table failures and confirms run-token identity",
{ tags: ["long-running"] },
async () => {
const root = await mkdtemp(
join(tmpdir(), "rea-process-snapshot-retry-test-"),
const root = await createTestTempDirectory(
"rea-process-snapshot-retry-test-",
);
const executable = join(root, "snapshot-probe");
const core = fileURLToPath(
@@ -1501,48 +1490,44 @@ it.skipIf(!onDarwin)(
import.meta.url,
),
);
try {
await execFileOutput(
"/usr/bin/xcrun",
["swiftc", core, fixture, "-o", executable],
{ timeout: 120_000, stopSignal: SWIFTC_INTERRUPT },
);
const { stdout } = await execFileAsync(executable, [], {
encoding: "utf8",
env: { ...process.env, REA_PROCESS_RUN_ID: "rea-snapshot-probe" },
timeout: 10_000,
});
expect(JSON.parse(stdout)).toEqual({
preservedOtherErrno: true,
retriedAfterFreshSize: true,
openingRunTokenSnapshotReads: 1,
failedOpeningRunTokens: [42, 43].map((pid) => ({
pid,
await execFileOutput(
"/usr/bin/xcrun",
["swiftc", core, fixture, "-o", executable],
{ timeout: 120_000, stopSignal: SWIFTC_INTERRUPT },
);
const { stdout } = await execFileAsync(executable, [], {
encoding: "utf8",
env: { ...process.env, REA_PROCESS_RUN_ID: "rea-snapshot-probe" },
timeout: 10_000,
});
expect(JSON.parse(stdout)).toEqual({
preservedOtherErrno: true,
retriedAfterFreshSize: true,
openingRunTokenSnapshotReads: 1,
failedOpeningRunTokens: [42, 43].map((pid) => ({
pid,
state: "unavailable",
reason: "process_table_failed_13",
})),
absentRunTokens: [
{ pid: 42, state: "unavailable", reason: "process_not_in_snapshot" },
],
failedConfirmingRunTokens: [
{
state: "unavailable",
reason: "process_table_failed_13",
})),
absentRunTokens: [
{ pid: 42, state: "unavailable", reason: "process_not_in_snapshot" },
],
failedConfirmingRunTokens: [
{
state: "unavailable",
reason: "process_table_failed_5",
tokenPresent: false,
},
],
confirmedRunTokens: [{ state: "readable", matchesFixtureToken: true }],
successfulSnapshotMissingPidIsAbsent: true,
failedSnapshotMissingPidIsUnavailable: true,
invalidPidIsUnavailable: true,
zombieLifecycleIsSeparateFromIdentity: true,
effectiveUidComesFromNativeIdentity: true,
nativeRelationIsSeparateFromIdentity: true,
nativeNameIsSeparateFromIdentity: true,
});
} finally {
await rm(root, { recursive: true, force: true });
}
reason: "process_table_failed_5",
tokenPresent: false,
},
],
confirmedRunTokens: [{ state: "readable", matchesFixtureToken: true }],
successfulSnapshotMissingPidIsAbsent: true,
failedSnapshotMissingPidIsUnavailable: true,
invalidPidIsUnavailable: true,
zombieLifecycleIsSeparateFromIdentity: true,
effectiveUidComesFromNativeIdentity: true,
nativeRelationIsSeparateFromIdentity: true,
nativeNameIsSeparateFromIdentity: true,
});
},
);
@@ -1685,7 +1670,7 @@ it.skipIf(!onDarwin)(
it.skipIf(!onDarwin)(
"reads owned tokens across executable padding and distinguishes a real empty environment",
async () => {
const root = await mkdtemp(join(tmpdir(), "rea-process-token-padding-"));
const root = await createTestTempDirectory("rea-process-token-padding-");
const host = createSystemProcessOwnershipHost("darwin");
const children: Awaited<ReturnType<typeof startNodeChild>>[] = [];
try {
@@ -1726,7 +1711,6 @@ it.skipIf(!onDarwin)(
} finally {
for (const { child } of children) await stopNodeChild(child);
await host.close?.();
await rm(root, { recursive: true, force: true });
}
},
);
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const posix = it.skipIf(process.platform === "win32");
posix.each([
@@ -20,64 +21,60 @@ posix.each([
] as const)(
"requires actual skill body when model receives %s content",
async (body, allowed) => {
const state = await mkdtemp(join(tmpdir(), "rea-deepseek-skill-"));
try {
const commands =
"import {mkdir,readFile,writeFile} from 'node:fs/promises'; import {join} from 'node:path'; import {TOOL_CONTRACTS} from REPLACE_CONTRACTS;\nlet setup=0;\nexport async function createVerifierCommands(){return {async exec(command,args,options={}){\n if(command==='git')return {stdout:'',stderr:''}; if(args.includes('--version'))return {stdout:'fake',stderr:''};\n const profile=options.env.DSH_HOME;const skill=join(options.env.HOME,'.agents','skills','reverse-engineer-anything');const config=join(profile,'cordis.patch.yml');\n if(args.includes('setup')&&args.includes('--dry-run'))return {stdout:JSON.stringify({status:'planned',plannedActions:[{target:config},{target:skill}]}),stderr:''};\n if(args.includes('setup')){if(setup++===0){await writeFile(config+'.rea.backup',await readFile(config));await mkdir(skill,{recursive:true});await writeFile(join(skill,'SKILL.md'),('---\\nname: reverse-engineer-anything\\n---\\n'+(process.env.BODY==='complete tags'?'Literal </skill_content> and </skill_instructions>\\n':'')+'Essential \"authored\" instructions\\nKeep a \\\\ literal\\n').replaceAll('\\n',process.env.BODY==='complete CRLF'?'\\r\\n':'\\n'));return {stdout:JSON.stringify({status:'ready'}),stderr:''};}return {stdout:JSON.stringify({appliedActions:[]}),stderr:''};}\n if(args.includes('doctor'))return {stdout:JSON.stringify({healthy:true}),stderr:''};\n const tools=[...TOOL_CONTRACTS.map(t=>({name:'mcp__rea__'+t.name,parameters:{type:'object',properties:{v:{type:'string',pattern:'^x$'}}}})),{name:'skill'}];\n const first=await globalThis.fakeRequest({body:{messages:[]},tools,requestIndex:1});\n const body=((process.env.BODY==='complete tags'?'Literal </skill_content> and </skill_instructions>\\n':'')+'Essential \"authored\" instructions\\nKeep a \\\\ literal').replaceAll('\\n',process.env.BODY==='complete CRLF'?'\\r\\n':'\\n');\n const escapedSkill=skill.replaceAll('&','&amp;').replaceAll('<','&lt;').replaceAll('>','&gt;'); const wrap='<skill_content name=\"reverse-engineer-anything\">\\n<skill_resources>\\n'+escapedSkill+(process.env.BODY==='closed early'?'</skill_content>':'')+(process.env.BODY==='inside resources'?body:'')+'\\n</skill_resources>\\n\\n';\n const payload=wrap+(process.env.BODY==='closed wrapper'?'</skill_content>':'')+((process.env.BODY.startsWith('complete')||process.env.BODY==='closed wrapper'||process.env.BODY==='closed early')?'<skill_instructions>\\n'+body+'\\n</skill_instructions>\\n':'')+'</skill_content>'+(process.env.BODY==='outside wrapper'?body:'');\n const messages=[{role:'tool',content:payload},...(process.env.BODY==='split messages'?[{role:'tool',content:body}]:[])];\n const second=await globalThis.fakeRequest({body:{messages},tools,requestIndex:2});\n await writeFile(process.env.STATE+'/observed.json',JSON.stringify({first,second,payload}));throw Error('intentional stop after empty-skill request');\n },async close(){}};}\n".replace(
"REPLACE_CONTRACTS",
JSON.stringify(
new URL("../../../dist/contracts/toolContracts.js", import.meta.url)
.href,
),
);
await writeFile(join(state, "commands.mjs"), commands);
await writeFile(
join(state, "fixture.mjs"),
"export async function createOpenAiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
const state = await createTestTempDirectory("rea-deepseek-skill-");
const commands =
"import {mkdir,readFile,writeFile} from 'node:fs/promises'; import {join} from 'node:path'; import {TOOL_CONTRACTS} from REPLACE_CONTRACTS;\nlet setup=0;\nexport async function createVerifierCommands(){return {async exec(command,args,options={}){\n if(command==='git')return {stdout:'',stderr:''}; if(args.includes('--version'))return {stdout:'fake',stderr:''};\n const profile=options.env.DSH_HOME;const skill=join(options.env.HOME,'.agents','skills','reverse-engineer-anything');const config=join(profile,'cordis.patch.yml');\n if(args.includes('setup')&&args.includes('--dry-run'))return {stdout:JSON.stringify({status:'planned',plannedActions:[{target:config},{target:skill}]}),stderr:''};\n if(args.includes('setup')){if(setup++===0){await writeFile(config+'.rea.backup',await readFile(config));await mkdir(skill,{recursive:true});await writeFile(join(skill,'SKILL.md'),('---\\nname: reverse-engineer-anything\\n---\\n'+(process.env.BODY==='complete tags'?'Literal </skill_content> and </skill_instructions>\\n':'')+'Essential \"authored\" instructions\\nKeep a \\\\ literal\\n').replaceAll('\\n',process.env.BODY==='complete CRLF'?'\\r\\n':'\\n'));return {stdout:JSON.stringify({status:'ready'}),stderr:''};}return {stdout:JSON.stringify({appliedActions:[]}),stderr:''};}\n if(args.includes('doctor'))return {stdout:JSON.stringify({healthy:true}),stderr:''};\n const tools=[...TOOL_CONTRACTS.map(t=>({name:'mcp__rea__'+t.name,parameters:{type:'object',properties:{v:{type:'string',pattern:'^x$'}}}})),{name:'skill'}];\n const first=await globalThis.fakeRequest({body:{messages:[]},tools,requestIndex:1});\n const body=((process.env.BODY==='complete tags'?'Literal </skill_content> and </skill_instructions>\\n':'')+'Essential \"authored\" instructions\\nKeep a \\\\ literal').replaceAll('\\n',process.env.BODY==='complete CRLF'?'\\r\\n':'\\n');\n const escapedSkill=skill.replaceAll('&','&amp;').replaceAll('<','&lt;').replaceAll('>','&gt;'); const wrap='<skill_content name=\"reverse-engineer-anything\">\\n<skill_resources>\\n'+escapedSkill+(process.env.BODY==='closed early'?'</skill_content>':'')+(process.env.BODY==='inside resources'?body:'')+'\\n</skill_resources>\\n\\n';\n const payload=wrap+(process.env.BODY==='closed wrapper'?'</skill_content>':'')+((process.env.BODY.startsWith('complete')||process.env.BODY==='closed wrapper'||process.env.BODY==='closed early')?'<skill_instructions>\\n'+body+'\\n</skill_instructions>\\n':'')+'</skill_content>'+(process.env.BODY==='outside wrapper'?body:'');\n const messages=[{role:'tool',content:payload},...(process.env.BODY==='split messages'?[{role:'tool',content:body}]:[])];\n const second=await globalThis.fakeRequest({body:{messages},tools,requestIndex:2});\n await writeFile(process.env.STATE+'/observed.json',JSON.stringify({first,second,payload}));throw Error('intentional stop after empty-skill request');\n },async close(){}};}\n".replace(
"REPLACE_CONTRACTS",
JSON.stringify(
new URL("../../../dist/contracts/toolContracts.js", import.meta.url)
.href,
),
);
await writeFile(
join(state, "hook.mjs"),
"import{registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-deepseek-client.mjs')){let f;if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
);
const script = fileURLToPath(
new URL("../../../scripts/verify-deepseek-client.mjs", import.meta.url),
);
const temporary =
body === "complete escaped" ? join(state, "dir &") : state;
if (temporary !== state) await mkdir(temporary);
const result = spawnSync(
process.execPath,
["--import", join(state, "hook.mjs"), script],
{
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
BODY: body,
TMPDIR: temporary,
TMP: temporary,
TEMP: temporary,
},
await writeFile(join(state, "commands.mjs"), commands);
await writeFile(
join(state, "fixture.mjs"),
"export async function createOpenAiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
);
await writeFile(
join(state, "hook.mjs"),
"import{registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-deepseek-client.mjs')){let f;if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
);
const script = fileURLToPath(
new URL("../../../scripts/verify-deepseek-client.mjs", import.meta.url),
);
const temporary =
body === "complete escaped" ? join(state, "dir &") : state;
if (temporary !== state) await mkdir(temporary);
const result = spawnSync(
process.execPath,
["--import", join(state, "hook.mjs"), script],
{
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
BODY: body,
TMPDIR: temporary,
TMP: temporary,
TEMP: temporary,
},
},
);
expect(result.status).not.toBe(0);
const observed = await readFile(join(state, "observed.json"), "utf8").then(
JSON.parse,
() => null,
);
expect(observed !== null).toBe(allowed);
if (allowed)
expect(observed.second.tool_calls[0].function.name).toBe(
"mcp__rea__analyze_javascript_application",
);
expect(result.status).not.toBe(0);
const observed = await readFile(
join(state, "observed.json"),
"utf8",
).then(JSON.parse, () => null);
expect(observed !== null).toBe(allowed);
if (allowed)
expect(observed.second.tool_calls[0].function.name).toBe(
"mcp__rea__analyze_javascript_application",
);
expect(result.stderr).toContain(
allowed
? "intentional stop after empty-skill request"
: "Harness must load the installed skill before analysis",
);
} finally {
await rm(state, { recursive: true, force: true });
}
expect(result.stderr).toContain(
allowed
? "intentional stop after empty-skill request"
: "Harness must load the installed skill before analysis",
);
},
);
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it.each([
["empty", false],
@@ -17,61 +18,57 @@ it.each([
] as const)(
"requires actual Gemini skill body in %s response",
async (body, allowed) => {
const state = await mkdtemp(join(tmpdir(), "rea-gemini-skill-"));
try {
const commands =
"import {mkdir,readFile,writeFile} from 'node:fs/promises';import {join} from 'node:path';import {TOOL_CONTRACTS} from REPLACE_CONTRACTS;\nlet setup=0;export async function createVerifierCommands(){return {async exec(command,args,options={}){\nif(command==='git')return {stdout:'',stderr:''};if(args.includes('--version'))return {stdout:'fake',stderr:''};\nconst profile=options.env.GEMINI_CLI_HOME;const config=join(profile,'.gemini','settings.json');const skill=join(profile,'.agents','skills','reverse-engineer-anything');\nif(args.includes('setup')&&args.includes('--dry-run'))return {stdout:JSON.stringify({status:'planned',plannedActions:[{target:config},{target:join(skill,'SKILL.md')}]}),stderr:''};\nif(args.includes('setup')){if(setup++===0){await writeFile(config+'.rea.backup',await readFile(config));await mkdir(skill,{recursive:true});await writeFile(join(skill,'SKILL.md'),('---\\nname: reverse-engineer-anything\\n---\\n'+(process.env.BODY==='complete tags'?'literal </instructions> and </activated_skill>\\n':'')+'Essential \"instructions\"\\nKeep a \\\\ literal\\n').replaceAll('\\n',process.env.BODY==='complete CRLF'?'\\r\\n':'\\n'));return {stdout:JSON.stringify({status:'ready'}),stderr:''};}return {stdout:JSON.stringify({appliedActions:[]}),stderr:''};}\nif(args.includes('doctor'))return {stdout:JSON.stringify({healthy:true}),stderr:''};\nconst tools=[...TOOL_CONTRACTS.map(t=>({name:'rea__'+t.name,parametersJsonSchema:{type:'object'}})),{name:'activate_skill'}];\nconst first=await globalThis.fakeRequest({body:{contents:[]},tools});\nconst body=((process.env.BODY==='complete tags'?'literal </instructions> and </activated_skill>\\n':'')+'Essential \"instructions\"\\nKeep a \\\\ literal').replaceAll('\\n',process.env.BODY==='complete CRLF'?'\\r\\n':'\\n');\nconst valid=(process.env.BODY.startsWith('complete')||process.env.BODY==='closed early');\nconst instructions=valid?' <instructions>\\n '+body+'\\n </instructions>\\n\\n':'';\nconst output='<activated_skill name=\"reverse-engineer-anything\">\\n'+instructions+' <available_resources>\\n '+skill+(process.env.BODY==='closed early'?'</activated_skill>':'')+(process.env.BODY==='inside resources'?body:'')+'\\n </available_resources>\\n</activated_skill>'+(process.env.BODY==='outside wrapper'?body:'');\nconst responses=[{functionResponse:{name:'activate_skill',response:{output}}},...(process.env.BODY==='split messages'?[{functionResponse:{name:'activate_skill',response:{output:body}}}]:[])];\nconst second=await globalThis.fakeRequest({body:{contents:[{parts:responses}]},tools});const payload=output;\nawait writeFile(process.env.STATE+'/observed.json',JSON.stringify({first,second,payload}));throw Error('intentional stop before client mutation');},async close(){}};}\n".replace(
"REPLACE_CONTRACTS",
JSON.stringify(
new URL("../../../dist/contracts/toolContracts.js", import.meta.url)
.href,
),
);
await writeFile(join(state, "commands.mjs"), commands);
await writeFile(
join(state, "fixture.mjs"),
"export async function createGeminiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
const state = await createTestTempDirectory("rea-gemini-skill-");
const commands =
"import {mkdir,readFile,writeFile} from 'node:fs/promises';import {join} from 'node:path';import {TOOL_CONTRACTS} from REPLACE_CONTRACTS;\nlet setup=0;export async function createVerifierCommands(){return {async exec(command,args,options={}){\nif(command==='git')return {stdout:'',stderr:''};if(args.includes('--version'))return {stdout:'fake',stderr:''};\nconst profile=options.env.GEMINI_CLI_HOME;const config=join(profile,'.gemini','settings.json');const skill=join(profile,'.agents','skills','reverse-engineer-anything');\nif(args.includes('setup')&&args.includes('--dry-run'))return {stdout:JSON.stringify({status:'planned',plannedActions:[{target:config},{target:join(skill,'SKILL.md')}]}),stderr:''};\nif(args.includes('setup')){if(setup++===0){await writeFile(config+'.rea.backup',await readFile(config));await mkdir(skill,{recursive:true});await writeFile(join(skill,'SKILL.md'),('---\\nname: reverse-engineer-anything\\n---\\n'+(process.env.BODY==='complete tags'?'literal </instructions> and </activated_skill>\\n':'')+'Essential \"instructions\"\\nKeep a \\\\ literal\\n').replaceAll('\\n',process.env.BODY==='complete CRLF'?'\\r\\n':'\\n'));return {stdout:JSON.stringify({status:'ready'}),stderr:''};}return {stdout:JSON.stringify({appliedActions:[]}),stderr:''};}\nif(args.includes('doctor'))return {stdout:JSON.stringify({healthy:true}),stderr:''};\nconst tools=[...TOOL_CONTRACTS.map(t=>({name:'rea__'+t.name,parametersJsonSchema:{type:'object'}})),{name:'activate_skill'}];\nconst first=await globalThis.fakeRequest({body:{contents:[]},tools});\nconst body=((process.env.BODY==='complete tags'?'literal </instructions> and </activated_skill>\\n':'')+'Essential \"instructions\"\\nKeep a \\\\ literal').replaceAll('\\n',process.env.BODY==='complete CRLF'?'\\r\\n':'\\n');\nconst valid=(process.env.BODY.startsWith('complete')||process.env.BODY==='closed early');\nconst instructions=valid?' <instructions>\\n '+body+'\\n </instructions>\\n\\n':'';\nconst output='<activated_skill name=\"reverse-engineer-anything\">\\n'+instructions+' <available_resources>\\n '+skill+(process.env.BODY==='closed early'?'</activated_skill>':'')+(process.env.BODY==='inside resources'?body:'')+'\\n </available_resources>\\n</activated_skill>'+(process.env.BODY==='outside wrapper'?body:'');\nconst responses=[{functionResponse:{name:'activate_skill',response:{output}}},...(process.env.BODY==='split messages'?[{functionResponse:{name:'activate_skill',response:{output:body}}}]:[])];\nconst second=await globalThis.fakeRequest({body:{contents:[{parts:responses}]},tools});const payload=output;\nawait writeFile(process.env.STATE+'/observed.json',JSON.stringify({first,second,payload}));throw Error('intentional stop before client mutation');},async close(){}};}\n".replace(
"REPLACE_CONTRACTS",
JSON.stringify(
new URL("../../../dist/contracts/toolContracts.js", import.meta.url)
.href,
),
);
await writeFile(
join(state, "hook.mjs"),
"import{registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-gemini-client.mjs')){let f;if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/gemini-model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
);
const script = fileURLToPath(
new URL("../../../scripts/verify-gemini-client.mjs", import.meta.url),
);
const result = spawnSync(
process.execPath,
["--import", join(state, "hook.mjs"), script],
{
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
BODY: body,
TMPDIR: state,
TMP: state,
TEMP: state,
},
await writeFile(join(state, "commands.mjs"), commands);
await writeFile(
join(state, "fixture.mjs"),
"export async function createGeminiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
);
await writeFile(
join(state, "hook.mjs"),
"import{registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-gemini-client.mjs')){let f;if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/gemini-model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
);
const script = fileURLToPath(
new URL("../../../scripts/verify-gemini-client.mjs", import.meta.url),
);
const result = spawnSync(
process.execPath,
["--import", join(state, "hook.mjs"), script],
{
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
BODY: body,
TMPDIR: state,
TMP: state,
TEMP: state,
},
},
);
expect(result.status).not.toBe(0);
const observed = await readFile(join(state, "observed.json"), "utf8").then(
JSON.parse,
() => null,
);
expect(observed !== null).toBe(allowed);
if (allowed)
expect(observed.second[0].functionCall.name).toBe(
"rea__analyze_javascript_application",
);
expect(result.status).not.toBe(0);
const observed = await readFile(
join(state, "observed.json"),
"utf8",
).then(JSON.parse, () => null);
expect(observed !== null).toBe(allowed);
if (allowed)
expect(observed.second[0].functionCall.name).toBe(
"rea__analyze_javascript_application",
);
expect(result.stderr).toContain(
allowed
? "intentional stop before client mutation"
: "Gemini must load the installed personal REA skill",
);
} finally {
await rm(state, { recursive: true, force: true });
}
expect(result.stderr).toContain(
allowed
? "intentional stop before client mutation"
: "Gemini must load the installed personal REA skill",
);
},
);
@@ -5,6 +5,7 @@ import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const execute = promisify(execFile);
@@ -20,15 +21,14 @@ it.each([
] as const)(
"requires overflow Evidence before reanalysis (%s, retained=%s)",
async (collection, retained) => {
const directory = await mkdtemp(
join(tmpdir(), "rea-il2cpp-retention-oracle-"),
const directory = await createTestTempDirectory(
"rea-il2cpp-retention-oracle-",
);
try {
// This recording qualifies the verifier's ordering oracle, not metadata
// decoding or transport conformance. A later analysis repairs retention.
await writeFile(
join(directory, "recording.mjs"),
`
// This recording qualifies the verifier's ordering oracle, not metadata
// decoding or transport conformance. A later analysis repairs retention.
await writeFile(
join(directory, "recording.mjs"),
`
import {promisify} from 'node:util';
const path=process.env.INPUT;
const identity={sha256:'a'.repeat(64),bytes:1};
@@ -56,61 +56,58 @@ export const requireMcpOutput=response=>{if(response.isError)throw Error('Unexpe
export const requireMcpToolError=response=>response.error;
export const hashVerifierFile=async()=>identity;
`,
);
await writeFile(
join(directory, "hook.mjs"),
`
);
await writeFile(
join(directory, "hook.mjs"),
`
import {registerHooks} from 'node:module';import {pathToFileURL} from 'node:url';
registerHooks({resolve(specifier,context,next){
if(context.parentURL?.endsWith('/scripts/verify-il2cpp-metadata.mjs')&&['node:child_process','@modelcontextprotocol/client','@modelcontextprotocol/client/stdio','../dist/contracts/toolContracts.js','./lib/mcp-verifier-results.mjs','./lib/verifier-file-resources.mjs'].includes(specifier))return {shortCircuit:true,url:pathToFileURL(process.env.RECORDING).href};
return next(specifier,context);
}});
`,
);
const result = execute(
process.execPath,
[
"--import",
join(directory, "hook.mjs"),
fileURLToPath(
new URL(
"../../../scripts/verify-il2cpp-metadata.mjs",
import.meta.url,
),
);
const result = execute(
process.execPath,
[
"--import",
join(directory, "hook.mjs"),
fileURLToPath(
new URL(
"../../../scripts/verify-il2cpp-metadata.mjs",
import.meta.url,
),
"--metadata",
join(directory, "metadata.dat"),
],
{
timeout: 10_000,
env: {
...process.env,
RECORDING: join(directory, "recording.mjs"),
INPUT: join(directory, "metadata.dat"),
RETAINED: String(retained),
COLLECTION: collection,
},
),
"--metadata",
join(directory, "metadata.dat"),
],
{
timeout: 10_000,
env: {
...process.env,
RECORDING: join(directory, "recording.mjs"),
INPUT: join(directory, "metadata.dat"),
RETAINED: String(retained),
COLLECTION: collection,
},
},
);
if (retained) {
const { stdout } = await result;
expect(stdout).toContain(
"All asserted IL2CPP metadata CLI/MCP checks passed",
);
if (retained) {
const { stdout } = await result;
expect(stdout).toContain(
"All asserted IL2CPP metadata CLI/MCP checks passed",
);
expect(
stdout.includes(
"empty queryable tables provide no nonempty row-content witness",
),
).toBe(collection === "empty");
} else {
await expect(result).rejects.toMatchObject({
stderr: expect.stringContaining(
"Failed delivery Evidence was not retained before reanalysis",
),
});
}
} finally {
await rm(directory, { recursive: true, force: true });
expect(
stdout.includes(
"empty queryable tables provide no nonempty row-content witness",
),
).toBe(collection === "empty");
} else {
await expect(result).rejects.toMatchObject({
stderr: expect.stringContaining(
"Failed delivery Evidence was not retained before reanalysis",
),
});
}
},
);
@@ -5,19 +5,19 @@ import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const execute = promisify(execFile);
it.each(["complete", "drop CLI", "drop MCP"])(
"requires each native UI adapter's own action (%s)",
async (mode) => {
const directory = await mkdtemp(join(tmpdir(), "rea-ui-action-oracle-"));
try {
// Authored AX recordings qualify adapter action assertions, not macOS
// permissions, native capture, Swift compilation or process ownership.
await writeFile(
join(directory, "recording.mjs"),
`
const directory = await createTestTempDirectory("rea-ui-action-oracle-");
// Authored AX recordings qualify adapter action assertions, not macOS
// permissions, native capture, Swift compilation or process ownership.
await writeFile(
join(directory, "recording.mjs"),
`
import {EventEmitter} from 'node:events';import {writeFile} from 'node:fs/promises';import {promisify} from 'node:util';
let count=0;
const nodes=()=>[{role:'AXButton',path:[0],title:count===0?'Increment REA fixture':'REA fixture incremented '+count}];
@@ -37,53 +37,50 @@ export const observeNativeUi=async(target,operation)=>{
export const withArtifactMcp=async(_path,run)=>run({});
export const artifactMcpResult=async(_client,name)=>{if(name==='observe_native_ui')return {initial:{nodes:nodes()}};if(process.env.MODE!=='drop MCP')count++;return captured();};
`,
);
await writeFile(
join(directory, "hook.mjs"),
`
);
await writeFile(
join(directory, "hook.mjs"),
`
import {registerHooks} from 'node:module';import {pathToFileURL} from 'node:url';
const darwinHost='data:text/javascript,'+encodeURIComponent('export const HOST_PLATFORM=Object.freeze({platform:"darwin",architecture:'+JSON.stringify(process.arch)+'});');process.kill=()=>{const open=globalThis.reaOpenChild;if(open?.exitCode===null){open.exitCode=0;queueMicrotask(()=>open.emit('exit',0,null));}return true;};
registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-native-ui.mjs')&&specifier==='../dist/platform/HostPlatform.js')return {shortCircuit:true,url:darwinHost};if(context.parentURL?.endsWith('/scripts/verify-native-ui.mjs')&&['node:child_process','../dist/application/BinaryTargetResolver.js','../dist/native/NativeUiObservation.js','./lib/artifact-e2e.mjs','../dist/process/ProcessOwnershipObservation.js'].includes(specifier))return {shortCircuit:true,url:pathToFileURL(process.env.RECORDING).href};return next(specifier,context);}});
`,
);
const result = execute(
process.execPath,
[
"--import",
join(directory, "hook.mjs"),
fileURLToPath(
new URL("../../../scripts/verify-native-ui.mjs", import.meta.url),
),
],
{
timeout: 10_000,
env: {
...process.env,
TMPDIR: directory,
TMP: directory,
TEMP: directory,
RECORDING: join(directory, "recording.mjs"),
MODE: mode,
},
);
const result = execute(
process.execPath,
[
"--import",
join(directory, "hook.mjs"),
fileURLToPath(
new URL("../../../scripts/verify-native-ui.mjs", import.meta.url),
),
],
{
timeout: 10_000,
env: {
...process.env,
TMPDIR: directory,
TMP: directory,
TEMP: directory,
RECORDING: join(directory, "recording.mjs"),
MODE: mode,
},
);
if (mode === "complete") {
expect(JSON.parse((await result).stdout)).toMatchObject({
ok: true,
positive_e2e: true,
scenario: "selected-AX-button-action-and-CLI-MCP-parity-observed",
});
} else {
await expect(result).rejects.toMatchObject({
stderr: expect.stringContaining(
mode === "drop CLI"
? "Native UI CLI did not preserve the selected scenario"
: "MCP did not observe the selected fixture's AX action",
),
});
}
} finally {
await rm(directory, { recursive: true, force: true });
},
);
if (mode === "complete") {
expect(JSON.parse((await result).stdout)).toMatchObject({
ok: true,
positive_e2e: true,
scenario: "selected-AX-button-action-and-CLI-MCP-parity-observed",
});
} else {
await expect(result).rejects.toMatchObject({
stderr: expect.stringContaining(
mode === "drop CLI"
? "Native UI CLI did not preserve the selected scenario"
: "MCP did not observe the selected fixture's AX action",
),
});
}
},
);
@@ -13,7 +13,10 @@ import {
import { parseProcessCapture } from "../../../src/domain/process/processCaptureParsing.js";
import { compareProcessCaptures } from "../../../src/domain/process/processComparison.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { itWithCaptureCapability } from "./processCaptureCapability.js";
import {
CAPTURE_SKIP_REASON,
itWithCaptureCapability,
} from "./processCaptureCapability.js";
const processFixture = fileURLToPath(
new URL("../../fixtures/processIdentity.mjs", import.meta.url),
@@ -25,8 +28,8 @@ const identitySchema = z.object({
session_id: z.number().int().positive(),
});
const itWithLinuxCaptureCapability =
process.platform === "linux" ? itWithCaptureCapability : it.skip;
const linuxCaptureSkip =
process.platform !== "linux" || CAPTURE_SKIP_REASON !== false;
itWithCaptureCapability(
"captures a POSIX PATH executable with a literal backslash in its basename",
@@ -180,8 +183,10 @@ itWithCaptureCapability.each([
20_000,
);
itWithLinuxCaptureCapability.each([false, true])(
"honors pids=%s in owned Linux capture samples and committed Evidence",
it.skipIf(linuxCaptureSkip).each([false, true])(
linuxCaptureSkip && CAPTURE_SKIP_REASON !== false
? `honors pids=%s in owned Linux capture samples and committed Evidence — ${CAPTURE_SKIP_REASON}`
: "honors pids=%s in owned Linux capture samples and committed Evidence",
async (pids) => {
const root = await createTestTempDirectory("rea-process-identifiers-");
const identityPath = join(root, "identity.json");
@@ -13,6 +13,7 @@ import {
type ProcessCaptureCleanupHost,
type ProcessCaptureResourceCleanupOptions,
} from "../../../src/process/capture/ProcessCaptureLifecycle.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const cleanupOptions = (
temporaryRoot: string,
@@ -34,7 +35,7 @@ const cleanupOptions = (
};
const createRoot = (): Promise<string> =>
mkdtemp(join(tmpdir(), "rea-process-cleanup-retry-"));
createTestTempDirectory("rea-process-cleanup-retry-");
const expectCaptureError = (operation: () => unknown): ProcessCaptureError => {
try {
@@ -101,7 +102,6 @@ it("resolves the origin and finalization copy after the exact root retry", async
} finally {
denyRemoval = false;
await scope.close();
await rm(root, { recursive: true, force: true });
}
});
@@ -183,9 +183,6 @@ it("keeps mixed root errors and retry aggregates bound to only unresolved roots"
} finally {
denied.clear();
await scope.close();
await Promise.all(
roots.map((root) => rm(root, { recursive: true, force: true })),
);
}
});
@@ -215,7 +212,6 @@ it("joins an already-started release when shutdown begins", async () => {
resourceRelease.release();
await Promise.allSettled([releasing, ...(closing ? [closing] : [])]);
await scope.close();
await rm(root, { recursive: true, force: true });
}
await releasing;
await closing;
@@ -256,7 +252,6 @@ it("binds a historical failed report after its owner already retried", async ()
} finally {
denyRemoval = false;
await scope.close();
await rm(root, { recursive: true, force: true });
}
});
@@ -308,7 +303,6 @@ it("blocks scope admission on owner-bound retry failure and resumes after releas
} finally {
denyRemoval = false;
await scope.close();
await rm(root, { recursive: true, force: true });
}
});
@@ -339,6 +333,5 @@ it("keeps historical report edits separate from cleanup authority", async () =>
} finally {
denied = false;
await scope.close();
await rm(root, { recursive: true, force: true });
}
});
@@ -114,11 +114,10 @@ import {
} from "../../../src/process/capture/ProcessCaptureLifecycle.js";
import { ProcessCaptureError } from "../../../src/process/capture/ProcessCaptureError.js";
import { classifyFilesystemEffects } from "../../../src/process/capture/ProcessFilesystemEffects.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const roots: string[] = [];
const trackedRoot = async (): Promise<string> => {
const root = await mkdtemp(join(tmpdir(), "rea-snapshot-handle-owner-"));
roots.push(root);
const root = await createTestTempDirectory("rea-snapshot-handle-owner-");
return root;
};
@@ -210,9 +209,6 @@ afterEach(async () => {
}
});
}
await Promise.all(
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
);
});
it("retains a completed file hash and its exact descriptor owner when close fails", async () => {
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it.each([
["no skill tool", false],
@@ -18,63 +19,59 @@ it.each([
["output terminal failure", false],
["output success", true],
] as const)("binds Qwen skill evidence for %s", async (mode, loaded) => {
const state = await mkdtemp(join(tmpdir(), "rea-qwen-skill-"));
try {
await writeFile(
join(state, "commands.mjs"),
"import {mkdir,readFile,writeFile} from 'node:fs/promises';import {join} from 'node:path';\nexport async function createVerifierCommands(){return {async exec(command,args,options={}){\n if(args.includes('--version'))return {stdout:'fake',stderr:''};\n const profile=options.env.QWEN_HOME;const config=join(profile,'settings.json');\n if(args.includes('setup')&&args.includes('--dry-run'))return {stdout:JSON.stringify({plannedActions:[{target:config}]}),stderr:''};\n if(args.includes('setup')){\n const original=await readFile(config,'utf8');await writeFile(config+'.rea.backup',original);\n const value=JSON.parse(original);value.mcpServers.rea={command:'/fake/rea',args:['mcp']};await writeFile(config,JSON.stringify(value));\n const skill=join(options.env.HOME,'.agents','skills','reverse-engineer-anything');await mkdir(skill,{recursive:true});\n const source='---\\nname: reverse-engineer-anything\\n---\\nQwen \"authored\" body\\nKeep a \\\\ literal\\n';\n await writeFile(join(skill,'SKILL.md'),process.env.MODE==='CRLF'?source.replaceAll('\\n','\\r\\n'):source);\n return {stdout:'{}',stderr:''};\n }\n if(args.includes('doctor'))return {stdout:'{}',stderr:''};\n if(process.env.MODE.startsWith('output ')){await globalThis.fakeRequest({body:{messages:[]},tools:[],requestIndex:1});const {TOOL_CONTRACTS}=await import(process.env.CONTRACTS);const events=[{type:'system',subtype:'init',tools:TOOL_CONTRACTS.map(c=>'mcp__rea__'+c.name)}];const success={type:'result',subtype:'success',is_error:false,result:process.env.MODE==='output missing marker'?'': 'REA_CLIENT_COMPATIBILITY_OK'};if(process.env.MODE!=='output missing result')events.push(success);if(process.env.MODE==='output terminal failure')events.push({type:'result',subtype:'error_during_execution',is_error:true});return {stdout:events.map(e=>JSON.stringify(e)).join('\\n')+'\\n',stderr:''};}\n const skill=join(options.env.HOME,'.agents','skills','reverse-engineer-anything');\n const content='Base directory for this skill: '+skill+'\\nImportant: ALWAYS resolve absolute paths from this base directory when working with skills.\\n\\nQwen \"authored\" body\\nKeep a \\\\ literal\\n';\n const tools=[...(process.env.MODE==='no skill tool'?[]:[{name:'skill'}]),{name:'mcp__rea__analyze_javascript_application'}];\n const first=await globalThis.fakeRequest({body:{messages:[]},tools,requestIndex:1});const callId=first.tool_calls[0].id;\n let messages=(process.env.MODE==='user mention'||process.env.MODE==='no skill tool')?[{role:'user',content:'Unrelated '+skill}]:[{role:'tool',tool_call_id:process.env.MODE==='wrong id'?'other':callId,content:process.env.MODE==='missing body'?'Base directory for this skill: '+skill:content}];\n if(process.env.MODE==='split')messages=[{role:'tool',tool_call_id:callId,content:'Base directory for this skill: '+skill},{role:'tool',tool_call_id:'other',content}];\n const second=await globalThis.fakeRequest({body:{messages},tools,requestIndex:2});await writeFile(process.env.STATE+'/observed.json',JSON.stringify({first,second,messages}));throw Error('intentional stop before client output');\n},async close(){}};}\n",
);
await writeFile(
join(state, "fixture.mjs"),
"export async function createOpenAiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
);
await writeFile(
const state = await createTestTempDirectory("rea-qwen-skill-");
await writeFile(
join(state, "commands.mjs"),
"import {mkdir,readFile,writeFile} from 'node:fs/promises';import {join} from 'node:path';\nexport async function createVerifierCommands(){return {async exec(command,args,options={}){\n if(args.includes('--version'))return {stdout:'fake',stderr:''};\n const profile=options.env.QWEN_HOME;const config=join(profile,'settings.json');\n if(args.includes('setup')&&args.includes('--dry-run'))return {stdout:JSON.stringify({plannedActions:[{target:config}]}),stderr:''};\n if(args.includes('setup')){\n const original=await readFile(config,'utf8');await writeFile(config+'.rea.backup',original);\n const value=JSON.parse(original);value.mcpServers.rea={command:'/fake/rea',args:['mcp']};await writeFile(config,JSON.stringify(value));\n const skill=join(options.env.HOME,'.agents','skills','reverse-engineer-anything');await mkdir(skill,{recursive:true});\n const source='---\\nname: reverse-engineer-anything\\n---\\nQwen \"authored\" body\\nKeep a \\\\ literal\\n';\n await writeFile(join(skill,'SKILL.md'),process.env.MODE==='CRLF'?source.replaceAll('\\n','\\r\\n'):source);\n return {stdout:'{}',stderr:''};\n }\n if(args.includes('doctor'))return {stdout:'{}',stderr:''};\n if(process.env.MODE.startsWith('output ')){await globalThis.fakeRequest({body:{messages:[]},tools:[],requestIndex:1});const {TOOL_CONTRACTS}=await import(process.env.CONTRACTS);const events=[{type:'system',subtype:'init',tools:TOOL_CONTRACTS.map(c=>'mcp__rea__'+c.name)}];const success={type:'result',subtype:'success',is_error:false,result:process.env.MODE==='output missing marker'?'': 'REA_CLIENT_COMPATIBILITY_OK'};if(process.env.MODE!=='output missing result')events.push(success);if(process.env.MODE==='output terminal failure')events.push({type:'result',subtype:'error_during_execution',is_error:true});return {stdout:events.map(e=>JSON.stringify(e)).join('\\n')+'\\n',stderr:''};}\n const skill=join(options.env.HOME,'.agents','skills','reverse-engineer-anything');\n const content='Base directory for this skill: '+skill+'\\nImportant: ALWAYS resolve absolute paths from this base directory when working with skills.\\n\\nQwen \"authored\" body\\nKeep a \\\\ literal\\n';\n const tools=[...(process.env.MODE==='no skill tool'?[]:[{name:'skill'}]),{name:'mcp__rea__analyze_javascript_application'}];\n const first=await globalThis.fakeRequest({body:{messages:[]},tools,requestIndex:1});const callId=first.tool_calls[0].id;\n let messages=(process.env.MODE==='user mention'||process.env.MODE==='no skill tool')?[{role:'user',content:'Unrelated '+skill}]:[{role:'tool',tool_call_id:process.env.MODE==='wrong id'?'other':callId,content:process.env.MODE==='missing body'?'Base directory for this skill: '+skill:content}];\n if(process.env.MODE==='split')messages=[{role:'tool',tool_call_id:callId,content:'Base directory for this skill: '+skill},{role:'tool',tool_call_id:'other',content}];\n const second=await globalThis.fakeRequest({body:{messages},tools,requestIndex:2});await writeFile(process.env.STATE+'/observed.json',JSON.stringify({first,second,messages}));throw Error('intentional stop before client output');\n},async close(){}};}\n",
);
await writeFile(
join(state, "fixture.mjs"),
"export async function createOpenAiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
);
await writeFile(
join(state, "hook.mjs"),
"import {registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-qwen-client.mjs')){let f;if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
);
const script = fileURLToPath(
new URL("../../../scripts/verify-qwen-client.mjs", import.meta.url),
);
const result = spawnSync(
process.execPath,
[
"--import",
join(state, "hook.mjs"),
"import {registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-qwen-client.mjs')){let f;if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
);
const script = fileURLToPath(
new URL("../../../scripts/verify-qwen-client.mjs", import.meta.url),
);
const result = spawnSync(
process.execPath,
[
"--import",
join(state, "hook.mjs"),
script,
...(mode.startsWith("output ") ? ["chat"] : []),
],
{
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
MODE: mode,
CONTRACTS: new URL(
"../../../dist/contracts/toolContracts.js",
import.meta.url,
).href,
TMPDIR: state,
TMP: state,
TEMP: state,
},
script,
...(mode.startsWith("output ") ? ["chat"] : []),
],
{
encoding: "utf8",
timeout: 10_000,
env: {
...process.env,
STATE: state,
MODE: mode,
CONTRACTS: new URL(
"../../../dist/contracts/toolContracts.js",
import.meta.url,
).href,
TMPDIR: state,
TMP: state,
TEMP: state,
},
);
if (mode.startsWith("output ")) {
// Authored stream result shape from Qwen's BaseJsonOutputAdapter at
// QwenLM/qwen-code c238beb56fa3c65a0f62ad7a3b2cd14db978b998.
expect(result.status, result.stderr).toBe(loaded ? 0 : 1);
const receipt = JSON.parse(result.stdout.trim().split("\n")[0] ?? "");
expect(receipt.finalSeen).toBe(loaded);
expect(receipt.passed).toBe(loaded);
return;
}
expect(result.status).not.toBe(0);
expect(result.stderr).toContain("intentional stop before client output");
},
);
if (mode.startsWith("output ")) {
// Authored stream result shape from Qwen's BaseJsonOutputAdapter at
// QwenLM/qwen-code c238beb56fa3c65a0f62ad7a3b2cd14db978b998.
expect(result.status, result.stderr).toBe(loaded ? 0 : 1);
const receipt = JSON.parse(result.stdout.trim().split("\n")[0] ?? "");
expect(receipt.selectedSkillLoaded).toBe(loaded);
expect(receipt.passed).toBe(false);
} finally {
await rm(state, { recursive: true, force: true });
expect(receipt.finalSeen).toBe(loaded);
expect(receipt.passed).toBe(loaded);
return;
}
expect(result.status).not.toBe(0);
expect(result.stderr).toContain("intentional stop before client output");
const receipt = JSON.parse(result.stdout.trim().split("\n")[0] ?? "");
expect(receipt.selectedSkillLoaded).toBe(loaded);
expect(receipt.passed).toBe(false);
});
@@ -54,11 +54,10 @@ import {
observeSelectedExecutable,
} from "../../../src/process/capture/ProcessCaptureLifecycle.js";
import { ProcessCaptureReadFailure } from "../../../src/process/capture/ProcessCaptureRead.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const roots: string[] = [];
const createExecutable = async (content: string): Promise<string> => {
const root = await mkdtemp(join(tmpdir(), "rea-selected-executable-owner-"));
roots.push(root);
const root = await createTestTempDirectory("rea-selected-executable-owner-");
const path = join(root, "selected-fixture");
await writeFile(path, content);
return path;
@@ -97,9 +96,6 @@ afterEach(async () => {
injected.abortOnClose = undefined;
injected.opened = [];
injected.closed = [];
await Promise.all(
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
);
vi.restoreAllMocks();
});
File diff suppressed because it is too large. Load diff
@@ -10,6 +10,7 @@ import {
ownedFailure,
ownedOutput,
} from "../support/reverseEngineeringCompositionFixtures.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
it.each([
{ budget: undefined, capacity: 8 },
@@ -17,7 +18,7 @@ it.each([
])(
"bounds provider concurrency and aggregate capture admission at budget $budget",
async ({ budget, capacity }) => {
const directory = await mkdtemp(join(tmpdir(), "rea-reverse-capacity-"));
const directory = await createTestTempDirectory("rea-reverse-capacity-");
const path = join(directory, "fixture.bin");
await writeFile(path, "fixture");
const input = {
@@ -102,13 +103,12 @@ it.each([
} finally {
release();
await service.close();
await rm(directory, { recursive: true, force: true });
}
},
);
it("preserves the exact caller reason when objdump admission is already aborted", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-reverse-preabort-"));
const directory = await createTestTempDirectory("rea-reverse-preabort-");
const path = join(directory, "fixture.bin");
await writeFile(path, "fixture");
const reason = Object.freeze({ requested: "stop" });
@@ -133,12 +133,11 @@ it("preserves the exact caller reason when objdump admission is already aborted"
expect(runs).toBe(0);
} finally {
await service.close();
await rm(directory, { recursive: true, force: true });
}
});
it("preserves the caller reason when cancellation arrives after provider output", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-reverse-postabort-"));
const directory = await createTestTempDirectory("rea-reverse-postabort-");
const path = join(directory, "fixture.bin");
await writeFile(path, "fixture");
const reason = Object.freeze({ requested: "stop-after-output" });
@@ -163,12 +162,11 @@ it("preserves the caller reason when cancellation arrives after provider output"
});
} finally {
await service.close();
await rm(directory, { recursive: true, force: true });
}
});
it("keeps a physical digest denial primary when the caller aborts during that failure", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-reverse-digest-deny-"));
const directory = await createTestTempDirectory("rea-reverse-digest-deny-");
const path = join(directory, "fixture.bin");
await writeFile(path, "fixture");
const reason = Object.freeze({ requested: "stop-during-denial" });
@@ -201,12 +199,11 @@ it("keeps a physical digest denial primary when the caller aborts during that fa
expect(runs).toBe(0);
} finally {
await service.close();
await rm(directory, { recursive: true, force: true });
}
});
it("keeps an unrelated digest ABORT_ERR as an adapter failure", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-reverse-digest-abort-"));
const directory = await createTestTempDirectory("rea-reverse-digest-abort-");
const path = join(directory, "fixture.bin");
await writeFile(path, "fixture");
const denied = Object.assign(new Error("digest aborted elsewhere"), {
@@ -230,12 +227,11 @@ it("keeps an unrelated digest ABORT_ERR as an adapter failure", async () => {
expect(result.error.cause).toBe(denied);
} finally {
await service.close();
await rm(directory, { recursive: true, force: true });
}
});
it("does not report a command ABORT_ERR without the caller's abort as cancellation", async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-reverse-command-abort-"));
const directory = await createTestTempDirectory("rea-reverse-command-abort-");
const path = join(directory, "fixture.bin");
await writeFile(path, "fixture");
const failure = Object.assign(new Error("aborted by another signal"), {
@@ -256,7 +252,6 @@ it("does not report a command ABORT_ERR without the caller's abort as cancellati
expect(result.error._tag).not.toBe("AnalysisCancelledError");
} finally {
await service.close();
await rm(directory, { recursive: true, force: true });
}
});
@@ -289,8 +284,8 @@ it.each([
] as const)(
"classifies a $code command failure with captured output $captured while the caller is aborted",
async ({ captured, code, tag }) => {
const directory = await mkdtemp(
join(tmpdir(), "rea-reverse-command-abort-"),
const directory = await createTestTempDirectory(
"rea-reverse-command-abort-",
);
const path = join(directory, "fixture.bin");
await writeFile(path, "fixture");
@@ -345,7 +340,6 @@ it.each([
}
} finally {
await service.close();
await rm(directory, { recursive: true, force: true });
}
},
);
@@ -5,6 +5,7 @@ import { join } from "node:path";
import { expect, it } from "vitest";
import { TestReverseEngineeringService as ReverseEngineeringService } from "../support/reverseEngineeringService.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
type PromiseOutcome<Value> =
| { readonly status: "fulfilled"; readonly value: Value }
@@ -159,44 +160,39 @@ const cleanupCancellationScenario = async (options: {
readonly pending: Promise<CancellationResult> | undefined;
readonly service: ReverseEngineeringService;
readonly processIds: CancellationProcessIds | undefined;
readonly directory: string;
}): Promise<void> => {
options.controller.abort();
try {
if (options.pending !== undefined) {
try {
if (options.processIds !== undefined)
await settleCancelledProvider(options.pending);
else await settleWithin(options.pending, 10_000);
} catch {
// Main assertions report operation failures; continue cleanup.
}
if (options.pending !== undefined) {
try {
if (options.processIds !== undefined)
await settleCancelledProvider(options.pending);
else await settleWithin(options.pending, 10_000);
} catch {
// Main assertions report operation failures; continue cleanup.
}
let cleanup = await settleWithin(options.service.close(), 7_000);
if (cleanup.status === "timeout" && options.processIds !== undefined) {
await killCancellationProcesses(options.processIds);
cleanup = await settleWithin(options.service.close(), 3_000);
}
let cleanup = await settleWithin(options.service.close(), 7_000);
if (cleanup.status === "timeout" && options.processIds !== undefined) {
await killCancellationProcesses(options.processIds);
cleanup = await settleWithin(options.service.close(), 3_000);
}
if (cleanup.status === "timeout")
throw new Error("Service cleanup did not settle within its deadline.");
if (cleanup.status === "rejected") throw cleanup.reason;
if (options.processIds !== undefined) {
for (const pid of [
options.processIds.providerPid,
options.processIds.descendantPid,
]) {
if (processIsRunning(pid)) await killProcessAndWait(pid, 2_000);
}
if (cleanup.status === "timeout")
throw new Error("Service cleanup did not settle within its deadline.");
if (cleanup.status === "rejected") throw cleanup.reason;
if (options.processIds !== undefined) {
for (const pid of [
options.processIds.providerPid,
options.processIds.descendantPid,
]) {
if (processIsRunning(pid)) await killProcessAndWait(pid, 2_000);
}
}
} finally {
await rm(options.directory, { recursive: true, force: true });
}
};
it.skipIf(process.platform === "win32")(
"waits for a cancelled Rizin process to exit before returning",
async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-rizin-cancel-settle-"));
const directory = await createTestTempDirectory("rea-rizin-cancel-settle-");
const path = join(directory, "fixture.bin");
const providerPidMarker = join(directory, "provider-pid");
const descendantStartedMarker = join(directory, "descendant-started");
@@ -261,7 +257,6 @@ setInterval(() => {}, 1000);
pending,
service,
processIds,
directory,
});
}
},
@@ -19,6 +19,7 @@ import { awaitAcknowledgement } from "../../fixtures/lifecycleAcknowledgement.js
import { runningTestDeadline } from "../../support/runningTestDeadline.js";
import { waitFor } from "../../support/testWait.js";
import { removeTestWorkspace } from "../../support/workspace/workspaceFixture.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const digest = (bytes: string | Buffer) =>
createHash("sha256").update(bytes).digest("hex");
@@ -27,13 +28,10 @@ const verifier = fileURLToPath(
);
const ownedFixture = async (prefix: string) => {
const root = await createTestTempDirectory(prefix);
const commands = await createVerifierCommands();
let root: string | undefined;
onTestFinished(async () => {
await commands.close();
if (root !== undefined) await removeTestWorkspace(root);
});
root = await realpath(await mkdtemp(join(await realpath(tmpdir()), prefix)));
// Registered after the directory helper so stack order closes commands first.
onTestFinished(() => commands.close());
return { commands, root };
};
@@ -3,10 +3,10 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { expect, it, onTestFinished } from "vitest";
import { assertCheckpointRefusalPreservesManifest } from "../../../../scripts/lib/ghidra-checkpoint-refusal.mjs";
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
const checkpointFile = async (bytes: Uint8Array) => {
const root = await mkdtemp(join(tmpdir(), "rea-checkpoint-refusal-"));
onTestFinished(() => rm(root, { recursive: true, force: true }));
const root = await createTestTempDirectory("rea-checkpoint-refusal-");
const path = join(root, "current.json");
await writeFile(path, bytes);
return path;
@@ -6,6 +6,7 @@ import { join } from "node:path";
import { test } from "vitest";
import { z } from "zod";
import { fileURLToPath } from "node:url";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
type Delivery = "complete" | "summary";
type Observation = {
@@ -90,45 +91,41 @@ const fixture = (delivery: Delivery, artifact: string): Fixture => ({
],
},
});
function compare(left: Fixture, right: Fixture) {
const root = mkdtempSync(join(tmpdir(), "rea-compare-test-"));
try {
const directories = [join(root, "left"), join(root, "right")] as const;
for (const [index, value] of [left, right].entries()) {
const directory = directories[index];
assert.ok(directory);
mkdirSync(directory);
for (const name of ["summary", "answer"] as const)
writeFileSync(
join(directory, `${name}.json`),
JSON.stringify(value[name]),
);
}
const result = spawnSync(
process.execPath,
[
fileURLToPath(
new URL(
"../../tests/support/analysis-efficiency/compare.mjs",
import.meta.url,
),
),
"--left",
directories[0],
"--right",
directories[1],
],
{ encoding: "utf8" },
);
assert.ifError(result.error);
assert.equal(result.stderr, "");
return {
status: result.status,
report: reportSchema.parse(JSON.parse(result.stdout)),
};
} finally {
rmSync(root, { recursive: true, force: true });
async function compare(left: Fixture, right: Fixture) {
const root = await createTestTempDirectory("rea-compare-test-");
const directories = [join(root, "left"), join(root, "right")] as const;
for (const [index, value] of [left, right].entries()) {
const directory = directories[index];
assert.ok(directory);
mkdirSync(directory);
for (const name of ["summary", "answer"] as const)
writeFileSync(
join(directory, `${name}.json`),
JSON.stringify(value[name]),
);
}
const result = spawnSync(
process.execPath,
[
fileURLToPath(
new URL(
"../../tests/support/analysis-efficiency/compare.mjs",
import.meta.url,
),
),
"--left",
directories[0],
"--right",
directories[1],
],
{ encoding: "utf8" },
);
assert.ifError(result.error);
assert.equal(result.stderr, "");
return {
status: result.status,
report: reportSchema.parse(JSON.parse(result.stdout)),
};
}
for (const artifact of [
@@ -136,7 +133,7 @@ for (const artifact of [
"wireshark-dns.cap",
"wireshark-dhcp.pcap",
]) {
test(`${artifact}: compare requested facts across packet plans and preserve observations`, () => {
test(`${artifact}: compare requested facts across packet plans and preserve observations`, async () => {
const left = fixture("complete", artifact);
left.summary.packet_selection = "baseline";
left.answer.facts = {
@@ -149,7 +146,7 @@ for (const artifact of [
right.answer.delivery_observations[0]!.evidence_id = "ev_focused";
right.answer.delivery_observations[0]!.coverage =
"up-to-input-packet-limit";
const equivalent = compare(left, right);
const equivalent = await compare(left, right);
assert.equal(equivalent.status, 0);
assert.equal(equivalent.report.facts_match, true);
assert.deepEqual(
@@ -157,15 +154,15 @@ for (const artifact of [
[left.answer.delivery_observations, right.answer.delivery_observations],
);
right.answer.facts!.matching_packets = 1338;
assert.equal(compare(left, right).report.facts_match, false);
assert.equal((await compare(left, right)).report.facts_match, false);
right.answer.facts!.matching_packets = 1337;
right.summary.packet_selection = "baseline";
assert.equal(compare(left, right).report.facts_match, false);
assert.equal((await compare(left, right)).report.facts_match, false);
});
}
for (const artifact of ["sigrok-uart-max3232e.sr", "sigrok-i2c-nunchuk.sr"]) {
test(`${artifact}: compare decoded facts across signal plans and preserve display scope`, () => {
test(`${artifact}: compare decoded facts across signal plans and preserve display scope`, async () => {
const left = fixture("complete", artifact);
left.summary.signal_selection = "baseline";
left.answer.facts = { kind: "signal", bytes: [72, 101] };
@@ -173,7 +170,7 @@ for (const artifact of ["sigrok-uart-max3232e.sr", "sigrok-i2c-nunchuk.sr"]) {
right.summary.signal_selection = "focused";
right.answer.delivery_observations[0]!.coverage =
"selected annotation lines";
const equivalent = compare(left, right);
const equivalent = await compare(left, right);
assert.equal(equivalent.status, 0);
assert.equal(equivalent.report.facts_match, true);
assert.deepEqual(
@@ -181,10 +178,10 @@ for (const artifact of ["sigrok-uart-max3232e.sr", "sigrok-i2c-nunchuk.sr"]) {
[left.answer.delivery_observations, right.answer.delivery_observations],
);
right.answer.facts!.bytes![0] = 73;
assert.equal(compare(left, right).report.facts_match, false);
assert.equal((await compare(left, right)).report.facts_match, false);
right.answer.facts!.bytes![0] = 72;
right.summary.signal_selection = "baseline";
assert.equal(compare(left, right).report.facts_match, false);
assert.equal((await compare(left, right)).report.facts_match, false);
});
}
@@ -192,7 +189,7 @@ for (const artifact of [
"wireshark-http.cap",
"wireshark-http_redirects.pcapng",
]) {
test(`${artifact}: repeated modes ignore only receipt IDs`, () => {
test(`${artifact}: repeated modes ignore only receipt IDs`, async () => {
for (const delivery of ["complete", "summary"] as const) {
const left = fixture(delivery, artifact);
const right = structuredClone(left);
@@ -201,7 +198,7 @@ for (const artifact of [
if (typeof value.parent_evidence_id === "string")
value.parent_evidence_id += "_second";
}
const { status, report } = compare(left, right);
const { status, report } = await compare(left, right);
assert.equal(status, 0);
assert.equal(report.facts_match, true);
assert.deepEqual(
@@ -211,7 +208,7 @@ for (const artifact of [
}
});
test(`${artifact}: repeated modes reject stable observation changes`, () => {
test(`${artifact}: repeated modes reject stable observation changes`, async () => {
for (const delivery of ["complete", "summary"] as const) {
const left = fixture(delivery, artifact);
const mutations: ((values: Observation[]) => void)[] = [
@@ -239,7 +236,7 @@ for (const artifact of [
for (const mutate of mutations) {
const right = structuredClone(left);
mutate(right.answer.delivery_observations);
const { status, report } = compare(left, right);
const { status, report } = await compare(left, right);
assert.equal(status, 1);
assert.equal(report.settings_match, true);
assert.equal(report.facts_match, false);
@@ -248,10 +245,10 @@ for (const artifact of [
}
});
test(`${artifact}: different modes preserve their different receipt scopes`, () => {
test(`${artifact}: different modes preserve their different receipt scopes`, async () => {
const left = fixture("complete", artifact);
const right = fixture("summary", artifact);
const { status, report } = compare(left, right);
const { status, report } = await compare(left, right);
assert.equal(status, 0);
assert.equal(report.facts_match, true);
assert.deepEqual(
@@ -259,6 +256,6 @@ for (const artifact of [
[left.answer.delivery_observations, right.answer.delivery_observations],
);
right.answer.capture.coverage = "partial";
assert.equal(compare(left, right).report.facts_match, false);
assert.equal((await compare(left, right)).report.facts_match, false);
});
}
@@ -9,6 +9,7 @@ import { createDarwinProcessRunTokenReader } from "../../src/process/DarwinProce
import { createSystemProcessOwnershipHost } from "../../src/process/ProcessOwnershipObservation.js";
import { startProcessSampler } from "../../src/process/capture/ProcessSampling.js";
import { ProcessOwnershipInspectionCancelled } from "../../src/process/ProcessInspectionCancellation.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
const waitForFile = async (path: string, timeoutMs = 4_000): Promise<void> => {
const deadline = Date.now() + timeoutMs;
@@ -81,25 +82,21 @@ const createDelayedCommand = async (directory: string) => {
const expectOwnedCommandToFinishOnAbort = async (
run: (signal: AbortSignal, directory: string) => Promise<unknown>,
): Promise<void> => {
const directory = await mkdtemp(join(tmpdir(), "rea-process-command-"));
const directory = await createTestTempDirectory("rea-process-command-");
const command = await createDelayedCommand(directory);
const controller = new AbortController();
const reason = new Error("cancel owned process command");
let pending: Promise<unknown> | undefined;
onTestFinished(async () => {
try {
controller.abort(reason);
await pending?.catch(() => {});
if (
await readFile(command.readyPath).then(
() => true,
() => false,
)
controller.abort(reason);
await pending?.catch(() => {});
if (
await readFile(command.readyPath).then(
() => true,
() => false,
)
await waitForFile(command.donePath);
} finally {
await rm(directory, { recursive: true, force: true });
}
)
await waitForFile(command.donePath);
});
pending = run(controller.signal, directory);
@@ -155,7 +152,7 @@ const processEntry = {
it.skipIf(process.platform === "win32")(
"waits for the owned ps command to exit when sampling stops",
async () => {
const directory = await mkdtemp(join(tmpdir(), "rea-process-sampler-"));
const directory = await createTestTempDirectory("rea-process-sampler-");
const readyPath = join(directory, "ready");
const donePath = join(directory, "done");
const psPath = join(directory, "ps");
@@ -175,7 +172,6 @@ it.skipIf(process.platform === "win32")(
await waitForFile(donePath);
} finally {
restoreProcessGlobals();
await rm(directory, { recursive: true, force: true });
}
});
@@ -229,27 +225,23 @@ it
const expectDarwinReaderCommandToFinishOnAbort = async (
operation: "read" | "identities",
): Promise<void> => {
const directory = await mkdtemp(join(tmpdir(), `rea-darwin-${operation}-`));
const directory = await createTestTempDirectory(`rea-darwin-${operation}-`);
const command = await createDelayedCommand(directory);
const reader = await createFakeDarwinReader(directory, command);
const controller = new AbortController();
const reason = new Error(`cancel ${operation}`);
let pending: Promise<unknown> | undefined;
onTestFinished(async () => {
try {
controller.abort(reason);
await pending?.catch(() => {});
if (
await readFile(command.readyPath).then(
() => true,
() => false,
)
controller.abort(reason);
await pending?.catch(() => {});
if (
await readFile(command.readyPath).then(
() => true,
() => false,
)
await waitForFile(command.donePath);
await reader.close();
} finally {
await rm(directory, { recursive: true, force: true });
}
)
await waitForFile(command.donePath);
await reader.close();
});
pending =