feat: complete REA remediation program
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFile, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { createAnalysisExecution } from "../src/application/AnalysisProvider.js";
|
||||
import { AnalysisSnapshotCache } from "../src/application/AnalysisSnapshotCache.js";
|
||||
import {
|
||||
@@ -144,7 +145,7 @@ describe("analysis snapshots", () => {
|
||||
});
|
||||
|
||||
it("writes canonical private v2 JSON and rejects changed query identity", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-snapshot-"));
|
||||
directory = await createTestTempDirectory("rea-snapshot-");
|
||||
const path = join(directory, "analysis.json");
|
||||
const target = snapshotTarget(TARGET);
|
||||
const binding = snapshotBinding(PROFILE);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
@@ -10,6 +9,8 @@ import {
|
||||
} from "@zip.js/zip.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { projectAndroidApplicationEvidence } from "../src/application/AndroidApplicationService.js";
|
||||
import { runProviderAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import { androidApplicationProjectionResultSchema } from "../src/domain/androidApplication.js";
|
||||
@@ -17,7 +18,7 @@ import { parseEvidence } from "../src/domain/evidence.js";
|
||||
|
||||
describe("Android application projection", () => {
|
||||
it("projects deterministic APK components and explicit bridge hypotheses", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-android-"));
|
||||
const root = await createTestTempDirectory("rea-android-");
|
||||
const path = join(root, "Fixture.apk");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add(
|
||||
@@ -93,7 +94,7 @@ describe("Android application projection", () => {
|
||||
});
|
||||
|
||||
it("rejects non-APK inventory Evidence", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-android-invalid-"));
|
||||
const root = await createTestTempDirectory("rea-android-invalid-");
|
||||
const path = join(root, "fixture.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("one.js", new TextReader("one"));
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
@@ -10,6 +9,8 @@ import {
|
||||
} from "@zip.js/zip.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { projectAppleApplicationEvidence } from "../src/application/AppleApplicationService.js";
|
||||
import { runProviderAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import { appleApplicationProjectionResultSchema } from "../src/domain/appleApplication.js";
|
||||
@@ -17,7 +18,7 @@ import { parseEvidence } from "../src/domain/evidence.js";
|
||||
|
||||
describe("Apple application projection", () => {
|
||||
it("projects deterministic IPA components and bridge hypotheses from exact inventory Evidence", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-apple-"));
|
||||
const root = await createTestTempDirectory("rea-apple-");
|
||||
const path = join(root, "Fixture.ipa");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("Payload/Fixture.app/", undefined, { directory: true });
|
||||
@@ -103,7 +104,7 @@ describe("Apple application projection", () => {
|
||||
});
|
||||
|
||||
it("rejects non-IPA Evidence and reports projection truncation", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-apple-invalid-"));
|
||||
const root = await createTestTempDirectory("rea-apple-invalid-");
|
||||
const path = join(root, "fixture.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("one.js", new TextReader("one"));
|
||||
@@ -120,7 +121,7 @@ describe("Apple application projection", () => {
|
||||
});
|
||||
|
||||
it("infers an application root when the IPA omits directory entries", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-apple-root-"));
|
||||
const root = await createTestTempDirectory("rea-apple-root-");
|
||||
const path = join(root, "Fixture.ipa");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add(
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
|
||||
JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE,
|
||||
JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE,
|
||||
} from "../src/contracts/javascriptApplicationWorkflowExamples.js";
|
||||
import {
|
||||
createEvidenceBundle,
|
||||
serializeEvidenceBundle,
|
||||
} from "../src/domain/evidenceBundle.js";
|
||||
import { analyzeJavaScriptApplication } from "../src/application/JavaScriptApplicationService.js";
|
||||
import { permissionAuthorityForRoot } from "./fixtures/permissionAuthority.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
|
||||
@@ -27,7 +36,7 @@ describe("application workflow CLI parity", () => {
|
||||
it("accepts inline trace JSON and file-backed comparison JSON", async () => {
|
||||
const traced = await runCli([
|
||||
"trace-application-feature",
|
||||
JSON.stringify(JAVASCRIPT_FEATURE_TRACE_EXAMPLE),
|
||||
JSON.stringify(JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE),
|
||||
"--json",
|
||||
]);
|
||||
expect(traced).toMatchObject({
|
||||
@@ -35,12 +44,12 @@ describe("application workflow CLI parity", () => {
|
||||
normalized_result: { schema_version: 1 },
|
||||
});
|
||||
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-application-cli-"));
|
||||
const root = await createTestTempDirectory("rea-application-cli-");
|
||||
temporary.push(root);
|
||||
const comparisonPath = join(root, "comparison.json");
|
||||
await writeFile(
|
||||
comparisonPath,
|
||||
JSON.stringify(JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE),
|
||||
JSON.stringify(JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE),
|
||||
);
|
||||
const compared = await runCli([
|
||||
"compare-application-versions",
|
||||
@@ -56,6 +65,174 @@ describe("application workflow CLI parity", () => {
|
||||
});
|
||||
}, 20_000);
|
||||
|
||||
it("resolves Evidence IDs from an explicitly authorized bundle", async () => {
|
||||
const root = await createTestTempDirectory("rea-application-bundle-cli-");
|
||||
temporary.push(root);
|
||||
const bundlePath = join(root, "evidence.json");
|
||||
await writeFile(
|
||||
bundlePath,
|
||||
serializeEvidenceBundle(
|
||||
createEvidenceBundle([
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left,
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.right,
|
||||
]),
|
||||
),
|
||||
);
|
||||
const environment = {
|
||||
REA_EVIDENCE_ROOTS_JSON: JSON.stringify([root]),
|
||||
};
|
||||
|
||||
const traced = await runCli(
|
||||
[
|
||||
"trace-application-feature",
|
||||
JSON.stringify({
|
||||
...JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
|
||||
application_evidence_id:
|
||||
JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE.application
|
||||
.evidence_id,
|
||||
}),
|
||||
"--evidence-bundle",
|
||||
bundlePath,
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
);
|
||||
expect(traced).toMatchObject({
|
||||
operation: "trace_application_feature",
|
||||
normalized_result: { schema_version: 1 },
|
||||
});
|
||||
|
||||
const compared = await runCli(
|
||||
[
|
||||
"compare-application-versions",
|
||||
JSON.stringify({
|
||||
...JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
|
||||
left_evidence_id:
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left
|
||||
.evidence_id,
|
||||
right_evidence_id:
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.right
|
||||
.evidence_id,
|
||||
}),
|
||||
"--evidence-bundle",
|
||||
bundlePath,
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
);
|
||||
expect(compared).toMatchObject({
|
||||
operation: "compare_application_versions",
|
||||
normalized_result: { schema_version: 1 },
|
||||
});
|
||||
|
||||
const missingRecord = await runCli(
|
||||
[
|
||||
"trace-application-feature",
|
||||
JSON.stringify(JAVASCRIPT_FEATURE_TRACE_EXAMPLE),
|
||||
"--evidence-bundle",
|
||||
bundlePath,
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
);
|
||||
expect(missingRecord).toMatchObject({
|
||||
code: "evidence_integrity_mismatch",
|
||||
details: { reason: "missing" },
|
||||
});
|
||||
|
||||
const outsideRoot = await createTestTempDirectory(
|
||||
"rea-outside-bundle-cli-",
|
||||
);
|
||||
temporary.push(outsideRoot);
|
||||
const outsideBundlePath = join(outsideRoot, "evidence.json");
|
||||
await writeFile(
|
||||
outsideBundlePath,
|
||||
serializeEvidenceBundle(createEvidenceBundle([])),
|
||||
);
|
||||
const denied = await runCli(
|
||||
[
|
||||
"trace-application-feature",
|
||||
JSON.stringify(JAVASCRIPT_FEATURE_TRACE_EXAMPLE),
|
||||
"--evidence-bundle",
|
||||
outsideBundlePath,
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
);
|
||||
expect(denied).toMatchObject({ code: "permission_required" });
|
||||
}, 20_000);
|
||||
|
||||
it("compares exact export shapes from an authorized Evidence bundle", async () => {
|
||||
const root = await createTestTempDirectory("rea-export-shape-cli-");
|
||||
temporary.push(root);
|
||||
const leftRoot = join(root, "left");
|
||||
const rightRoot = join(root, "right");
|
||||
await Promise.all([mkdir(leftRoot), mkdir(rightRoot)]);
|
||||
await Promise.all([
|
||||
copyFile(
|
||||
join(process.cwd(), "tests/fixtures/replay/parser.mjs"),
|
||||
join(leftRoot, "parser.mjs"),
|
||||
),
|
||||
copyFile(
|
||||
join(process.cwd(), "tests/fixtures/replay/parser-v2.mjs"),
|
||||
join(rightRoot, "parser.mjs"),
|
||||
),
|
||||
]);
|
||||
const authority = await permissionAuthorityForRoot(
|
||||
root,
|
||||
["investigation_input"],
|
||||
["investigation_input"],
|
||||
);
|
||||
const [left, right] = await Promise.all([
|
||||
analyzeJavaScriptApplication(authority, {
|
||||
input_path: leftRoot,
|
||||
approved: true,
|
||||
}),
|
||||
analyzeJavaScriptApplication(authority, {
|
||||
input_path: rightRoot,
|
||||
approved: true,
|
||||
}),
|
||||
]);
|
||||
if (!left.ok) throw left.error;
|
||||
if (!right.ok) throw right.error;
|
||||
const bundlePath = join(root, "evidence.json");
|
||||
await writeFile(
|
||||
bundlePath,
|
||||
serializeEvidenceBundle(createEvidenceBundle([left.value, right.value])),
|
||||
);
|
||||
const compared = await runCli(
|
||||
[
|
||||
"compare-javascript-export-shapes",
|
||||
JSON.stringify({
|
||||
left_evidence_id: left.value.evidence_id,
|
||||
right_evidence_id: right.value.evidence_id,
|
||||
left_module_path: "parser.mjs",
|
||||
left_export_name: "default",
|
||||
right_module_path: "parser.mjs",
|
||||
right_export_name: "default",
|
||||
}),
|
||||
"--evidence-bundle",
|
||||
bundlePath,
|
||||
"--json",
|
||||
],
|
||||
{ REA_EVIDENCE_ROOTS_JSON: JSON.stringify([root]) },
|
||||
);
|
||||
expect(compared).toMatchObject({
|
||||
operation: "compare_javascript_export_shapes",
|
||||
predicate_type: "rea.javascript-export-shape-comparison/v1",
|
||||
normalized_result: {
|
||||
summary: { added: 1, removed: 0, changed: 0, unknown: 0 },
|
||||
changes: [
|
||||
{
|
||||
status: "added",
|
||||
path: "/depth",
|
||||
right: { availability: "literal", value: 1 },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}, 20_000);
|
||||
|
||||
it("returns safe actionable JSON validation details", async () => {
|
||||
const malformed = await runCli([
|
||||
"trace-application-feature",
|
||||
@@ -77,7 +254,7 @@ describe("application workflow CLI parity", () => {
|
||||
details: {
|
||||
issues: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
path: ["application"],
|
||||
path: ["seed"],
|
||||
reason: "missing_argument",
|
||||
}),
|
||||
]),
|
||||
@@ -86,12 +263,19 @@ describe("application workflow CLI parity", () => {
|
||||
}, 20_000);
|
||||
});
|
||||
|
||||
const runCli = async (arguments_: readonly string[]): Promise<unknown> => {
|
||||
const runCli = async (
|
||||
arguments_: readonly string[],
|
||||
environment: Readonly<Record<string, string>> = {},
|
||||
): Promise<unknown> => {
|
||||
try {
|
||||
const { stdout } = await execute(
|
||||
process.execPath,
|
||||
["scripts/rea.mjs", ...arguments_],
|
||||
{ cwd: process.cwd(), env: process.env, maxBuffer: 16 * 1_024 * 1_024 },
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
env: { ...process.env, ...environment },
|
||||
maxBuffer: 16 * 1_024 * 1_024,
|
||||
},
|
||||
);
|
||||
return JSON.parse(stdout);
|
||||
} catch (cause: unknown) {
|
||||
|
||||
@@ -1,22 +1,127 @@
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { createHash } from "node:crypto";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { readFile, realpath } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { copyFile, mkdir, readFile, realpath, rm } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import {
|
||||
JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
|
||||
JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE,
|
||||
JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE,
|
||||
} from "../src/contracts/javascriptApplicationWorkflowExamples.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
import { createServer } from "../src/server/createServer.js";
|
||||
import { observed } from "./fixtures/analysisExecution.js";
|
||||
import { PermissionAuthority } from "../src/application/PermissionAuthority.js";
|
||||
import { createPermissionPolicy } from "../src/domain/permissionPolicy.js";
|
||||
import { controlledReplayOutputSchema } from "../src/domain/javascriptReplay.js";
|
||||
import { nodeCharacterizationPreparationOutputSchema } from "../src/domain/nodeRuntimeCharacterization.js";
|
||||
import { analyzeJavaScriptApplication } from "../src/application/JavaScriptApplicationService.js";
|
||||
import { permissionAuthorityForRoot } from "./fixtures/permissionAuthority.js";
|
||||
|
||||
describe("application workflow MCP parity", () => {
|
||||
it("compares exact parser export shapes through full Evidence and session IDs", async () => {
|
||||
const root = await createTestTempDirectory("rea-export-shape-mcp-");
|
||||
const leftRoot = join(root, "left");
|
||||
const rightRoot = join(root, "right");
|
||||
await Promise.all([mkdir(leftRoot), mkdir(rightRoot)]);
|
||||
await Promise.all([
|
||||
copyFile(
|
||||
resolve("tests/fixtures/replay/parser.mjs"),
|
||||
join(leftRoot, "parser.mjs"),
|
||||
),
|
||||
copyFile(
|
||||
resolve("tests/fixtures/replay/parser-v2.mjs"),
|
||||
join(rightRoot, "parser.mjs"),
|
||||
),
|
||||
]);
|
||||
const authority = await permissionAuthorityForRoot(
|
||||
root,
|
||||
["investigation_input"],
|
||||
["investigation_input"],
|
||||
);
|
||||
const [left, right] = await Promise.all([
|
||||
analyzeJavaScriptApplication(authority, {
|
||||
input_path: leftRoot,
|
||||
approved: true,
|
||||
}),
|
||||
analyzeJavaScriptApplication(authority, {
|
||||
input_path: rightRoot,
|
||||
approved: true,
|
||||
}),
|
||||
]);
|
||||
if (!left.ok) throw left.error;
|
||||
if (!right.ok) throw right.error;
|
||||
const session = new BinarySession(() => ({
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}));
|
||||
const server = createServer(session, session);
|
||||
const client = new Client({ name: "export-shape-test", version: "1" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
const selectors = {
|
||||
left_module_path: "parser.mjs",
|
||||
left_export_name: "default",
|
||||
right_module_path: "parser.mjs",
|
||||
right_export_name: "default",
|
||||
};
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const full = await client.callTool({
|
||||
name: "compare_javascript_export_shapes",
|
||||
arguments: { left: left.value, right: right.value, ...selectors },
|
||||
});
|
||||
expect(full.isError).not.toBe(true);
|
||||
expect(full.structuredContent).toMatchObject({
|
||||
result: {
|
||||
summary: { added: 1, removed: 0, changed: 0, unknown: 0 },
|
||||
changes: [
|
||||
{
|
||||
status: "added",
|
||||
path: "/depth",
|
||||
right: { availability: "literal", value: 1 },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(session.exportEvidenceBundle().records).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
operation: "compare_javascript_export_shapes",
|
||||
predicate_type: "rea.javascript-export-shape-comparison/v1",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
const byId = await client.callTool({
|
||||
name: "compare_javascript_export_shapes",
|
||||
arguments: {
|
||||
left_evidence_id: left.value.evidence_id,
|
||||
right_evidence_id: right.value.evidence_id,
|
||||
...selectors,
|
||||
},
|
||||
});
|
||||
expect(byId.isError).not.toBe(true);
|
||||
expect(byId.structuredContent).toMatchObject({
|
||||
result: {
|
||||
evidence_links: [left.value.evidence_id, right.value.evidence_id],
|
||||
changes: [expect.objectContaining({ path: "/depth" })],
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
await client.close();
|
||||
await server.close();
|
||||
await session.close();
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("traces and compares authenticated graph Evidence in the session", async () => {
|
||||
const session = new BinarySession(() => ({
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
@@ -29,13 +134,20 @@ describe("application workflow MCP parity", () => {
|
||||
});
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
let resourceListChanges = 0;
|
||||
client.setNotificationHandler(
|
||||
"notifications/resources/list_changed",
|
||||
() => {
|
||||
resourceListChanges += 1;
|
||||
},
|
||||
);
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
|
||||
const traced = await client.callTool({
|
||||
name: "trace_application_feature",
|
||||
arguments: JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
|
||||
arguments: JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE,
|
||||
});
|
||||
expect(traced.isError).not.toBe(true);
|
||||
expect(traced.structuredContent).toMatchObject({
|
||||
@@ -48,7 +160,7 @@ describe("application workflow MCP parity", () => {
|
||||
const compared = await client.callTool({
|
||||
name: "compare_application_versions",
|
||||
arguments: {
|
||||
...JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
|
||||
...JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE,
|
||||
unknown_registry_approved: true,
|
||||
},
|
||||
});
|
||||
@@ -62,12 +174,112 @@ describe("application workflow MCP parity", () => {
|
||||
});
|
||||
expect(session.exportEvidenceBundle().records.length).toBeGreaterThan(2);
|
||||
|
||||
const spoofed = await client.callTool({
|
||||
await new Promise<void>((resolve) => setImmediate(resolve));
|
||||
const notificationsBeforeIdReuse = resourceListChanges;
|
||||
const tracedById = await client.callTool({
|
||||
name: "trace_application_feature",
|
||||
arguments: {
|
||||
...JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
|
||||
application_evidence_id:
|
||||
JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE.application
|
||||
.evidence_id,
|
||||
},
|
||||
});
|
||||
expect(tracedById.isError).not.toBe(true);
|
||||
await new Promise<void>((resolve) => setImmediate(resolve));
|
||||
expect(resourceListChanges).toBe(notificationsBeforeIdReuse);
|
||||
|
||||
const comparedById = await client.callTool({
|
||||
name: "compare_application_versions",
|
||||
arguments: {
|
||||
...JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
|
||||
left_evidence_id:
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left
|
||||
.evidence_id,
|
||||
right_evidence_id:
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.right
|
||||
.evidence_id,
|
||||
},
|
||||
});
|
||||
expect(comparedById).toMatchObject({
|
||||
structuredContent: {
|
||||
result: {
|
||||
evidence_links: expect.arrayContaining([
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left
|
||||
.evidence_id,
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.right
|
||||
.evidence_id,
|
||||
]),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const missing = await client.callTool({
|
||||
name: "trace_application_feature",
|
||||
arguments: JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
|
||||
});
|
||||
expect(missing).toMatchObject({
|
||||
isError: true,
|
||||
structuredContent: {
|
||||
error: { details: { reason: "missing" } },
|
||||
},
|
||||
});
|
||||
|
||||
const wrongOperation = createEvidence(
|
||||
undefined,
|
||||
{ id: "fixture", name: "Fixture", version: "1" },
|
||||
{ operation: "inventory_artifact", parameters: {}, result: {} },
|
||||
);
|
||||
const wrongPredicate = createEvidence(
|
||||
undefined,
|
||||
{ id: "fixture", name: "Fixture", version: "1" },
|
||||
{
|
||||
predicateType: "fixture.application/v1",
|
||||
operation: "analyze_javascript_application",
|
||||
parameters: {},
|
||||
result: {},
|
||||
},
|
||||
);
|
||||
expect(session.recordEvidence(wrongOperation).ok).toBe(true);
|
||||
expect(session.recordEvidence(wrongPredicate).ok).toBe(true);
|
||||
for (const [record, reason] of [
|
||||
[wrongOperation, "wrong_operation"],
|
||||
[wrongPredicate, "wrong_predicate"],
|
||||
] as const) {
|
||||
const rejected = await client.callTool({
|
||||
name: "trace_application_feature",
|
||||
arguments: {
|
||||
...JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
|
||||
application_evidence_id: record.evidence_id,
|
||||
},
|
||||
});
|
||||
expect(rejected).toMatchObject({
|
||||
isError: true,
|
||||
structuredContent: { error: { details: { reason } } },
|
||||
});
|
||||
}
|
||||
|
||||
const duplicateNative = await client.callTool({
|
||||
name: "trace_application_feature",
|
||||
arguments: {
|
||||
...JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE,
|
||||
native_observations: [
|
||||
JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE.application,
|
||||
],
|
||||
native_observation_evidence_ids: [
|
||||
JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE.application
|
||||
.evidence_id,
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(duplicateNative.isError).toBe(true);
|
||||
|
||||
const spoofed = await client.callTool({
|
||||
name: "trace_application_feature",
|
||||
arguments: {
|
||||
...JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE,
|
||||
application: {
|
||||
...JAVASCRIPT_FEATURE_TRACE_EXAMPLE.application,
|
||||
...JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE.application,
|
||||
provider: { id: "spoofed", name: "spoofed", version: "1" },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { copyFile, mkdir, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { writeVersionedJavaScriptApplicationFixtures } from "./fixtures/javascriptArtifactApplication.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
@@ -22,7 +23,7 @@ describe("local application workflow verifier", () => {
|
||||
});
|
||||
|
||||
it("reports bounded two-version and trace claims without source text", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-application-verifier-"));
|
||||
const root = await createTestTempDirectory("rea-application-verifier-");
|
||||
temporary.push(root);
|
||||
const fixtures = await writeVersionedJavaScriptApplicationFixtures(root);
|
||||
const { stdout } = await execute(
|
||||
@@ -58,4 +59,57 @@ describe("local application workflow verifier", () => {
|
||||
});
|
||||
expect(stdout).not.toContain("stableValue");
|
||||
}, 20_000);
|
||||
|
||||
it("verifies the source-owned parser depth return-shape addition", async () => {
|
||||
const root = await createTestTempDirectory("rea-shape-verifier-");
|
||||
temporary.push(root);
|
||||
const left = join(root, "left");
|
||||
const right = join(root, "right");
|
||||
await Promise.all([mkdir(left), mkdir(right)]);
|
||||
await Promise.all([
|
||||
copyFile(
|
||||
join(process.cwd(), "tests/fixtures/replay/parser.mjs"),
|
||||
join(left, "parser.mjs"),
|
||||
),
|
||||
copyFile(
|
||||
join(process.cwd(), "tests/fixtures/replay/parser-v2.mjs"),
|
||||
join(right, "parser.mjs"),
|
||||
),
|
||||
]);
|
||||
const { stdout } = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
"scripts/verify-local-application-workflows.mjs",
|
||||
"--left",
|
||||
left,
|
||||
"--right",
|
||||
right,
|
||||
"--left-module-path",
|
||||
"parser.mjs",
|
||||
"--left-export-name",
|
||||
"default",
|
||||
"--right-module-path",
|
||||
"parser.mjs",
|
||||
"--right-export-name",
|
||||
"default",
|
||||
],
|
||||
{ cwd: process.cwd(), maxBuffer: 16 * 1_024 * 1_024 },
|
||||
);
|
||||
const result = JSON.parse(stdout);
|
||||
expect(result.export_shape_comparison).toMatchObject({
|
||||
summary: { added: 1, removed: 0, changed: 0, unknown: 0 },
|
||||
changes: [
|
||||
{
|
||||
status: "added",
|
||||
path: "/depth",
|
||||
right: { availability: "literal", value: 1 },
|
||||
},
|
||||
],
|
||||
runtime_validation: {
|
||||
recommended_tool: "run_controlled_replay",
|
||||
automatically_started: false,
|
||||
},
|
||||
});
|
||||
expect(stdout).not.toContain("value.slice");
|
||||
}, 20_000);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, mkdir, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { inventoryArtifact } from "../src/application/ArtifactInventory.js";
|
||||
import {
|
||||
artifactComparisonResultSchema,
|
||||
@@ -62,7 +63,7 @@ const observe = async (
|
||||
|
||||
describe("artifact comparison", () => {
|
||||
it("classifies deterministic path changes and cites both inventories", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-artifact-compare-"));
|
||||
const parent = await createTestTempDirectory("rea-artifact-compare-");
|
||||
const leftPath = join(parent, "left.app");
|
||||
const rightPath = join(parent, "right.app");
|
||||
await Promise.all([mkdir(leftPath), mkdir(rightPath)]);
|
||||
@@ -104,7 +105,7 @@ describe("artifact comparison", () => {
|
||||
});
|
||||
|
||||
it("reports incomplete inventory as truncated, never unchanged", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-artifact-truncated-"));
|
||||
const root = await createTestTempDirectory("rea-artifact-truncated-");
|
||||
await writeFile(join(root, "one.txt"), "one");
|
||||
const incomplete = await observe(root, { nodeLimit: 1 });
|
||||
const comparison = compareArtifacts(incomplete, incomplete, 0, 100);
|
||||
@@ -118,7 +119,7 @@ describe("artifact comparison", () => {
|
||||
});
|
||||
|
||||
it("assembles bounded page sets for graphs larger than one page", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-artifact-pages-"));
|
||||
const root = await createTestTempDirectory("rea-artifact-pages-");
|
||||
await Promise.all(
|
||||
Array.from({ length: 501 }, async (_, index) =>
|
||||
writeFile(
|
||||
@@ -143,7 +144,7 @@ describe("artifact comparison", () => {
|
||||
}, 15_000);
|
||||
|
||||
it("rejects non-inventory and tampered Evidence", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-artifact-invalid-"));
|
||||
const root = await createTestTempDirectory("rea-artifact-invalid-");
|
||||
const evidence = await observe(root);
|
||||
expect(() =>
|
||||
compareArtifacts(
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
paginateArtifactInventory,
|
||||
scanArtifactInventory,
|
||||
@@ -20,7 +21,7 @@ const LIMITS = {
|
||||
|
||||
describe("artifact inventory snapshot", () => {
|
||||
it("projects every page from the same completed scan", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-inventory-snapshot-"));
|
||||
const root = await createTestTempDirectory("rea-inventory-snapshot-");
|
||||
await writeFile(join(root, "a.txt"), "a");
|
||||
await writeFile(join(root, "b.txt"), "b");
|
||||
const snapshot = await scanArtifactInventory(root, LIMITS);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
@@ -8,6 +7,8 @@ import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { ArtifactProvider } from "../src/artifacts/ArtifactProvider.js";
|
||||
import { ARTIFACT_COMPARISON_EXAMPLE } from "../src/contracts/artifactComparisonExample.js";
|
||||
@@ -22,7 +23,7 @@ describe("artifact graph MCP integration", () => {
|
||||
])(
|
||||
"returns actionable local details for an $label ASAR integrity error",
|
||||
async ({ unpacked }) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-asar-integrity-mcp-"));
|
||||
const root = await createTestTempDirectory("rea-asar-integrity-mcp-");
|
||||
const source = join(root, "source");
|
||||
const original = "console.log('ok');\n";
|
||||
const changed = "console.log('no');\n";
|
||||
@@ -94,7 +95,7 @@ describe("artifact graph MCP integration", () => {
|
||||
);
|
||||
|
||||
it("records an approved mismatch, preserves verified siblings, and never reports equivalence", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-asar-continue-mcp-"));
|
||||
const root = await createTestTempDirectory("rea-asar-continue-mcp-");
|
||||
const source = join(root, "source");
|
||||
await mkdir(source);
|
||||
const original = "console.log('ok');\n";
|
||||
@@ -300,7 +301,7 @@ describe("artifact graph MCP integration", () => {
|
||||
});
|
||||
|
||||
it("opens archives without Hopper, compares them, and exports linked evidence", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-artifact-mcp-"));
|
||||
const directory = await createTestTempDirectory("rea-artifact-mcp-");
|
||||
const archive = join(directory, "fixture.ipa");
|
||||
const changedArchive = join(directory, "changed.ipa");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import {
|
||||
access,
|
||||
mkdtemp,
|
||||
mkdir,
|
||||
readFile,
|
||||
readdir,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { createPackage, createPackageWithOptions } from "@electron/asar";
|
||||
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { ArtifactProvider } from "../src/artifacts/ArtifactProvider.js";
|
||||
import { MachOSliceArtifactReader } from "../src/artifacts/MachOSliceArtifactReader.js";
|
||||
import { runProviderAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
@@ -37,7 +37,7 @@ import {
|
||||
|
||||
describe("artifact graph provider", () => {
|
||||
it("inventories app trees deterministically without following symlinks", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-artifacts-"));
|
||||
const root = await createTestTempDirectory("rea-artifacts-");
|
||||
const app = join(root, "Fixture.app");
|
||||
await mkdir(join(app, "Contents", "Resources"), { recursive: true });
|
||||
await mkdir(join(app, "Contents", "MacOS"), { recursive: true });
|
||||
@@ -102,7 +102,7 @@ describe("artifact graph provider", () => {
|
||||
});
|
||||
|
||||
it("streams ZIP and official ASAR inventories within shared limits", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-containers-"));
|
||||
const root = await createTestTempDirectory("rea-containers-");
|
||||
const zipPath = join(root, "fixture.apk");
|
||||
const zipWriter = new ZipWriter(new Uint8ArrayWriter());
|
||||
await zipWriter.add("assets/index.js", new TextReader("export default 1;"));
|
||||
@@ -187,7 +187,7 @@ describe("artifact graph provider", () => {
|
||||
registry.add("A.js", "file");
|
||||
expect(() => registry.add("a.js", "file")).toThrow(/collision/u);
|
||||
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-bomb-"));
|
||||
const root = await createTestTempDirectory("rea-bomb-");
|
||||
const zipPath = join(root, "bomb.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("zeros", new TextReader("0".repeat(100_000)));
|
||||
@@ -204,7 +204,7 @@ describe("artifact graph provider", () => {
|
||||
});
|
||||
|
||||
it("extracts only selected occurrences through an exclusively owned output tree", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-extract-"));
|
||||
const root = await createTestTempDirectory("rea-extract-");
|
||||
const source = join(root, "source");
|
||||
await mkdir(join(source, "assets"), { recursive: true });
|
||||
await writeFile(join(source, "assets", "selected.js"), "selected();\n");
|
||||
@@ -302,7 +302,7 @@ describe("artifact graph provider", () => {
|
||||
});
|
||||
|
||||
it("paginates wide graphs without changing manifest identity", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-wide-"));
|
||||
const root = await createTestTempDirectory("rea-wide-");
|
||||
await Promise.all(
|
||||
Array.from({ length: 520 }, async (_, index) =>
|
||||
writeFile(
|
||||
@@ -340,7 +340,7 @@ describe("artifact graph provider", () => {
|
||||
}, 15_000);
|
||||
|
||||
it("uses bounded native lipo metadata for universal slice ranges", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-slices-"));
|
||||
const root = await createTestTempDirectory("rea-slices-");
|
||||
const binary = join(root, "fat");
|
||||
await writeFile(binary, Buffer.from("0123456789abcdef"));
|
||||
const runner: NativeCommandRunner = {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { scanAuthorizedArtifactInventory } from "../src/application/AuthorizedArtifactInventory.js";
|
||||
|
||||
const LIMITS = {
|
||||
@@ -17,7 +18,7 @@ const LIMITS = {
|
||||
|
||||
describe("authorized artifact inventory", () => {
|
||||
it("uses a valid input root when another configured root is missing", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-artifact-roots-"));
|
||||
const root = await createTestTempDirectory("rea-artifact-roots-");
|
||||
try {
|
||||
const path = join(root, "artifact.js");
|
||||
await writeFile(path, "export const value = 1;\n");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import type { AnalysisClient } from "../src/application/AnalysisProvider.js";
|
||||
import type {
|
||||
@@ -421,7 +422,7 @@ describe("binary session", () => {
|
||||
});
|
||||
|
||||
it("keeps the active client when a switch fails", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "bb-session-"));
|
||||
directory = await createTestTempDirectory("bb-session-");
|
||||
const first = join(directory, "first.hop");
|
||||
const second = join(directory, "second.hop");
|
||||
await writeFile(first, "one");
|
||||
@@ -458,7 +459,7 @@ describe("binary session", () => {
|
||||
});
|
||||
|
||||
it("replaces the active client when a canonical path changes contents", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "bb-session-"));
|
||||
directory = await createTestTempDirectory("bb-session-");
|
||||
const path = join(directory, "mutable.hop");
|
||||
await writeFile(path, "one");
|
||||
const clients: Array<{
|
||||
@@ -739,7 +740,7 @@ class TestClient implements AnalysisClient {
|
||||
}
|
||||
|
||||
const targets = async (): Promise<readonly [string, string]> => {
|
||||
directory ??= await mkdtemp(join(tmpdir(), "bb-session-"));
|
||||
directory ??= await createTestTempDirectory("bb-session-");
|
||||
const first = join(directory, "first.hop");
|
||||
const second = join(directory, "second.hop");
|
||||
await writeFile(first, "one");
|
||||
|
||||
+12
-18
@@ -1,15 +1,9 @@
|
||||
import {
|
||||
mkdir,
|
||||
mkdtemp,
|
||||
realpath,
|
||||
rm,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, realpath, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
parseBinaryTarget,
|
||||
parseExecutableHeader,
|
||||
@@ -102,7 +96,7 @@ describe("executable header parsing", () => {
|
||||
|
||||
describe("binary target I/O", () => {
|
||||
it("classifies ZIP profiles and text artifacts without Hopper", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-artifact-target-"));
|
||||
const directory = await createTestTempDirectory("rea-artifact-target-");
|
||||
const zip = join(directory, "fixture.apk");
|
||||
const script = join(directory, "bundle.js");
|
||||
await writeFile(zip, Buffer.from([0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0]));
|
||||
@@ -120,7 +114,7 @@ describe("binary target I/O", () => {
|
||||
});
|
||||
|
||||
it("does not trust a ZIP-family extension without ZIP magic", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-fake-archive-"));
|
||||
const directory = await createTestTempDirectory("rea-fake-archive-");
|
||||
const path = join(directory, "fake.zip");
|
||||
await writeFile(path, "not a zip");
|
||||
const result = await parseBinaryTarget(path);
|
||||
@@ -131,7 +125,7 @@ describe("binary target I/O", () => {
|
||||
});
|
||||
|
||||
it("resolves relative Hopper databases and rejects unknown or unreadable paths", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-target-"));
|
||||
directory = await createTestTempDirectory("rea-target-");
|
||||
await writeFile(join(directory, "sample.hop"), "database");
|
||||
await writeFile(join(directory, "text"), "hello");
|
||||
const database = await parseBinaryTarget("sample.hop", directory);
|
||||
@@ -143,12 +137,12 @@ describe("binary target I/O", () => {
|
||||
});
|
||||
|
||||
it("rejects non-regular targets before reading them", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-target-"));
|
||||
directory = await createTestTempDirectory("rea-target-");
|
||||
expect((await parseBinaryTarget(directory)).ok).toBe(false);
|
||||
});
|
||||
|
||||
it("resolves a macOS app bundle to its declared program file", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-target-"));
|
||||
directory = await createTestTempDirectory("rea-target-");
|
||||
const app = join(directory, "Example App.app");
|
||||
const contents = join(app, "Contents");
|
||||
const programs = join(contents, "MacOS");
|
||||
@@ -180,7 +174,7 @@ describe("binary target I/O", () => {
|
||||
"<plist><dict><key>CFBundleExecutable</key><string>Missing</string></dict></plist>",
|
||||
],
|
||||
])("rejects an app bundle with %s", async (_case, plist) => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-target-"));
|
||||
directory = await createTestTempDirectory("rea-target-");
|
||||
const app = join(directory, "Broken.app");
|
||||
const contents = join(app, "Contents");
|
||||
await mkdir(join(contents, "MacOS"), { recursive: true });
|
||||
@@ -192,7 +186,7 @@ describe("binary target I/O", () => {
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"rejects an app program symlink that leaves the bundle",
|
||||
async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-target-"));
|
||||
directory = await createTestTempDirectory("rea-target-");
|
||||
const app = join(directory, "Escaping.app");
|
||||
const contents = join(app, "Contents");
|
||||
const programs = join(contents, "MacOS");
|
||||
@@ -209,7 +203,7 @@ describe("binary target I/O", () => {
|
||||
);
|
||||
|
||||
it("honors an explicit database kind without relying on the file suffix", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-target-"));
|
||||
directory = await createTestTempDirectory("rea-target-");
|
||||
await writeFile(join(directory, "saved-analysis"), "database");
|
||||
const result = await parseBinaryTarget(
|
||||
"saved-analysis",
|
||||
@@ -224,7 +218,7 @@ describe("binary target I/O", () => {
|
||||
});
|
||||
|
||||
it("reads a PE header beyond the initial probe", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-target-"));
|
||||
directory = await createTestTempDirectory("rea-target-");
|
||||
const path = join(directory, "delayed.exe");
|
||||
await writeFile(path, pe(0x8664, 8192));
|
||||
const result = await parseBinaryTarget(path, directory, "x64");
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { access, chmod, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { access, chmod, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
type HopperApplicationLauncherOptions,
|
||||
linuxDemoLaunch,
|
||||
usesLinuxDemo,
|
||||
} from "../src/hopper/BridgeLauncher.js";
|
||||
|
||||
@@ -52,8 +54,77 @@ describe("Hopper bridge launcher selection", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("builds the namespace launch without sudo or a shell command", () => {
|
||||
const launch = linuxDemoLaunch(
|
||||
options("/opt/hopper/bin/Hopper"),
|
||||
{
|
||||
directory: "/tmp/rea-fixture",
|
||||
socketPath: "/tmp/rea-fixture/bridge.sock",
|
||||
token: "not-forwarded",
|
||||
runId: "fixture-run",
|
||||
},
|
||||
["--analysis"],
|
||||
"user-mount-namespace",
|
||||
);
|
||||
|
||||
expect(launch).toMatchObject({
|
||||
command: "/usr/bin/unshare",
|
||||
ownershipCommand: "/usr/bin/python3",
|
||||
args: [
|
||||
"--user",
|
||||
"--map-root-user",
|
||||
"--mount",
|
||||
"--propagation",
|
||||
"private",
|
||||
"/usr/bin/python3",
|
||||
"/rea/hopper-demo-x11.py",
|
||||
"--strategy",
|
||||
"user-mount-namespace",
|
||||
"--mount-private-x11",
|
||||
"--hopper",
|
||||
"/opt/hopper/bin/Hopper",
|
||||
"--socket",
|
||||
"/tmp/rea-fixture/bridge.sock",
|
||||
"--",
|
||||
"/opt/hopper/bin/Hopper",
|
||||
"--analysis",
|
||||
],
|
||||
});
|
||||
expect(launch?.args).not.toContain("sudo");
|
||||
expect(launch?.args).not.toContain("-c");
|
||||
});
|
||||
|
||||
it("keeps an ordinary Linux launch on the direct Python adapter", () => {
|
||||
expect(
|
||||
linuxDemoLaunch(
|
||||
options("/opt/hopper/bin/Hopper"),
|
||||
{
|
||||
directory: "/tmp/rea-fixture",
|
||||
socketPath: "/tmp/rea-fixture/bridge.sock",
|
||||
token: "not-forwarded",
|
||||
runId: "fixture-run",
|
||||
},
|
||||
[],
|
||||
"direct",
|
||||
),
|
||||
).toMatchObject({
|
||||
command: "/usr/bin/python3",
|
||||
args: [
|
||||
"/rea/hopper-demo-x11.py",
|
||||
"--strategy",
|
||||
"direct",
|
||||
"--hopper",
|
||||
"/opt/hopper/bin/Hopper",
|
||||
"--socket",
|
||||
"/tmp/rea-fixture/bridge.sock",
|
||||
"--",
|
||||
"/opt/hopper/bin/Hopper",
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects an unpinned wrapper before executing it", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-hopper-wrapper-"));
|
||||
const directory = await createTestTempDirectory("rea-hopper-wrapper-");
|
||||
const wrapper = join(directory, "hopper-wrapper");
|
||||
const marker = join(directory, "executed");
|
||||
try {
|
||||
@@ -75,7 +146,9 @@ describe("Hopper bridge launcher selection", () => {
|
||||
),
|
||||
).rejects.toMatchObject({
|
||||
code: 72,
|
||||
stderr: expect.stringContaining("unsupported Hopper binary"),
|
||||
stderr: expect.stringContaining(
|
||||
'"failure_code":"unsupported_hopper_build"',
|
||||
),
|
||||
});
|
||||
await expect(access(marker)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
} finally {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
BrowserStartupError,
|
||||
waitForBrowserDevtoolsPort,
|
||||
@@ -94,7 +95,7 @@ describe("browser process startup", () => {
|
||||
});
|
||||
|
||||
const temporaryRoot = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-browser-startup-"));
|
||||
const root = await createTestTempDirectory("rea-browser-startup-");
|
||||
roots.push(root);
|
||||
return root;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
import {
|
||||
@@ -36,7 +37,7 @@ const sourceEvidence = (label: string) =>
|
||||
|
||||
describe("bundle comparison MCP integration", () => {
|
||||
it("reads two approved bounded bundle files and records a compact result", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-bundle-mcp-"));
|
||||
const root = await createTestTempDirectory("rea-bundle-mcp-");
|
||||
roots.push(root);
|
||||
const leftPath = join(root, "left.json");
|
||||
const rightPath = join(root, "right.json");
|
||||
@@ -79,8 +80,8 @@ describe("bundle comparison MCP integration", () => {
|
||||
});
|
||||
|
||||
it("rejects a bundle path outside the approved root", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-bundle-root-"));
|
||||
const outside = await mkdtemp(join(tmpdir(), "rea-bundle-outside-"));
|
||||
const root = await createTestTempDirectory("rea-bundle-root-");
|
||||
const outside = await createTestTempDirectory("rea-bundle-outside-");
|
||||
roots.push(root, outside);
|
||||
const leftPath = join(root, "left.json");
|
||||
const rightPath = join(outside, "right.json");
|
||||
@@ -108,7 +109,7 @@ describe("bundle comparison MCP integration", () => {
|
||||
});
|
||||
|
||||
it("rejects an oversized approved bundle", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-bundle-size-"));
|
||||
const root = await createTestTempDirectory("rea-bundle-size-");
|
||||
roots.push(root);
|
||||
const leftPath = join(root, "left.json");
|
||||
const rightPath = join(root, "right.json");
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { CdpElectronProvider } from "../src/browser/CdpElectronProvider.js";
|
||||
import {
|
||||
inspectElectronPageInputSchema,
|
||||
@@ -251,7 +252,7 @@ describe("CdpElectronProvider", () => {
|
||||
});
|
||||
|
||||
const electronFixture = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-electron-provider-"));
|
||||
const root = await createTestTempDirectory("rea-electron-provider-");
|
||||
temporary.push(root);
|
||||
await writeFile(join(root, "index.html"), "<script src='app.js'></script>");
|
||||
await writeFile(join(root, "app.js"), "export const app = true;");
|
||||
|
||||
+66
-4
@@ -1,19 +1,81 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { createPackageWithOptions } from "@electron/asar";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sanitizeCliOutput } from "../src/cliOutput.js";
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
renderCliOutputArgumentError,
|
||||
sanitizeCliOutput,
|
||||
validateCliOutputArguments,
|
||||
} from "../src/cliOutput.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const CLI_INTEGRATION_TIMEOUT_MS = 60_000;
|
||||
const CLI_VARIANT_TIMEOUT_MS = 120_000;
|
||||
|
||||
describe("CLI output boundary", () => {
|
||||
it("rejects token windows that would corrupt structured output", () => {
|
||||
for (const format of ["json", "jsonl", "yaml"] as const) {
|
||||
const validation = validateCliOutputArguments([
|
||||
"providers",
|
||||
"--token-limit",
|
||||
"5",
|
||||
"--format",
|
||||
format,
|
||||
]);
|
||||
expect(validation).toMatchObject({
|
||||
ok: false,
|
||||
format,
|
||||
code: "UNSUPPORTED_OUTPUT_COMBINATION",
|
||||
});
|
||||
if (!validation.ok) {
|
||||
const rendered = renderCliOutputArgumentError(validation);
|
||||
expect(rendered).not.toContain("[truncated:");
|
||||
if (format === "json" || format === "jsonl")
|
||||
expect(JSON.parse(rendered)).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "UNSUPPORTED_OUTPUT_COMBINATION" },
|
||||
});
|
||||
else
|
||||
expect(rendered).toMatch(
|
||||
/^ok: false\nerror:\n code: UNSUPPORTED_OUTPUT_COMBINATION\n/u,
|
||||
);
|
||||
}
|
||||
}
|
||||
expect(
|
||||
validateCliOutputArguments([
|
||||
"providers",
|
||||
"--token-limit",
|
||||
"5",
|
||||
"--format",
|
||||
"toon",
|
||||
]),
|
||||
).toEqual({ ok: true });
|
||||
expect(
|
||||
validateCliOutputArguments(["providers", "--token-count", "--json"]),
|
||||
).toEqual({ ok: true });
|
||||
});
|
||||
|
||||
it("fails before emitting a truncated JSON document", async () => {
|
||||
const execution = execFileAsync(
|
||||
process.execPath,
|
||||
["scripts/rea.mjs", "providers", "--token-limit", "5", "--json"],
|
||||
{ cwd: process.cwd() },
|
||||
);
|
||||
const failure = await execution.catch((cause: unknown) => cause);
|
||||
expect(failure).toMatchObject({ code: 1 });
|
||||
const { stdout } = failure as { readonly stdout: string };
|
||||
expect(JSON.parse(stdout)).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "UNSUPPORTED_OUTPUT_COMBINATION" },
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves normal output and sanitizes text and JSON validation errors", () => {
|
||||
expect(sanitizeCliOutput("result: ok\n")).toBe("result: ok\n");
|
||||
expect(sanitizeCliOutput("result: VALIDATION_ERROR\n")).toBe(
|
||||
@@ -101,7 +163,7 @@ describe("CLI output boundary", () => {
|
||||
it(
|
||||
"preserves artifact diagnostics in ordinary and full JSON output",
|
||||
async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-cli-diagnostics-"));
|
||||
const root = await createTestTempDirectory("rea-cli-diagnostics-");
|
||||
const source = join(root, "source");
|
||||
await mkdir(source);
|
||||
await writeFile(join(source, "main.js"), "console.log('ok');\n");
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFile, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
readProjectPermissionStore,
|
||||
writeProjectPermissionStore,
|
||||
@@ -71,7 +72,7 @@ describe("policy revocation approval", () => {
|
||||
);
|
||||
|
||||
it("keeps the packaged project store unchanged until --yes is supplied", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-cli-"));
|
||||
const project = await createTestTempDirectory("rea-policy-cli-");
|
||||
roots.push(project);
|
||||
const store = join(project, ".rea", "permissions.json");
|
||||
const grant = {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { spawn } from "@lydell/node-pty";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const decisionMarker = "REA_SETUP_DECISION:";
|
||||
|
||||
@@ -256,7 +256,7 @@ const runJourney = async (
|
||||
accessible = false,
|
||||
journeyActions: readonly object[] = actions,
|
||||
): Promise<JourneyResult> => {
|
||||
const isolatedHome = await mkdtemp(join(tmpdir(), "rea-cli-setup-test-"));
|
||||
const isolatedHome = await createTestTempDirectory("rea-cli-setup-test-");
|
||||
const script = [
|
||||
'import { confirmInteractiveSetup } from "./dist/cliSetup.js";',
|
||||
`const actions = ${JSON.stringify(journeyActions)};`,
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { readClientRegistrationStatuses } from "../src/application/ClientRegistrationStatus.js";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
|
||||
describe("client registration status", () => {
|
||||
it("distinguishes aligned, stale, missing, and invalid registrations", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-registrations-"));
|
||||
const home = await createTestTempDirectory("rea-registrations-");
|
||||
await Promise.all([
|
||||
mkdir(join(home, ".codex")),
|
||||
mkdir(join(home, ".cursor")),
|
||||
@@ -47,7 +48,7 @@ describe("client registration status", () => {
|
||||
});
|
||||
|
||||
it("reports an unversioned npx registration as stale", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-registrations-"));
|
||||
const home = await createTestTempDirectory("rea-registrations-");
|
||||
await mkdir(join(home, ".codex"));
|
||||
await writeFile(
|
||||
join(home, ".codex/config.toml"),
|
||||
|
||||
@@ -160,4 +160,74 @@ describe("Codex agent release evaluation", () => {
|
||||
|
||||
expect(metrics.reaCalls[0]?.error).toBe(true);
|
||||
});
|
||||
|
||||
it("requires an ordered tool subsequence and rejects input validation failures", () => {
|
||||
const evidenceId = `ev_${"b".repeat(64)}`;
|
||||
const call = (
|
||||
id: string,
|
||||
tool: string,
|
||||
result: unknown = { evidence_id: evidenceId },
|
||||
) => ({
|
||||
type: "item.completed",
|
||||
item: {
|
||||
id,
|
||||
type: "mcp_tool_call",
|
||||
server: "rea",
|
||||
tool,
|
||||
arguments: { id },
|
||||
result,
|
||||
},
|
||||
});
|
||||
const final = {
|
||||
type: "item.completed",
|
||||
item: {
|
||||
type: "agent_message",
|
||||
text: `Static inferred evidence ${evidenceId} shows depth: 1; runtime behavior remains unknown without controlled replay authority.`,
|
||||
},
|
||||
};
|
||||
const options = {
|
||||
requireEvidence: true,
|
||||
requiredToolSubsequence: [
|
||||
"analyze_javascript_application",
|
||||
"analyze_javascript_application",
|
||||
"compare_javascript_export_shapes",
|
||||
],
|
||||
forbidInputValidationFailures: true,
|
||||
};
|
||||
const valid = evaluateCodexEvents(
|
||||
[
|
||||
call("left", "analyze_javascript_application"),
|
||||
call("right", "analyze_javascript_application"),
|
||||
call("compare", "compare_javascript_export_shapes"),
|
||||
final,
|
||||
],
|
||||
"analyze_javascript_application",
|
||||
options,
|
||||
);
|
||||
expect(valid).toMatchObject({
|
||||
requiredToolSubsequenceMet: true,
|
||||
inputValidationFailureCount: 0,
|
||||
completionQuality: true,
|
||||
});
|
||||
|
||||
const invalid = evaluateCodexEvents(
|
||||
[
|
||||
call("left", "analyze_javascript_application"),
|
||||
call("bad", "compare_javascript_export_shapes", {
|
||||
structured_content: {
|
||||
error: { code: "invalid_request" },
|
||||
},
|
||||
isError: true,
|
||||
}),
|
||||
final,
|
||||
],
|
||||
"analyze_javascript_application",
|
||||
options,
|
||||
);
|
||||
expect(invalid).toMatchObject({
|
||||
requiredToolSubsequenceMet: false,
|
||||
inputValidationFailureCount: 1,
|
||||
completionQuality: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# Source-built conformance fixtures
|
||||
|
||||
These sources are deliberately small semantic oracles for REA providers. Run
|
||||
`npm run verify:fixtures` on macOS to compile them into the ignored
|
||||
`npm run verify:fixtures` on macOS or Linux to compile them into the ignored
|
||||
`build/conformance/` directory, emit a hash-and-toolchain manifest, and verify
|
||||
their Mach-O symbols and strings with native command-line tools.
|
||||
their platform-native symbols and strings with local command-line tools. The
|
||||
portable C, version, and pagination fixtures build as Mach-O on macOS and ELF on
|
||||
Linux; Objective-C, Swift, and N-API-like fixtures remain macOS-only.
|
||||
|
||||
Only source files are versioned. Generated binaries, generated large-fixture
|
||||
source, debug information, and manifests must remain under `build/`.
|
||||
|
||||
@@ -97,7 +97,7 @@ describe("tool contract surface", () => {
|
||||
...ELECTRON_TOOL_CONTRACTS,
|
||||
...APPLICATION_TOOL_CONTRACTS,
|
||||
];
|
||||
expect(contracts).toHaveLength(77);
|
||||
expect(contracts).toHaveLength(78);
|
||||
for (const contract of contracts) {
|
||||
const inputSchema = contractJsonSchema(contract.inputSchema);
|
||||
const outputSchema = contractJsonSchema(contract.outputSchema);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { scanArtifactInventory } from "../src/application/ArtifactInventory.js";
|
||||
import {
|
||||
scanVersionInventories,
|
||||
@@ -38,7 +39,7 @@ const deferred = <Value>() => {
|
||||
|
||||
describe("cross-version inventory", () => {
|
||||
it("starts both scans together and preserves left/right result order", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-version-inventory-"));
|
||||
const root = await createTestTempDirectory("rea-version-inventory-");
|
||||
try {
|
||||
const artifact = join(root, "artifact.js");
|
||||
await writeFile(artifact, "export const value = 1;\n");
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { copyFile, mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
const roots: string[] = [];
|
||||
const script = join(process.cwd(), "scripts", "check-dependency-install.mjs");
|
||||
|
||||
@@ -18,7 +19,7 @@ const fixture = async (
|
||||
installedVersion?: string,
|
||||
omitDevDependency = false,
|
||||
) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-deps-"));
|
||||
const root = await createTestTempDirectory("rea-deps-");
|
||||
roots.push(root);
|
||||
await mkdir(join(root, "node_modules"));
|
||||
await writeFile(
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { chmod, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { chmod, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { writeAnalysisSnapshot } from "../src/application/AnalysisSnapshotFiles.js";
|
||||
import { runDirectAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import type { AnalysisSnapshot } from "../src/domain/analysisSnapshot.js";
|
||||
@@ -33,7 +34,7 @@ afterEach(async () => {
|
||||
|
||||
describe("direct analysis snapshot permissions", () => {
|
||||
it("forwards the CLI provider selector ahead of the environment preference", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-direct-provider-"));
|
||||
directory = await createTestTempDirectory("rea-direct-provider-");
|
||||
const targetPath = join(directory, "fixture.hop");
|
||||
await writeFile(targetPath, "fixture");
|
||||
vi.stubEnv("HOPPER_LAUNCHER_PATH", process.execPath);
|
||||
@@ -60,7 +61,7 @@ describe("direct analysis snapshot permissions", () => {
|
||||
});
|
||||
|
||||
it("replays a cache hit with snapshot read authority only", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-direct-snapshot-"));
|
||||
directory = await createTestTempDirectory("rea-direct-snapshot-");
|
||||
const snapshotPath = join(directory, "analysis.json");
|
||||
const launcherPath = join(directory, "hopper-launcher");
|
||||
await writeFile(launcherPath, "fixture Hopper launcher");
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { copyFile, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
let fixtureRoot: string | undefined;
|
||||
|
||||
@@ -18,7 +19,7 @@ afterEach(async () => {
|
||||
|
||||
describe("executable dispatcher", () => {
|
||||
it("reserves production MCP routing for bare mode arguments", async () => {
|
||||
fixtureRoot = await mkdtemp(join(tmpdir(), "rea-dispatcher-"));
|
||||
fixtureRoot = await createTestTempDirectory("rea-dispatcher-");
|
||||
const scripts = join(fixtureRoot, "scripts");
|
||||
const dist = join(fixtureRoot, "dist");
|
||||
await Promise.all([mkdir(scripts), mkdir(dist)]);
|
||||
@@ -38,7 +39,11 @@ describe("executable dispatcher", () => {
|
||||
),
|
||||
writeFile(
|
||||
join(dist, "cliOutput.js"),
|
||||
"export const sanitizeCliOutput = (output) => output;\n",
|
||||
"export const sanitizeCliOutput = (output) => output; export const validateCliOutputArguments = () => ({ ok: true }); export const renderCliOutputArgumentError = () => '';\n",
|
||||
),
|
||||
writeFile(
|
||||
join(dist, "mcpDoctor.js"),
|
||||
'export const runProductionMcpDoctorCli = (args) => Promise.resolve({ output: JSON.stringify({ adapter: "mcp-doctor", args }), exitCode: 0 });\n',
|
||||
),
|
||||
]);
|
||||
|
||||
@@ -52,6 +57,10 @@ describe("executable dispatcher", () => {
|
||||
|
||||
await expect(invoke(["mcp"])).resolves.toEqual({ adapter: "mcp" });
|
||||
await expect(invoke(["--mcp"])).resolves.toEqual({ adapter: "mcp" });
|
||||
await expect(invoke(["mcp", "doctor", "--json"])).resolves.toEqual({
|
||||
adapter: "mcp-doctor",
|
||||
args: ["--json"],
|
||||
});
|
||||
await expect(invoke(["mcp", "add"])).resolves.toEqual({
|
||||
adapter: "cli",
|
||||
args: ["mcp", "add"],
|
||||
@@ -63,7 +72,7 @@ describe("executable dispatcher", () => {
|
||||
});
|
||||
|
||||
it("explains how to restore a missing compiled runtime", async () => {
|
||||
fixtureRoot = await mkdtemp(join(tmpdir(), "rea-dispatcher-"));
|
||||
fixtureRoot = await createTestTempDirectory("rea-dispatcher-");
|
||||
const scripts = join(fixtureRoot, "scripts");
|
||||
await mkdir(scripts);
|
||||
await Promise.all([
|
||||
@@ -74,7 +83,7 @@ describe("executable dispatcher", () => {
|
||||
),
|
||||
]);
|
||||
|
||||
for (const args of [["mcp"], ["--help"]]) {
|
||||
for (const args of [["mcp"], ["mcp", "doctor"], ["--help"]]) {
|
||||
const execution = execFileAsync(process.execPath, [
|
||||
join(scripts, "rea.mjs"),
|
||||
...args,
|
||||
|
||||
+93
-2
@@ -12,7 +12,12 @@ const host = (overrides: Partial<DoctorHost> = {}): DoctorHost => ({
|
||||
validTarget: (path) => Promise.resolve(path.includes("Hopper")),
|
||||
executable: (path) => Promise.resolve(path.includes("Hopper")),
|
||||
supportedLinuxHopper: () => Promise.resolve(true),
|
||||
linuxDemoRuntimeReady: () => Promise.resolve(true),
|
||||
linuxDemoRuntimeCheck: () =>
|
||||
Promise.resolve({
|
||||
name: "hopper-demo-runtime",
|
||||
ok: true,
|
||||
classification: "healthy",
|
||||
}),
|
||||
brewHopperPath: () => Promise.resolve(undefined),
|
||||
manualHopperPaths: () => Promise.resolve([]),
|
||||
installedSkillIdentity: () =>
|
||||
@@ -237,6 +242,86 @@ describe("doctor", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("scopes effective readiness to selected clients without hiding drift", async () => {
|
||||
const registrations = [
|
||||
{
|
||||
client: "codex",
|
||||
config_path: "/home/user/.codex/config.toml",
|
||||
command: ["/current/rea", "mcp"],
|
||||
state: "aligned" as const,
|
||||
remediation: null,
|
||||
},
|
||||
{
|
||||
client: "cursor",
|
||||
config_path: "/home/user/.cursor/mcp.json",
|
||||
command: ["/old/rea", "mcp"],
|
||||
state: "stale" as const,
|
||||
remediation: "Run rea setup to refresh this registration.",
|
||||
},
|
||||
];
|
||||
const scoped = await runDoctor(
|
||||
undefined,
|
||||
host({ clientRegistrations: () => Promise.resolve(registrations) }),
|
||||
{ clients: ["codex"] },
|
||||
);
|
||||
|
||||
expect(scoped).toMatchObject({
|
||||
healthy: true,
|
||||
environment_healthy: false,
|
||||
scope: { mode: "explicit", clients: ["codex"] },
|
||||
});
|
||||
expect(scoped.scope_checks).toContainEqual(
|
||||
expect.objectContaining({ name: "registration:codex", ok: true }),
|
||||
);
|
||||
expect(scoped.informational_checks).toContainEqual(
|
||||
expect.objectContaining({ name: "registration:cursor", ok: false }),
|
||||
);
|
||||
|
||||
const staleSelected = await runDoctor(
|
||||
undefined,
|
||||
host({ clientRegistrations: () => Promise.resolve(registrations) }),
|
||||
{ clients: ["cursor"] },
|
||||
);
|
||||
expect(staleSelected.healthy).toBe(false);
|
||||
});
|
||||
|
||||
it("requires explicitly selected providers instead of any available provider", async () => {
|
||||
const ghidra = {
|
||||
id: "ghidra",
|
||||
configured: true,
|
||||
available: true,
|
||||
providerVersion: "12.1.2",
|
||||
registrationEnvironment: { GHIDRA_INSTALL_DIR: "/tools/ghidra" },
|
||||
checks: [
|
||||
{
|
||||
name: "configuration",
|
||||
ok: true,
|
||||
code: null,
|
||||
detail: "/tools/ghidra",
|
||||
remediation: null,
|
||||
classification: "config_drift" as const,
|
||||
},
|
||||
],
|
||||
};
|
||||
const noHopper = host({
|
||||
executable: () => Promise.resolve(false),
|
||||
providerInspections: () => Promise.resolve([ghidra]),
|
||||
});
|
||||
|
||||
const hopper = await runDoctor(undefined, noHopper, {
|
||||
providers: ["hopper"],
|
||||
});
|
||||
expect(hopper).toMatchObject({
|
||||
healthy: false,
|
||||
environment_healthy: true,
|
||||
});
|
||||
|
||||
const selectedGhidra = await runDoctor(undefined, noHopper, {
|
||||
providers: ["ghidra"],
|
||||
});
|
||||
expect(selectedGhidra.healthy).toBe(true);
|
||||
});
|
||||
it("accepts an officially supported Linux distribution", async () => {
|
||||
const path = "/home/user/.local/share/rea/hopper/bin/Hopper";
|
||||
const result = await runDoctor(
|
||||
@@ -271,7 +356,13 @@ describe("doctor", () => {
|
||||
packageFamily: "deb",
|
||||
supported: true,
|
||||
}),
|
||||
linuxDemoRuntimeReady: () => Promise.resolve(false),
|
||||
linuxDemoRuntimeCheck: () =>
|
||||
Promise.resolve({
|
||||
name: "hopper-demo-runtime",
|
||||
ok: false,
|
||||
classification: "missing_dependency",
|
||||
remediation: "Install Xvfb, xauth, Python 3, libX11, and libXtst.",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(result.healthy).toBe(false);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { mkdtemp } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../src/application/JavaScriptApplicationService.js";
|
||||
import { PermissionAuthority } from "../src/application/PermissionAuthority.js";
|
||||
import { reconstructJavaScriptArtifact } from "../src/application/JavaScriptArtifactReconstruction.js";
|
||||
@@ -295,7 +295,7 @@ describe("static Electron application analysis", () => {
|
||||
});
|
||||
|
||||
const fixtureDirectory = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-electron-boundaries-"));
|
||||
const root = await createTestTempDirectory("rea-electron-boundaries-");
|
||||
await writeElectronBoundaryFixture(root);
|
||||
return root;
|
||||
};
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
startFakeCdpBrowser,
|
||||
type FakeCdpBrowser,
|
||||
@@ -35,7 +36,7 @@ describe("Electron CLI parity", () => {
|
||||
it(
|
||||
"returns the same root-confined Electron Evidence contracts",
|
||||
async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-electron-cli-"));
|
||||
const root = await createTestTempDirectory("rea-electron-cli-");
|
||||
temporary.push(root);
|
||||
await writeFile(
|
||||
join(root, "index.html"),
|
||||
@@ -88,7 +89,7 @@ describe("Electron CLI parity", () => {
|
||||
it(
|
||||
"returns the static JavaScript application Evidence contract",
|
||||
async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-electron-static-cli-"));
|
||||
const root = await createTestTempDirectory("rea-electron-static-cli-");
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
const environment = {
|
||||
@@ -117,10 +118,42 @@ describe("Electron CLI parity", () => {
|
||||
INTEGRATION_TEST_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"keeps artifact format separate from structured output format",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-format-cli-");
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
const environment = {
|
||||
...process.env,
|
||||
REA_INVESTIGATION_INPUT_ROOTS_JSON: JSON.stringify([root]),
|
||||
};
|
||||
|
||||
const analyzed = await runCli(
|
||||
[
|
||||
"--format",
|
||||
"json",
|
||||
"analyze-javascript-application",
|
||||
root,
|
||||
"--approved",
|
||||
"--artifact-format",
|
||||
"directory",
|
||||
],
|
||||
environment,
|
||||
);
|
||||
|
||||
expect(analyzed).toMatchObject({
|
||||
operation: "analyze_javascript_application",
|
||||
normalized_result: { input_path: root, format: "directory" },
|
||||
});
|
||||
},
|
||||
INTEGRATION_TEST_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"routes generic approved analysis of a directory to static JavaScript",
|
||||
async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-electron-routed-cli-"));
|
||||
const root = await createTestTempDirectory("rea-electron-routed-cli-");
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
const environment = {
|
||||
@@ -149,8 +182,8 @@ describe("Electron CLI parity", () => {
|
||||
it(
|
||||
"requires explicit approval before generic JavaScript analysis",
|
||||
async () => {
|
||||
const root = await mkdtemp(
|
||||
join(tmpdir(), "rea-electron-unapproved-cli-"),
|
||||
const root = await createTestTempDirectory(
|
||||
"rea-electron-unapproved-cli-",
|
||||
);
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
@@ -182,7 +215,7 @@ describe("Electron CLI parity", () => {
|
||||
it(
|
||||
"reads a file and returns the derived static/runtime reconciliation contract",
|
||||
async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-runtime-cli-"));
|
||||
const root = await createTestTempDirectory("rea-runtime-cli-");
|
||||
const inputPath = join(root, "reconciliation.json");
|
||||
temporary.push(root);
|
||||
await writeFile(
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { mkdtemp, mkdir, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { mkdir, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
authorizedElectronFile,
|
||||
canonicalElectronRoots,
|
||||
@@ -22,7 +23,7 @@ describe("Electron file scope", () => {
|
||||
});
|
||||
|
||||
it("accepts canonical files within a root and rejects escape forms", async () => {
|
||||
const base = await mkdtemp(join(tmpdir(), "rea-electron-scope-"));
|
||||
const base = await createTestTempDirectory("rea-electron-scope-");
|
||||
temporary.push(base);
|
||||
const root = join(base, "root");
|
||||
const outside = join(base, "outside");
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { loadConfiguredPermissionAuthority } from "../src/application/PermissionConfiguration.js";
|
||||
import { CdpElectronProvider } from "../src/browser/CdpElectronProvider.js";
|
||||
@@ -37,7 +38,7 @@ describe("Electron MCP tools", () => {
|
||||
});
|
||||
|
||||
it("exposes root-confined Electron discovery and inspection as Evidence v2", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-electron-mcp-"));
|
||||
const root = await createTestTempDirectory("rea-electron-mcp-");
|
||||
temporary.push(root);
|
||||
await writeFile(join(root, "index.html"), "<script src='app.js'></script>");
|
||||
await writeFile(
|
||||
@@ -187,7 +188,7 @@ describe("Electron MCP tools", () => {
|
||||
});
|
||||
|
||||
it("exposes the target-free static JavaScript application workflow", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-electron-static-mcp-"));
|
||||
const root = await createTestTempDirectory("rea-electron-static-mcp-");
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
const config = parseConfig({
|
||||
@@ -276,7 +277,7 @@ describe("Electron MCP tools", () => {
|
||||
});
|
||||
|
||||
it("reports an unconfigured investigation ceiling before static analysis", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-electron-denied-mcp-"));
|
||||
const root = await createTestTempDirectory("rea-electron-denied-mcp-");
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
const config = parseConfig({});
|
||||
|
||||
@@ -76,6 +76,7 @@ describe("analysis error projection", () => {
|
||||
[77, "unexpected_display_geometry"],
|
||||
[78, "x11_input_failed"],
|
||||
[79, "runtime_dependency_unavailable"],
|
||||
[80, "x11_socket_directory_unusable"],
|
||||
] as const;
|
||||
for (const [exitCode, code] of expected) {
|
||||
const projected = projectAnalysisError(new HopperProcessError(exitCode));
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import {
|
||||
mkdtemp,
|
||||
mkdir,
|
||||
readFile,
|
||||
rm,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, readFile, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
readEvidenceBundle,
|
||||
writeEvidenceBundle,
|
||||
@@ -50,7 +44,7 @@ const policy = (root: string): EvidenceFilePolicy => ({
|
||||
|
||||
describe("evidence bundle filesystem adapter", () => {
|
||||
it("round trips canonical bytes and requires explicit overwrite", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-evidence-"));
|
||||
directory = await createTestTempDirectory("rea-evidence-");
|
||||
const path = join(directory, "bundle.json");
|
||||
const evidenceBundle = bundle();
|
||||
const first = await writeEvidenceBundle(
|
||||
@@ -94,7 +88,7 @@ describe("evidence bundle filesystem adapter", () => {
|
||||
});
|
||||
|
||||
it("uses valid evidence roots when another configured root is missing", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-evidence-roots-"));
|
||||
directory = await createTestTempDirectory("rea-evidence-roots-");
|
||||
const path = join(directory, "bundle.json");
|
||||
const configured = {
|
||||
...policy(directory),
|
||||
@@ -109,7 +103,7 @@ describe("evidence bundle filesystem adapter", () => {
|
||||
});
|
||||
|
||||
it("rejects traversal and symlink escape from approved roots", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-evidence-"));
|
||||
directory = await createTestTempDirectory("rea-evidence-");
|
||||
const root = join(directory, "approved");
|
||||
const outside = join(directory, "outside");
|
||||
await mkdir(root);
|
||||
@@ -131,7 +125,7 @@ describe("evidence bundle filesystem adapter", () => {
|
||||
});
|
||||
|
||||
it("rejects malformed, tampered, oversized, and deeply nested input", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-evidence-"));
|
||||
directory = await createTestTempDirectory("rea-evidence-");
|
||||
const malformed = join(directory, "malformed.json");
|
||||
await writeFile(malformed, "{");
|
||||
expect(
|
||||
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
process.stderr.write("fixture MCP startup exit\n");
|
||||
process.exitCode = 23;
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
|
||||
if (process.env.REA_MCP_DOCTOR_PID_PATH !== undefined)
|
||||
await writeFile(process.env.REA_MCP_DOCTOR_PID_PATH, String(process.pid));
|
||||
setInterval(() => undefined, 1_000);
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
import { mkdtemp, realpath, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { onTestFinished } from "vitest";
|
||||
|
||||
const TEMPORARY_PREFIX = /^[A-Za-z0-9][A-Za-z0-9._-]*-$/u;
|
||||
|
||||
/** Creates a canonical temporary directory owned by the current Vitest case. */
|
||||
export const createTestTempDirectory = async (
|
||||
prefix: string,
|
||||
): Promise<string> => {
|
||||
if (!TEMPORARY_PREFIX.test(prefix) || prefix.length > 80) {
|
||||
throw new TypeError(
|
||||
"Test temporary directory prefixes must be safe basenames ending in '-'",
|
||||
);
|
||||
}
|
||||
|
||||
const canonicalTemporaryRoot = await realpath(tmpdir());
|
||||
const created = await mkdtemp(join(canonicalTemporaryRoot, prefix));
|
||||
const canonicalDirectory = await realpath(created);
|
||||
|
||||
onTestFinished(async () => {
|
||||
await rm(canonicalDirectory, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
maxRetries: 3,
|
||||
retryDelay: 25,
|
||||
});
|
||||
});
|
||||
|
||||
return canonicalDirectory;
|
||||
};
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
fixture = str(Path(__file__).resolve())
|
||||
subprocess.Popen(
|
||||
[sys.executable, "-c", "import time; time.sleep(60)", fixture],
|
||||
)
|
||||
while True:
|
||||
time.sleep(60)
|
||||
@@ -64,7 +64,12 @@ const doctorHost = (
|
||||
executable: (path) =>
|
||||
Promise.resolve(hopperAvailable && path.includes("Hopper")),
|
||||
supportedLinuxHopper: () => Promise.resolve(true),
|
||||
linuxDemoRuntimeReady: () => Promise.resolve(true),
|
||||
linuxDemoRuntimeCheck: () =>
|
||||
Promise.resolve({
|
||||
name: "hopper-demo-runtime",
|
||||
ok: true,
|
||||
classification: "healthy",
|
||||
}),
|
||||
brewHopperPath: () => Promise.resolve(undefined),
|
||||
manualHopperPaths: () => Promise.resolve([]),
|
||||
providerInspections: () =>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { access, chmod, mkdtemp, readFile, rm, stat } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { access, chmod, readFile, rm, stat } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
ghidraHeadlessArguments,
|
||||
ghidraHeadlessCommand,
|
||||
@@ -112,7 +113,7 @@ describe("Ghidra headless launcher", () => {
|
||||
vi.stubEnv("JAVA_TOOL_OPTIONS", "-Duser.home=/unapproved/home");
|
||||
vi.stubEnv("JDK_JAVA_OPTIONS", "-XX:MaxRAMPercentage=99");
|
||||
vi.stubEnv("_JAVA_OPTIONS", "-Xmx99G");
|
||||
const runtimeRoot = await mkdtemp(join(tmpdir(), "rea-launcher-test-"));
|
||||
const runtimeRoot = await createTestTempDirectory("rea-launcher-test-");
|
||||
roots.push(runtimeRoot);
|
||||
const token = "secret-token-that-must-not-leak";
|
||||
const javaHome =
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { access, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { access, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { createGhidraTargetSnapshot } from "../src/ghidra/GhidraTargetSnapshot.js";
|
||||
|
||||
const roots: string[] = [];
|
||||
@@ -17,7 +18,7 @@ afterEach(async () => {
|
||||
|
||||
describe("Ghidra target snapshot", () => {
|
||||
it("copies an exact digest-bound target into the private runtime", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-ghidra-snapshot-"));
|
||||
const root = await createTestTempDirectory("rea-ghidra-snapshot-");
|
||||
roots.push(root);
|
||||
const source = join(root, "source.exe");
|
||||
const bytes = Buffer.from("native PE fixture");
|
||||
@@ -34,7 +35,7 @@ describe("Ghidra target snapshot", () => {
|
||||
});
|
||||
|
||||
it("removes a snapshot whose digest differs from admission", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-ghidra-snapshot-"));
|
||||
const root = await createTestTempDirectory("rea-ghidra-snapshot-");
|
||||
roots.push(root);
|
||||
const source = join(root, "source with unsafe extension.%PATH%");
|
||||
await writeFile(source, "changed target");
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { observeGhidraEndpoint } from "../src/ghidra/GhidraTransport.js";
|
||||
|
||||
const roots: string[] = [];
|
||||
@@ -16,7 +17,7 @@ afterEach(async () => {
|
||||
|
||||
describe("Ghidra local transport", () => {
|
||||
it("observes Unix readiness without interpreting endpoint content", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-ghidra-transport-"));
|
||||
const root = await createTestTempDirectory("rea-ghidra-transport-");
|
||||
roots.push(root);
|
||||
const path = join(root, "bridge.sock");
|
||||
|
||||
@@ -30,7 +31,7 @@ describe("Ghidra local transport", () => {
|
||||
});
|
||||
|
||||
it("accepts only an exact IPv4 loopback endpoint record", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-ghidra-transport-"));
|
||||
const root = await createTestTempDirectory("rea-ghidra-transport-");
|
||||
roots.push(root);
|
||||
const path = join(root, "bridge-endpoint.json");
|
||||
await writeFile(
|
||||
@@ -56,7 +57,7 @@ describe("Ghidra local transport", () => {
|
||||
])(
|
||||
"rejects an invalid or expanded TCP endpoint: $host:$port",
|
||||
async (value) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-ghidra-transport-"));
|
||||
const root = await createTestTempDirectory("rea-ghidra-transport-");
|
||||
roots.push(root);
|
||||
const path = join(root, "bridge-endpoint.json");
|
||||
await writeFile(path, JSON.stringify(value));
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import type { BinaryTarget } from "../src/domain/binaryTarget.js";
|
||||
import {
|
||||
hopperLoaderArgsForTarget,
|
||||
@@ -49,7 +50,7 @@ describe("Hopper analysis profiles", () => {
|
||||
});
|
||||
|
||||
it("commits launcher build and configured overrides without target coupling", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-hopper-profile-"));
|
||||
directory = await createTestTempDirectory("rea-hopper-profile-");
|
||||
const launcher = join(directory, "hopper");
|
||||
await writeFile(launcher, "Hopper build A");
|
||||
const input = target("mach-o", "arm64");
|
||||
@@ -117,7 +118,7 @@ describe("Hopper analysis profiles", () => {
|
||||
});
|
||||
|
||||
it("stops launcher hashing when profile resolution is cancelled", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-hopper-profile-cancel-"));
|
||||
directory = await createTestTempDirectory("rea-hopper-profile-cancel-");
|
||||
const launcher = join(directory, "hopper");
|
||||
await writeFile(launcher, "Hopper build");
|
||||
const controller = new AbortController();
|
||||
|
||||
@@ -6,12 +6,14 @@ import { fileURLToPath } from "node:url";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { OFFICIAL_TOOL_CONTRACTS } from "../src/contracts/toolContracts.js";
|
||||
import type { HopperStartupDiagnostic } from "../src/domain/hopperStartupFailure.js";
|
||||
import { ok } from "../src/domain/result.js";
|
||||
import type {
|
||||
BridgeLauncher,
|
||||
BridgeSession,
|
||||
} from "../src/hopper/BridgeLauncher.js";
|
||||
import { HopperClient } from "../src/hopper/HopperClient.js";
|
||||
import { LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX } from "../src/hopper/LinuxPrivateDisplayDiagnostic.js";
|
||||
|
||||
const fixturePath = fileURLToPath(
|
||||
new URL("./fixtures/fakeHopper.mjs", import.meta.url),
|
||||
@@ -92,6 +94,43 @@ class ExitingLauncher implements BridgeLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
class DiagnosticExitingLauncher implements BridgeLauncher {
|
||||
launch() {
|
||||
const diagnostic: HopperStartupDiagnostic = {
|
||||
schema_version: 1,
|
||||
component: "hopper_private_display",
|
||||
operation: "launch",
|
||||
status: "error",
|
||||
failure_code: "x11_socket_directory_unusable",
|
||||
reason: "socket_directory_read_only",
|
||||
socket_directory: "/tmp/.X11-unix",
|
||||
socket_directory_mode: "0777",
|
||||
mount_read_only: true,
|
||||
effective_socket_directory_mode: "0777",
|
||||
effective_mount_read_only: true,
|
||||
wsl: true,
|
||||
strategy: "direct",
|
||||
fallback_reason: null,
|
||||
xvfb_stderr_bytes: 100,
|
||||
xvfb_stderr_truncated: false,
|
||||
};
|
||||
const line = `${LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX}${JSON.stringify(diagnostic)}\n`;
|
||||
return Promise.resolve(
|
||||
ok({
|
||||
process: spawn(
|
||||
process.execPath,
|
||||
[
|
||||
"-e",
|
||||
`process.stderr.write(${JSON.stringify(line)}, () => process.exit(80))`,
|
||||
],
|
||||
{ stdio: ["ignore", "ignore", "pipe"] },
|
||||
),
|
||||
ownsProcessLifetime: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LateSilentLauncher implements BridgeLauncher {
|
||||
readonly directories: string[] = [];
|
||||
readonly processes: ChildProcess[] = [];
|
||||
@@ -261,7 +300,7 @@ describe("HopperClient", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it.each([70, 71, 72, 73, 74, 75, 76, 77, 78, 79])(
|
||||
it.each([70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80])(
|
||||
"reports Linux adapter exit %i during bridge startup",
|
||||
async (exitCode) => {
|
||||
const client = new HopperClient({
|
||||
@@ -279,6 +318,30 @@ describe("HopperClient", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves the bounded private-display diagnostic from an adapter exit", async () => {
|
||||
const client = new HopperClient({
|
||||
launcher: new DiagnosticExitingLauncher(),
|
||||
startupTimeoutMs: 10_000,
|
||||
});
|
||||
clients.push(client);
|
||||
const result = await client.start();
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "HopperProcessError",
|
||||
exitCode: 80,
|
||||
failureCode: "x11_socket_directory_unusable",
|
||||
diagnostic: {
|
||||
socket_directory: "/tmp/.X11-unix",
|
||||
socket_directory_mode: "0777",
|
||||
mount_read_only: true,
|
||||
wsl: true,
|
||||
strategy: "direct",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("allows a short-lived launcher to hand off bridge startup", async () => {
|
||||
const client = new HopperClient({
|
||||
launcher: new ExitingLauncher(0),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import {
|
||||
chmod,
|
||||
mkdtemp,
|
||||
mkdir,
|
||||
readFile,
|
||||
readdir,
|
||||
@@ -9,12 +8,13 @@ import {
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const roots: string[] = [];
|
||||
|
||||
@@ -165,7 +165,7 @@ interface InstallerFixture {
|
||||
}
|
||||
|
||||
const createFixture = async (): Promise<InstallerFixture> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-install-test-"));
|
||||
const root = await createTestTempDirectory("rea-install-test-");
|
||||
roots.push(root);
|
||||
const home = join(root, "home");
|
||||
const bin = join(root, "bin");
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { FUNCTION_COMPARISON_EXAMPLE } from "../src/contracts/functionComparisonExample.js";
|
||||
import { INVESTIGATION_EXAMPLES } from "../src/contracts/investigationExamples.js";
|
||||
@@ -69,7 +70,7 @@ describe("investigation MCP workflows", () => {
|
||||
});
|
||||
|
||||
it("runs and reuses a persistent cross-version workspace", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-investigation-mcp-"));
|
||||
const directory = await createTestTempDirectory("rea-investigation-mcp-");
|
||||
const left = join(directory, "left");
|
||||
const right = join(directory, "right");
|
||||
const workspace = join(directory, "workspace.json");
|
||||
@@ -146,7 +147,7 @@ describe("investigation MCP workflows", () => {
|
||||
});
|
||||
|
||||
it("replays a complete workspace without write authority", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-investigation-read-"));
|
||||
const directory = await createTestTempDirectory("rea-investigation-read-");
|
||||
const left = join(directory, "left");
|
||||
const right = join(directory, "right");
|
||||
const workspace = join(directory, "workspace.json");
|
||||
@@ -211,8 +212,8 @@ describe("investigation MCP workflows", () => {
|
||||
});
|
||||
|
||||
it("defers input permission for an explicit replay with deleted inputs", async () => {
|
||||
const directory = await mkdtemp(
|
||||
join(tmpdir(), "rea-investigation-replay-"),
|
||||
const directory = await createTestTempDirectory(
|
||||
"rea-investigation-replay-",
|
||||
);
|
||||
const left = join(directory, "left");
|
||||
const right = join(directory, "right");
|
||||
@@ -288,7 +289,7 @@ describe("investigation MCP workflows", () => {
|
||||
});
|
||||
|
||||
it("refuses automatic artifact reads outside operator-approved roots", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-investigation-mcp-"));
|
||||
const directory = await createTestTempDirectory("rea-investigation-mcp-");
|
||||
const approvedInputs = join(directory, "approved-inputs");
|
||||
const outsideInputs = join(directory, "outside-inputs");
|
||||
const evidenceRoot = join(directory, "evidence");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
chmod,
|
||||
mkdir,
|
||||
mkdtemp,
|
||||
readFile,
|
||||
rm,
|
||||
stat,
|
||||
@@ -9,13 +8,14 @@ import {
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { createHash } from "node:crypto";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createPackageWithOptions } from "@electron/asar";
|
||||
import canonicalize from "canonicalize";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { runCrossVersionInvestigation } from "../src/application/CrossVersionInvestigation.js";
|
||||
import {
|
||||
readInvestigationWorkspace,
|
||||
@@ -56,7 +56,7 @@ const policy = (root: string): EvidenceFilePolicy => ({
|
||||
});
|
||||
|
||||
const fixture = async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-workspace-"));
|
||||
directory = await createTestTempDirectory("rea-workspace-");
|
||||
const left = join(directory, "left");
|
||||
const right = join(directory, "right");
|
||||
await Promise.all([mkdir(left), mkdir(right)]);
|
||||
@@ -480,7 +480,7 @@ describe("persistent cross-version investigation workspace", () => {
|
||||
});
|
||||
|
||||
it("checkpoints bounded integrity contradictions and safely reuses them", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-workspace-integrity-"));
|
||||
directory = await createTestTempDirectory("rea-workspace-integrity-");
|
||||
const source = join(directory, "source");
|
||||
await mkdir(source);
|
||||
await writeFile(join(source, "addon.node"), "verified native addon\n");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { rm } from "node:fs/promises";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../src/application/JavaScriptApplicationService.js";
|
||||
import { compareApplicationVersionsEvidence } from "../src/application/JavaScriptApplicationWorkflowService.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
@@ -131,7 +131,7 @@ describe("JavaScript application workflows", () => {
|
||||
});
|
||||
|
||||
it("matches rechunked modules by exact source and minified modules by structural fingerprint", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-application-versions-"));
|
||||
const root = await createTestTempDirectory("rea-application-versions-");
|
||||
temporary.push(root);
|
||||
const fixtures = await writeVersionedJavaScriptApplicationFixtures(root);
|
||||
const [left, right] = await Promise.all([
|
||||
@@ -189,7 +189,7 @@ describe("JavaScript application workflows", () => {
|
||||
});
|
||||
|
||||
it("pairs source-map originals without promoting the match to exact", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-source-map-versions-"));
|
||||
const root = await createTestTempDirectory("rea-source-map-versions-");
|
||||
temporary.push(root);
|
||||
const fixtures = await writeVersionedJavaScriptApplicationFixtures(root);
|
||||
const [left, right] = await Promise.all([
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { Readable } from "node:stream";
|
||||
import { mkdtemp, mkdir, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { createPackageWithOptions } from "@electron/asar";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { readJavaScriptArtifactFiles } from "../src/application/JavaScriptArtifactFiles.js";
|
||||
import { reconstructJavaScriptArtifact } from "../src/application/JavaScriptArtifactReconstruction.js";
|
||||
import {
|
||||
@@ -151,7 +152,7 @@ describe("JavaScript artifact reconstruction", () => {
|
||||
});
|
||||
|
||||
it("produces deterministic ASAR graphs with unpacked native linkage and complete paths/digests", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-javascript-asar-"));
|
||||
const root = await createTestTempDirectory("rea-javascript-asar-");
|
||||
const source = join(root, "source");
|
||||
await mkdir(source);
|
||||
await writeJavaScriptArtifactFixture(source);
|
||||
@@ -210,7 +211,7 @@ describe("JavaScript artifact reconstruction", () => {
|
||||
});
|
||||
|
||||
it("keeps ASAR analysis usable when unpacked native companion bytes are absent", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-javascript-asar-missing-"));
|
||||
const root = await createTestTempDirectory("rea-javascript-asar-missing-");
|
||||
const source = join(root, "source");
|
||||
await mkdir(source);
|
||||
await writeJavaScriptArtifactFixture(source);
|
||||
@@ -253,7 +254,7 @@ describe("JavaScript artifact reconstruction", () => {
|
||||
});
|
||||
|
||||
it("recurses into filesystem-backed ASAR containers without losing container-relative paths", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-javascript-nested-asar-"));
|
||||
const root = await createTestTempDirectory("rea-javascript-nested-asar-");
|
||||
const source = await fixtureDirectory();
|
||||
const outer = join(root, "outer");
|
||||
const resources = join(outer, "resources");
|
||||
@@ -362,7 +363,7 @@ describe("JavaScript artifact reconstruction", () => {
|
||||
});
|
||||
|
||||
it("uses an unknown omission count when AST traversal reaches its bound", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-javascript-ast-limit-"));
|
||||
const root = await createTestTempDirectory("rea-javascript-ast-limit-");
|
||||
await writeFile(
|
||||
join(root, "large.js"),
|
||||
[
|
||||
@@ -403,7 +404,7 @@ describe("JavaScript artifact reconstruction", () => {
|
||||
|
||||
it("does not follow symlinks or read oversized JavaScript text", async () => {
|
||||
const root = await fixtureDirectory();
|
||||
const outside = await mkdtemp(join(tmpdir(), "rea-javascript-outside-"));
|
||||
const outside = await createTestTempDirectory("rea-javascript-outside-");
|
||||
const outsideFile = join(outside, "secret.js");
|
||||
await writeFile(
|
||||
outsideFile,
|
||||
@@ -465,7 +466,7 @@ describe("JavaScript artifact reconstruction", () => {
|
||||
});
|
||||
|
||||
it("applies one source-map source budget across every local map", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-javascript-source-maps-"));
|
||||
const root = await createTestTempDirectory("rea-javascript-source-maps-");
|
||||
await Promise.all([
|
||||
writeFile(
|
||||
join(root, "a.js.map"),
|
||||
@@ -506,7 +507,7 @@ describe("JavaScript artifact reconstruction", () => {
|
||||
});
|
||||
|
||||
it("bounds repeated content observations while retaining every containment path", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-javascript-observations-"));
|
||||
const root = await createTestTempDirectory("rea-javascript-observations-");
|
||||
await Promise.all(
|
||||
Array.from({ length: 70 }, (_, index) =>
|
||||
writeFile(
|
||||
@@ -617,7 +618,7 @@ class TraversalReader implements ArtifactReader {
|
||||
}
|
||||
|
||||
const fixtureDirectory = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-javascript-artifact-"));
|
||||
const root = await createTestTempDirectory("rea-javascript-artifact-");
|
||||
await writeJavaScriptArtifactFixture(root);
|
||||
return root;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { reconstructJavaScriptArtifact } from "../src/application/JavaScriptArtifactReconstruction.js";
|
||||
import type {
|
||||
ApplicationEdge,
|
||||
@@ -106,7 +107,7 @@ describe("Webpack and Rspack runtime adapters", () => {
|
||||
});
|
||||
|
||||
const bundlerFixture = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-bundler-adapters-"));
|
||||
const root = await createTestTempDirectory("rea-bundler-adapters-");
|
||||
await mkdir(join(root, "renderer", "chunks"), { recursive: true });
|
||||
await writeFile(
|
||||
join(root, "renderer", "chunks", "runtime.js"),
|
||||
|
||||
@@ -0,0 +1,332 @@
|
||||
import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../src/application/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../src/application/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { compareJavaScriptExportShapes } from "../src/domain/javascriptExportShapeComparison.js";
|
||||
import { javaScriptExportShapeComparisonResultSchema } from "../src/domain/javascriptExportShapeComparisonSchemas.js";
|
||||
import {
|
||||
createJavaScriptApplicationGraph,
|
||||
createJavaScriptApplicationNode,
|
||||
} from "../src/domain/javascriptApplicationGraph.js";
|
||||
import { permissionAuthorityForRoot } from "./fixtures/permissionAuthority.js";
|
||||
|
||||
describe("JavaScript export return-shape comparison", () => {
|
||||
const temporary: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporary
|
||||
.splice(0)
|
||||
.map(async (path) => rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports exactly the heading depth addition from source-owned parser fixtures", async () => {
|
||||
const root = await temporaryRoot(temporary);
|
||||
const leftRoot = join(root, "left");
|
||||
const rightRoot = join(root, "right");
|
||||
await Promise.all([mkdir(leftRoot), mkdir(rightRoot)]);
|
||||
await Promise.all([
|
||||
copyFile(
|
||||
resolve("tests/fixtures/replay/parser.mjs"),
|
||||
join(leftRoot, "parser.mjs"),
|
||||
),
|
||||
copyFile(
|
||||
resolve("tests/fixtures/replay/parser-v2.mjs"),
|
||||
join(rightRoot, "parser.mjs"),
|
||||
),
|
||||
]);
|
||||
const [left, right] = await Promise.all([
|
||||
analyzeGraph(leftRoot),
|
||||
analyzeGraph(rightRoot),
|
||||
]);
|
||||
|
||||
const first = compare(left, right);
|
||||
const second = compare(left, right);
|
||||
|
||||
expect(first.comparison_id).toBe(second.comparison_id);
|
||||
expect(() =>
|
||||
javaScriptExportShapeComparisonResultSchema.parse(first),
|
||||
).not.toThrow();
|
||||
expect(first.summary).toEqual({
|
||||
added: 1,
|
||||
removed: 0,
|
||||
changed: 0,
|
||||
unknown: 0,
|
||||
});
|
||||
expect(first.changes).toEqual([
|
||||
expect.objectContaining({
|
||||
status: "added",
|
||||
path: "/depth",
|
||||
discriminant: { path: "/type", value: "heading" },
|
||||
left: { availability: "absent" },
|
||||
right: { availability: "literal", value: 1 },
|
||||
}),
|
||||
]);
|
||||
expect(first.changes.some(({ path }) => path === "/text")).toBe(false);
|
||||
expect(first.coverage).toMatchObject({
|
||||
status: "complete-within-inputs",
|
||||
paired_variants: 3,
|
||||
unpaired_left_variants: 0,
|
||||
unpaired_right_variants: 0,
|
||||
});
|
||||
expect(first.runtime_validation).toEqual({
|
||||
recommended_tool: "run_controlled_replay",
|
||||
automatically_started: false,
|
||||
required_for: "runtime-semantics",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps additions unknown when spread coverage is incomplete", async () => {
|
||||
const [left, right] = await analyzeSources(temporary, {
|
||||
left: `
|
||||
const dynamic = getDynamic();
|
||||
export default () => ({ type: "heading", ...dynamic });
|
||||
`,
|
||||
right: `
|
||||
const dynamic = getDynamic();
|
||||
export default () => ({ type: "heading", depth: 1, ...dynamic });
|
||||
`,
|
||||
});
|
||||
const result = compare(left, right);
|
||||
|
||||
expect(result.changes).toEqual([
|
||||
expect.objectContaining({ status: "unknown", path: "/depth" }),
|
||||
]);
|
||||
expect(result.coverage.status).toBe("partial");
|
||||
});
|
||||
|
||||
it("does not pair ambiguous variants or invent behavior for no-return exports", async () => {
|
||||
const ambiguous = await analyzeSources(temporary, {
|
||||
left: `
|
||||
export default function parse(value) {
|
||||
if (value) return { type: "heading", text: render(value) };
|
||||
return { type: "heading", text: render(value) };
|
||||
}
|
||||
`,
|
||||
right: `export default (value) => ({ type: "heading", text: render(value) });`,
|
||||
});
|
||||
const compared = compare(...ambiguous);
|
||||
expect(compared.summary.unknown).toBe(3);
|
||||
expect(compared.coverage).toMatchObject({
|
||||
status: "partial",
|
||||
paired_variants: 0,
|
||||
unpaired_left_variants: 2,
|
||||
unpaired_right_variants: 1,
|
||||
});
|
||||
|
||||
const noReturn = await analyzeSources(temporary, {
|
||||
left: `export default function stop() { throw new Error("stop"); }`,
|
||||
right: `export default function stop() { throw new Error("stop"); }`,
|
||||
});
|
||||
const unknown = compare(...noReturn);
|
||||
expect(unknown.changes).toEqual([
|
||||
expect.objectContaining({ status: "unknown", path: "" }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("reports selector candidates and enforces candidate, variant, and change limits", async () => {
|
||||
const candidates = await analyzeSources(temporary, {
|
||||
left: `
|
||||
export const first = () => ({ type: "first" });
|
||||
export const second = () => ({ type: "second" });
|
||||
export const third = () => ({ type: "third" });
|
||||
`,
|
||||
right: `export default () => ({ type: "default" });`,
|
||||
});
|
||||
const missing = compare(candidates[0], candidates[1], {
|
||||
leftExportName: "missing",
|
||||
limits: { max_candidate_exports: 1 },
|
||||
});
|
||||
expect(missing.left).toMatchObject({
|
||||
status: "missing",
|
||||
omitted_candidates: 2,
|
||||
candidates: [expect.objectContaining({ module_path: "parser.mjs" })],
|
||||
});
|
||||
expect(missing.coverage.status).toBe("truncated");
|
||||
|
||||
const parsers = await sourceOwnedParsers(temporary);
|
||||
const variantLimited = compare(parsers[0], parsers[1], {
|
||||
limits: { max_return_variants: 1 },
|
||||
});
|
||||
expect(variantLimited.coverage).toMatchObject({
|
||||
status: "truncated",
|
||||
omitted_left_variants: 2,
|
||||
omitted_right_variants: 2,
|
||||
});
|
||||
|
||||
const changes = await analyzeSources(temporary, {
|
||||
left: `export default () => ({ type: "item" });`,
|
||||
right: `export default () => ({ type: "item", depth: 1, level: 2 });`,
|
||||
});
|
||||
const changeLimited = compare(changes[0], changes[1], {
|
||||
limits: { max_changes: 1 },
|
||||
});
|
||||
expect(changeLimited.summary.added).toBe(2);
|
||||
expect(changeLimited.changes).toHaveLength(1);
|
||||
expect(changeLimited.coverage).toMatchObject({
|
||||
status: "truncated",
|
||||
omitted_changes: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it("refuses an exact selector that resolves to multiple graph nodes", async () => {
|
||||
const [left, right] = await analyzeSources(temporary, {
|
||||
left: `export default () => ({ type: "item" });`,
|
||||
right: `export default () => ({ type: "item" });`,
|
||||
});
|
||||
const exported = left.graph.nodes.find((node) =>
|
||||
node.observations.some(
|
||||
({ properties }) => properties.semantic_role === "export-binding",
|
||||
),
|
||||
);
|
||||
if (
|
||||
exported === undefined ||
|
||||
exported.identity.strategy !== "artifact-local-key"
|
||||
)
|
||||
throw new Error("Expected one artifact-local export fixture node");
|
||||
const duplicate = createJavaScriptApplicationNode({
|
||||
kind: exported.kind,
|
||||
identity: {
|
||||
...exported.identity,
|
||||
key: `${exported.identity.key}:duplicate`,
|
||||
},
|
||||
observations: exported.observations.map(
|
||||
({ label, properties, evidence }) => ({ label, properties, evidence }),
|
||||
),
|
||||
});
|
||||
const ambiguousGraph = createJavaScriptApplicationGraph({
|
||||
schema: "JavaScriptApplicationGraph",
|
||||
schema_version: 1,
|
||||
root_node_ids: left.graph.root_node_ids,
|
||||
nodes: [...left.graph.nodes, duplicate],
|
||||
edges: left.graph.edges,
|
||||
coverage: left.graph.coverage,
|
||||
limitations: left.graph.limitations,
|
||||
});
|
||||
const result = compare({ ...left, graph: ambiguousGraph }, right);
|
||||
|
||||
expect(result.left).toMatchObject({
|
||||
status: "ambiguous",
|
||||
selected_node_id: null,
|
||||
candidates: [expect.any(Object), expect.any(Object)],
|
||||
});
|
||||
expect(result.changes).toEqual([
|
||||
expect.objectContaining({ status: "unknown", path: "" }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("marks graph field projection omissions as truncated", async () => {
|
||||
const properties = [
|
||||
'a_type: "item"',
|
||||
...Array.from(
|
||||
{ length: 70 },
|
||||
(_, index) => `field${String(index)}: ${String(index)}`,
|
||||
),
|
||||
].join(",");
|
||||
const [left, right] = await analyzeSources(temporary, {
|
||||
left: `export default () => ({ ${properties} });`,
|
||||
right: `export default () => ({ ${properties} });`,
|
||||
});
|
||||
const result = compare(left, right);
|
||||
|
||||
expect(result.coverage.status).toBe("truncated");
|
||||
expect(result.coverage.left_omitted_fields).toBeGreaterThan(0);
|
||||
expect(result.coverage.right_omitted_fields).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
type GraphSource = Awaited<ReturnType<typeof analyzeGraph>>;
|
||||
|
||||
const compare = (
|
||||
left: GraphSource,
|
||||
right: GraphSource,
|
||||
options: {
|
||||
readonly leftExportName?: string;
|
||||
readonly rightExportName?: string;
|
||||
readonly limits?: Partial<{
|
||||
readonly max_candidate_exports: number;
|
||||
readonly max_return_variants: number;
|
||||
readonly max_changes: number;
|
||||
}>;
|
||||
} = {},
|
||||
) =>
|
||||
compareJavaScriptExportShapes({
|
||||
left: {
|
||||
evidenceId: left.evidence.evidence_id,
|
||||
graph: left.graph,
|
||||
modulePath: "parser.mjs",
|
||||
exportName: options.leftExportName ?? "default",
|
||||
},
|
||||
right: {
|
||||
evidenceId: right.evidence.evidence_id,
|
||||
graph: right.graph,
|
||||
modulePath: "parser.mjs",
|
||||
exportName: options.rightExportName ?? "default",
|
||||
},
|
||||
limits: {
|
||||
max_candidate_exports: options.limits?.max_candidate_exports ?? 100,
|
||||
max_return_variants: options.limits?.max_return_variants ?? 128,
|
||||
max_changes: options.limits?.max_changes ?? 1_000,
|
||||
},
|
||||
});
|
||||
|
||||
const analyzeGraph = async (root: string) => {
|
||||
const authority = await permissionAuthorityForRoot(
|
||||
root,
|
||||
["investigation_input"],
|
||||
["investigation_input"],
|
||||
);
|
||||
const result = await analyzeJavaScriptApplication(authority, {
|
||||
input_path: root,
|
||||
approved: true,
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
return parseApplicationGraphEvidence(result.value);
|
||||
};
|
||||
|
||||
const analyzeSources = async (
|
||||
temporary: string[],
|
||||
sources: { readonly left: string; readonly right: string },
|
||||
): Promise<[GraphSource, GraphSource]> => {
|
||||
const root = await temporaryRoot(temporary);
|
||||
const leftRoot = join(root, "left");
|
||||
const rightRoot = join(root, "right");
|
||||
await Promise.all([mkdir(leftRoot), mkdir(rightRoot)]);
|
||||
await Promise.all([
|
||||
writeFile(join(leftRoot, "parser.mjs"), sources.left),
|
||||
writeFile(join(rightRoot, "parser.mjs"), sources.right),
|
||||
]);
|
||||
return Promise.all([analyzeGraph(leftRoot), analyzeGraph(rightRoot)]);
|
||||
};
|
||||
|
||||
const sourceOwnedParsers = async (
|
||||
temporary: string[],
|
||||
): Promise<[GraphSource, GraphSource]> => {
|
||||
const root = await temporaryRoot(temporary);
|
||||
const leftRoot = join(root, "left");
|
||||
const rightRoot = join(root, "right");
|
||||
await Promise.all([mkdir(leftRoot), mkdir(rightRoot)]);
|
||||
await Promise.all([
|
||||
copyFile(
|
||||
resolve("tests/fixtures/replay/parser.mjs"),
|
||||
join(leftRoot, "parser.mjs"),
|
||||
),
|
||||
copyFile(
|
||||
resolve("tests/fixtures/replay/parser-v2.mjs"),
|
||||
join(rightRoot, "parser.mjs"),
|
||||
),
|
||||
]);
|
||||
return Promise.all([analyzeGraph(leftRoot), analyzeGraph(rightRoot)]);
|
||||
};
|
||||
|
||||
const temporaryRoot = async (temporary: string[]): Promise<string> => {
|
||||
const root = await createTestTempDirectory("rea-export-shapes-");
|
||||
temporary.push(root);
|
||||
return root;
|
||||
};
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { reconstructJavaScriptArtifact } from "../src/application/JavaScriptArtifactReconstruction.js";
|
||||
import type {
|
||||
ApplicationEdge,
|
||||
@@ -152,7 +153,7 @@ describe("CommonJS and ESM module relationships", () => {
|
||||
});
|
||||
|
||||
it("retains exact semantic omissions when the relationship budget truncates", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-module-limit-"));
|
||||
const root = await createTestTempDirectory("rea-module-limit-");
|
||||
try {
|
||||
await writeFile(
|
||||
join(root, "exports.mjs"),
|
||||
@@ -183,7 +184,7 @@ describe("CommonJS and ESM module relationships", () => {
|
||||
});
|
||||
|
||||
const moduleFixture = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-module-relationships-"));
|
||||
const root = await createTestTempDirectory("rea-module-relationships-");
|
||||
await mkdir(join(root, "node_modules", "fixture-package"), {
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, readFile, realpath, rm, stat } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFile, realpath, rm, stat } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { runControlledReplay } from "../src/application/JavaScriptReplayService.js";
|
||||
import type {
|
||||
JavaScriptReplayHost,
|
||||
@@ -379,7 +380,7 @@ describe("controlled JavaScript replay", () => {
|
||||
});
|
||||
|
||||
it("exports an owner-only source-free reproducer after cleanup", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-reproducer-test-"));
|
||||
const directory = await createTestTempDirectory("rea-reproducer-test-");
|
||||
const path = join(directory, "reproducer.json");
|
||||
const dependencies = {
|
||||
policy,
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { createElectronEvidence } from "../src/application/ElectronEvidence.js";
|
||||
import { analyzeJavaScriptApplication } from "../src/application/JavaScriptApplicationService.js";
|
||||
import { reconcileJavaScriptRuntime } from "../src/domain/javascriptRuntimeReconciliation.js";
|
||||
@@ -147,9 +148,9 @@ describe("JavaScript static/passive-runtime reconciliation", () => {
|
||||
|
||||
it("imports an operator-provided cache layer through an explicit file mapping", async () => {
|
||||
const application = await applicationFixture();
|
||||
const cache = await mkdtemp(join(tmpdir(), "rea-runtime-cache-static-"));
|
||||
const runtimeCache = await mkdtemp(
|
||||
join(tmpdir(), "rea-runtime-cache-live-"),
|
||||
const cache = await createTestTempDirectory("rea-runtime-cache-static-");
|
||||
const runtimeCache = await createTestTempDirectory(
|
||||
"rea-runtime-cache-live-",
|
||||
);
|
||||
temporary.push(application, cache, runtimeCache);
|
||||
const cacheSource = "export const cachedFeature = 'fixture';\n";
|
||||
@@ -215,8 +216,8 @@ describe("JavaScript static/passive-runtime reconciliation", () => {
|
||||
|
||||
it("keeps byte-identical cross-layer candidates explicitly ambiguous", async () => {
|
||||
const application = await applicationFixture();
|
||||
const assets = await mkdtemp(join(tmpdir(), "rea-runtime-assets-static-"));
|
||||
const runtime = await mkdtemp(join(tmpdir(), "rea-runtime-assets-live-"));
|
||||
const assets = await createTestTempDirectory("rea-runtime-assets-static-");
|
||||
const runtime = await createTestTempDirectory("rea-runtime-assets-live-");
|
||||
temporary.push(application, assets, runtime);
|
||||
await Promise.all([
|
||||
writeFile(join(assets, "app.js"), SOURCE),
|
||||
@@ -345,7 +346,7 @@ describe("JavaScript static/passive-runtime reconciliation", () => {
|
||||
|
||||
it("runs the local verifier from operator-provided paths without emitting source", async () => {
|
||||
const fixture = await applicationFixture();
|
||||
const evidenceRoot = await mkdtemp(join(tmpdir(), "rea-runtime-evidence-"));
|
||||
const evidenceRoot = await createTestTempDirectory("rea-runtime-evidence-");
|
||||
const evidencePath = join(evidenceRoot, "runtime-evidence.json");
|
||||
temporary.push(fixture, evidenceRoot);
|
||||
await writeFile(
|
||||
@@ -375,7 +376,7 @@ describe("JavaScript static/passive-runtime reconciliation", () => {
|
||||
});
|
||||
|
||||
const applicationFixture = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-runtime-reconciliation-"));
|
||||
const root = await createTestTempDirectory("rea-runtime-reconciliation-");
|
||||
await Promise.all([
|
||||
writeFile(
|
||||
join(root, "package.json"),
|
||||
|
||||
@@ -200,6 +200,95 @@ describe("JavaScript semantic analysis", () => {
|
||||
expect(bindingsNamed(ir, "method")).toEqual([]);
|
||||
});
|
||||
|
||||
it("recovers only direct return sites with literal and unknown object fields", () => {
|
||||
const ir = analyzeJavaScriptSemantics(`
|
||||
export default function parseMarkdown(value) {
|
||||
if (value.startsWith("# "))
|
||||
return { type: "heading", depth: 1, text: value.slice(2) };
|
||||
function nested() { return { type: "nested" }; }
|
||||
const arrow = () => ({ type: "arrow" });
|
||||
void nested; void arrow;
|
||||
return { type: "paragraph", text: value.replaceAll("x", "y") };
|
||||
}
|
||||
`);
|
||||
|
||||
const parse = onlyCallable(ir, "parseMarkdown");
|
||||
expect(parse.returnCoverage).toEqual({
|
||||
status: "complete",
|
||||
retainedCount: 2,
|
||||
omittedCount: 0,
|
||||
limitsReached: [],
|
||||
});
|
||||
expect(parse.returnSites).toHaveLength(2);
|
||||
expect(parse.returnSites[0]?.value).toMatchObject({
|
||||
status: "object",
|
||||
unknownProperties: false,
|
||||
omittedProperties: 0,
|
||||
properties: expect.arrayContaining([
|
||||
{ name: "depth", value: { status: "literal", value: 1 } },
|
||||
{ name: "type", value: { status: "literal", value: "heading" } },
|
||||
{
|
||||
name: "text",
|
||||
value: {
|
||||
status: "unknown",
|
||||
reason: "Unsupported CallExpression value.",
|
||||
},
|
||||
},
|
||||
]),
|
||||
});
|
||||
expect(onlyCallable(ir, "nested").returnSites).toHaveLength(1);
|
||||
expect(onlyCallable(ir, "arrow").returnSites).toHaveLength(1);
|
||||
expect(ir.moduleLinks).toContainEqual(
|
||||
expect.objectContaining({
|
||||
exportedName: "default",
|
||||
callableId: parse.callableId,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("retains partial property coverage, empty returns, and return limits", () => {
|
||||
const partial = analyzeJavaScriptSemantics(`
|
||||
const spread = () => ({ type: "spread", ...dynamic });
|
||||
const computed = () => ({ type: "computed", [key]: 1 });
|
||||
function noReturn() { throw new Error("stop"); }
|
||||
function emptyReturn() { return; }
|
||||
`);
|
||||
expect(onlyCallable(partial, "spread").returnSites[0]?.value).toMatchObject(
|
||||
{
|
||||
status: "object",
|
||||
unknownProperties: true,
|
||||
omittedProperties: null,
|
||||
},
|
||||
);
|
||||
expect(
|
||||
onlyCallable(partial, "computed").returnSites[0]?.value,
|
||||
).toMatchObject({
|
||||
status: "object",
|
||||
unknownProperties: true,
|
||||
omittedProperties: 1,
|
||||
});
|
||||
expect(onlyCallable(partial, "noReturn").returnSites).toEqual([]);
|
||||
expect(onlyCallable(partial, "emptyReturn").returnSites[0]?.value).toEqual({
|
||||
status: "unknown",
|
||||
reason: "Return has no value.",
|
||||
});
|
||||
|
||||
const limited = analyzeJavaScriptSemantics(
|
||||
"function many(value) { if (value) return 1; return 2; }",
|
||||
{ maxReturnSites: 1 },
|
||||
);
|
||||
expect(onlyCallable(limited, "many")).toMatchObject({
|
||||
returnSites: [{ value: { status: "literal", value: 1 } }],
|
||||
returnCoverage: {
|
||||
status: "truncated",
|
||||
retainedCount: 1,
|
||||
omittedCount: 1,
|
||||
limitsReached: ["maxReturnSites"],
|
||||
},
|
||||
});
|
||||
expect(limited.coverage.limitsReached).toContain("maxReturnSites");
|
||||
});
|
||||
|
||||
it("fails closed on assignment ambiguity, alias cycles, and lattice limits", () => {
|
||||
const ambiguous = analyzeJavaScriptSemantics(`
|
||||
let current = "first";
|
||||
@@ -347,6 +436,36 @@ describe("JavaScript semantic analysis", () => {
|
||||
expect(ir.limitations.join(" ")).toMatch(/parser recovered/iu);
|
||||
});
|
||||
|
||||
it("keeps parser-recovered return shapes partial", () => {
|
||||
const ir = analyzeJavaScriptSemantics(
|
||||
`
|
||||
export default function recovered(value) {
|
||||
const duplicate = 1;
|
||||
const duplicate = 2;
|
||||
return { type: "item", text: render(value) };
|
||||
}
|
||||
`,
|
||||
);
|
||||
const recovered = onlyCallable(ir, "recovered");
|
||||
|
||||
expect(ir.coverage.status).toBe("partial");
|
||||
expect(recovered.returnCoverage).toMatchObject({
|
||||
status: "partial",
|
||||
retainedCount: 1,
|
||||
omittedCount: 0,
|
||||
});
|
||||
expect(recovered.returnSites[0]?.value).toMatchObject({
|
||||
status: "object",
|
||||
properties: expect.arrayContaining([
|
||||
{ name: "type", value: { status: "literal", value: "item" } },
|
||||
expect.objectContaining({
|
||||
name: "text",
|
||||
value: expect.objectContaining({ status: "unknown" }),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
it.prop([fc.string({ maxLength: 512 })])(
|
||||
"fails closed for arbitrary bounded source text",
|
||||
(source) => {
|
||||
@@ -394,6 +513,15 @@ const onlyBinding = (
|
||||
return binding;
|
||||
};
|
||||
|
||||
const onlyCallable = (ir: JavaScriptSemanticIr, name: string) => {
|
||||
const callables = ir.callables.filter(
|
||||
({ name: candidate }) => candidate === name,
|
||||
);
|
||||
if (callables.length !== 1 || callables[0] === undefined)
|
||||
throw new Error(`Expected one callable named ${name}`);
|
||||
return callables[0];
|
||||
};
|
||||
|
||||
const topLevelBinding = (
|
||||
ir: JavaScriptSemanticIr,
|
||||
name: string,
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { HopperStartupDiagnostic } from "../src/domain/hopperStartupFailure.js";
|
||||
import {
|
||||
runLinuxPrivateDisplayProbe,
|
||||
selectLinuxPrivateDisplayStrategy,
|
||||
type LinuxPrivateDisplayProbeProcessResult,
|
||||
type LinuxPrivateDisplayProbeRunner,
|
||||
type LinuxPrivateDisplayRunnableStrategy,
|
||||
} from "../src/hopper/LinuxPrivateDisplayProbe.js";
|
||||
import {
|
||||
LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX,
|
||||
parseLinuxPrivateDisplayDiagnostic,
|
||||
} from "../src/hopper/LinuxPrivateDisplayDiagnostic.js";
|
||||
|
||||
const helperPath = fileURLToPath(
|
||||
new URL("../scripts/hopper-demo-x11.py", import.meta.url),
|
||||
);
|
||||
const hangingHelperPath = fileURLToPath(
|
||||
new URL("./fixtures/x11ProbeHang.py", import.meta.url),
|
||||
);
|
||||
|
||||
const diagnostic = (
|
||||
overrides: Partial<HopperStartupDiagnostic> = {},
|
||||
): HopperStartupDiagnostic => ({
|
||||
schema_version: 1,
|
||||
component: "hopper_private_display",
|
||||
operation: "probe",
|
||||
status: "ready",
|
||||
failure_code: null,
|
||||
reason: "ready",
|
||||
socket_directory: "/tmp/.X11-unix",
|
||||
socket_directory_mode: "1777",
|
||||
mount_read_only: false,
|
||||
effective_socket_directory_mode: "1777",
|
||||
effective_mount_read_only: false,
|
||||
wsl: false,
|
||||
strategy: "direct",
|
||||
fallback_reason: null,
|
||||
xvfb_stderr_bytes: 0,
|
||||
xvfb_stderr_truncated: false,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const processResult = (
|
||||
value: HopperStartupDiagnostic,
|
||||
overrides: Partial<LinuxPrivateDisplayProbeProcessResult> = {},
|
||||
): LinuxPrivateDisplayProbeProcessResult => ({
|
||||
exitCode: value.status === "ready" ? 0 : failureExit(value.failure_code),
|
||||
stderr: `${LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX}${JSON.stringify(value)}\n`,
|
||||
stderrBytes: 0,
|
||||
stderrTruncated: false,
|
||||
timedOut: false,
|
||||
cancelled: false,
|
||||
cleanupIncomplete: false,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const failureExit = (code: HopperStartupDiagnostic["failure_code"]): number =>
|
||||
code === "x11_socket_directory_unusable"
|
||||
? 80
|
||||
: code === "runtime_dependency_unavailable"
|
||||
? 79
|
||||
: 70;
|
||||
|
||||
describe("Linux private display selection", () => {
|
||||
it("prefers a successful direct Xvfb probe", async () => {
|
||||
const calls: LinuxPrivateDisplayRunnableStrategy[] = [];
|
||||
const runProbe: LinuxPrivateDisplayProbeRunner = (strategy) => {
|
||||
calls.push(strategy);
|
||||
return Promise.resolve(processResult(diagnostic({ strategy })));
|
||||
};
|
||||
|
||||
await expect(
|
||||
selectLinuxPrivateDisplayStrategy({ helperPath, runProbe }),
|
||||
).resolves.toMatchObject({ ok: true, strategy: "direct" });
|
||||
expect(calls).toEqual(["direct"]);
|
||||
});
|
||||
|
||||
it("uses a private mount namespace only for the exact socket conflict", async () => {
|
||||
const calls: LinuxPrivateDisplayRunnableStrategy[] = [];
|
||||
const runProbe: LinuxPrivateDisplayProbeRunner = (strategy) => {
|
||||
calls.push(strategy);
|
||||
return Promise.resolve(
|
||||
strategy === "direct"
|
||||
? processResult(
|
||||
diagnostic({
|
||||
strategy,
|
||||
status: "error",
|
||||
failure_code: "x11_socket_directory_unusable",
|
||||
reason: "socket_directory_read_only",
|
||||
socket_directory_mode: "0777",
|
||||
mount_read_only: true,
|
||||
effective_socket_directory_mode: "0777",
|
||||
effective_mount_read_only: true,
|
||||
wsl: true,
|
||||
}),
|
||||
)
|
||||
: processResult(diagnostic({ strategy, wsl: true })),
|
||||
);
|
||||
};
|
||||
|
||||
const selected = await selectLinuxPrivateDisplayStrategy({
|
||||
helperPath,
|
||||
runProbe,
|
||||
});
|
||||
expect(selected).toMatchObject({
|
||||
ok: true,
|
||||
strategy: "user-mount-namespace",
|
||||
diagnostic: {
|
||||
socket_directory_mode: "0777",
|
||||
mount_read_only: true,
|
||||
effective_socket_directory_mode: "1777",
|
||||
effective_mount_read_only: false,
|
||||
wsl: true,
|
||||
},
|
||||
});
|
||||
expect(calls).toEqual(["direct", "user-mount-namespace"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["missing_xvfb", "runtime_dependency_unavailable", 79],
|
||||
["address_collision", "private_display_unavailable", 70],
|
||||
] as const)(
|
||||
"does not mask deterministic direct failure %s with a namespace probe",
|
||||
async (reason, failureCode, exitCode) => {
|
||||
const calls: LinuxPrivateDisplayRunnableStrategy[] = [];
|
||||
const runProbe: LinuxPrivateDisplayProbeRunner = (strategy) => {
|
||||
calls.push(strategy);
|
||||
return Promise.resolve(
|
||||
processResult(
|
||||
diagnostic({
|
||||
strategy,
|
||||
status: "error",
|
||||
failure_code: failureCode,
|
||||
reason,
|
||||
}),
|
||||
{ exitCode },
|
||||
),
|
||||
);
|
||||
};
|
||||
await expect(
|
||||
selectLinuxPrivateDisplayStrategy({ helperPath, runProbe }),
|
||||
).resolves.toMatchObject({ ok: false, exitCode });
|
||||
expect(calls).toEqual(["direct"]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
[
|
||||
"malformed",
|
||||
`${LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX}not-json`,
|
||||
false,
|
||||
"diagnostic_malformed",
|
||||
],
|
||||
[
|
||||
"oversized",
|
||||
`${LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX}${"x".repeat(70_000)}`,
|
||||
true,
|
||||
"diagnostic_truncated",
|
||||
],
|
||||
] as const)(
|
||||
"rejects %s helper diagnostics",
|
||||
async (_name, stderr, stderrTruncated, reason) => {
|
||||
const runProbe: LinuxPrivateDisplayProbeRunner = () =>
|
||||
Promise.resolve({
|
||||
...processResult(diagnostic()),
|
||||
exitCode: 70,
|
||||
stderr,
|
||||
stderrTruncated,
|
||||
});
|
||||
await expect(
|
||||
selectLinuxPrivateDisplayStrategy({ helperPath, runProbe }),
|
||||
).resolves.toMatchObject({
|
||||
ok: false,
|
||||
diagnostic: { reason },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("reports missing helper dependencies without exposing raw stderr", () => {
|
||||
for (const [option, reason] of [
|
||||
["--xauth", "missing_xauth"],
|
||||
["--xvfb", "missing_xvfb"],
|
||||
] as const) {
|
||||
const result = spawnSync(
|
||||
"/usr/bin/python3",
|
||||
[helperPath, "--probe", option, "/rea/missing-executable"],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
expect(result.status).toBe(79);
|
||||
const parsed = parseLinuxPrivateDisplayDiagnostic(result.stderr, false);
|
||||
expect(parsed).toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
status: "error",
|
||||
failure_code: "runtime_dependency_unavailable",
|
||||
reason,
|
||||
},
|
||||
});
|
||||
expect(result.stderr).not.toContain("Traceback");
|
||||
}
|
||||
});
|
||||
|
||||
it("kills the owned probe group when its absolute deadline expires", async () => {
|
||||
const result = await selectLinuxPrivateDisplayStrategy({
|
||||
helperPath: hangingHelperPath,
|
||||
timeoutMs: 75,
|
||||
runProbe: runLinuxPrivateDisplayProbe,
|
||||
});
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
diagnostic: { reason: "probe_timeout" },
|
||||
});
|
||||
const processes = spawnSync("/bin/ps", ["-eo", "args="], {
|
||||
encoding: "utf8",
|
||||
}).stdout;
|
||||
expect(processes).not.toContain(hangingHelperPath);
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,11 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import type { PermissionAuthority } from "../src/application/PermissionAuthority.js";
|
||||
import type { ProjectPermissionStore } from "../src/application/ProjectPermissionStore.js";
|
||||
import type { PermissionGrant } from "../src/domain/permissionPolicy.js";
|
||||
@@ -139,7 +140,7 @@ describe("runtime permission reload", () => {
|
||||
});
|
||||
|
||||
const reloadFixture = async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-main-reload-"));
|
||||
const directory = await createTestTempDirectory("rea-main-reload-");
|
||||
directories.push(directory);
|
||||
const oldRoot = join(directory, "old");
|
||||
const newRoot = join(directory, "new");
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { runProviderAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import type { AnalysisExecution } from "../src/application/AnalysisProvider.js";
|
||||
import {
|
||||
@@ -569,7 +570,7 @@ describe("managed PE/CLI static provider", () => {
|
||||
});
|
||||
|
||||
it("executes as a read-only auxiliary provider with digest, cancellation, and format boundaries", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-provider-"));
|
||||
const directory = await createTestTempDirectory("rea-managed-provider-");
|
||||
const bytes = buildManagedPeFixture();
|
||||
const path = join(directory, "fixture.exe");
|
||||
await writeFile(path, bytes);
|
||||
@@ -646,7 +647,7 @@ describe("managed PE/CLI static provider", () => {
|
||||
});
|
||||
|
||||
it("has the same evidence shape through direct CLI analysis plumbing", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-cli-"));
|
||||
const directory = await createTestTempDirectory("rea-managed-cli-");
|
||||
const path = join(directory, "fixture.exe");
|
||||
await writeFile(path, buildManagedPeFixture());
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { buildManagedPeFixture } from "../scripts/lib/managed-pe-fixture.mjs";
|
||||
import { parseBinaryTarget } from "../src/domain/binaryTarget.js";
|
||||
|
||||
@@ -17,7 +18,7 @@ afterEach(async () => {
|
||||
|
||||
describe("managed conformance fixture", () => {
|
||||
it("emits PE32+ headers when the COFF machine is x86-64", async () => {
|
||||
const workspace = await mkdtemp(join(tmpdir(), "rea-managed-fixture-"));
|
||||
const workspace = await createTestTempDirectory("rea-managed-fixture-");
|
||||
workspaces.push(workspace);
|
||||
const path = join(workspace, "fixture.exe");
|
||||
await writeFile(path, buildManagedPeFixture({ machine: 0x8664 }));
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
@@ -7,6 +6,8 @@ import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { AnalysisProviderRegistry } from "../src/application/AnalysisProviderRegistry.js";
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { createPermissionAuthority } from "../src/application/PermissionAuthority.js";
|
||||
@@ -19,7 +20,7 @@ import { buildManagedPeFixture } from "./fixtures/managedPe.js";
|
||||
|
||||
describe("managed artifact MCP tools", () => {
|
||||
it("opens a managed PE and executes the managed static provider through MCP", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-mcp-"));
|
||||
const directory = await createTestTempDirectory("rea-managed-mcp-");
|
||||
const path = join(directory, "fixture.exe");
|
||||
const rightPath = join(directory, "fixture-renamed.exe");
|
||||
const runtimePath = join(directory, "dotnet");
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { compareManagedMemberPaths } from "../src/application/ManagedMemberComparisonService.js";
|
||||
import { MANAGED_STATIC_PROVIDER } from "../src/application/InvestigationProviders.js";
|
||||
import {
|
||||
@@ -256,7 +257,7 @@ describe("managed member comparison", () => {
|
||||
});
|
||||
|
||||
it("compares two local paths and returns derived Evidence", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-compare-"));
|
||||
const directory = await createTestTempDirectory("rea-managed-compare-");
|
||||
const leftPath = join(directory, "left.dll");
|
||||
const rightPath = join(directory, "right.dll");
|
||||
await writeFile(leftPath, buildManagedPeFixture());
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
planManagedRuntimeCorrelationEvidence,
|
||||
type ManagedRuntimePolicy,
|
||||
@@ -54,7 +55,7 @@ describe("managed runtime correlation planning", () => {
|
||||
});
|
||||
|
||||
it("requires an explicit managed_runtime grant under an enabled ceiling", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-runtime-"));
|
||||
const directory = await createTestTempDirectory("rea-managed-runtime-");
|
||||
const artifactPath = join(directory, "fixture.dll");
|
||||
const executablePath = join(directory, "dotnet");
|
||||
await writeFile(artifactPath, buildManagedPeFixture());
|
||||
@@ -75,7 +76,7 @@ describe("managed runtime correlation planning", () => {
|
||||
});
|
||||
|
||||
it("records an exact-build non-executing admission plan when authorized", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-runtime-"));
|
||||
const directory = await createTestTempDirectory("rea-managed-runtime-");
|
||||
const artifactPath = join(directory, "fixture.dll");
|
||||
const executablePath = join(directory, "dotnet");
|
||||
await writeFile(artifactPath, buildManagedPeFixture());
|
||||
@@ -121,7 +122,7 @@ describe("managed runtime correlation planning", () => {
|
||||
});
|
||||
|
||||
it("rejects a method lock that no longer matches static Evidence", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-runtime-"));
|
||||
const directory = await createTestTempDirectory("rea-managed-runtime-");
|
||||
const artifactPath = join(directory, "fixture.dll");
|
||||
const executablePath = join(directory, "dotnet");
|
||||
await writeFile(artifactPath, buildManagedPeFixture());
|
||||
@@ -148,7 +149,7 @@ describe("managed runtime correlation planning", () => {
|
||||
});
|
||||
|
||||
it("rejects a runtime lock for instruction-limited CIL", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-runtime-"));
|
||||
const directory = await createTestTempDirectory("rea-managed-runtime-");
|
||||
const artifactPath = join(directory, "fixture.dll");
|
||||
const executablePath = join(directory, "dotnet");
|
||||
const bytes = buildManagedPeFixture();
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import { readFile, rm } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { compareInventory, runProductionMcpDoctor } from "../src/mcpDoctor.js";
|
||||
import { CATALOG_IDENTITY } from "../src/catalogIdentity.js";
|
||||
|
||||
const temporary: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporary
|
||||
.splice(0)
|
||||
.map((path) => rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
describe("production MCP doctor", () => {
|
||||
it("connects to the production stdio child and verifies the canonical catalog", async () => {
|
||||
const result = await runProductionMcpDoctor({
|
||||
command: process.execPath,
|
||||
args: [resolve("scripts/rea.mjs"), "mcp"],
|
||||
cwd: process.cwd(),
|
||||
environment: process.env,
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({
|
||||
healthy: true,
|
||||
adapter: "production-stdio",
|
||||
inventory: {
|
||||
tools: {
|
||||
expected: CATALOG_IDENTITY.counts.mcp_tools,
|
||||
observed: CATALOG_IDENTITY.counts.mcp_tools,
|
||||
missing: [],
|
||||
unexpected: [],
|
||||
},
|
||||
},
|
||||
request_flow: { tool: "binary_session", ok: true },
|
||||
});
|
||||
}, 30_000);
|
||||
|
||||
it("reports exact missing, unexpected, and duplicate inventory names", () => {
|
||||
expect(compareInventory(["a", "b"], ["b", "c", "c"])).toEqual({
|
||||
expected: 2,
|
||||
observed: 3,
|
||||
missing: ["a"],
|
||||
unexpected: ["c"],
|
||||
duplicates: ["c"],
|
||||
});
|
||||
});
|
||||
|
||||
it("captures startup exit diagnostics", async () => {
|
||||
const result = await runProductionMcpDoctor({
|
||||
command: process.execPath,
|
||||
args: [resolve("tests/fixtures/mcpDoctorExit.mjs")],
|
||||
cwd: process.cwd(),
|
||||
environment: process.env,
|
||||
deadlineMs: 2_000,
|
||||
});
|
||||
expect(result).toMatchObject({
|
||||
healthy: false,
|
||||
checks: [{ name: "transport", ok: false }],
|
||||
diagnostics: { stderr: expect.stringContaining("startup exit") },
|
||||
});
|
||||
});
|
||||
|
||||
it("kills a child that misses the absolute startup deadline", async () => {
|
||||
const root = await createTestTempDirectory("rea-mcp-doctor-");
|
||||
temporary.push(root);
|
||||
const pidPath = join(root, "pid");
|
||||
const result = await runProductionMcpDoctor({
|
||||
command: process.execPath,
|
||||
args: [resolve("tests/fixtures/mcpDoctorHang.mjs")],
|
||||
cwd: process.cwd(),
|
||||
environment: { ...process.env, REA_MCP_DOCTOR_PID_PATH: pidPath },
|
||||
deadlineMs: 250,
|
||||
});
|
||||
expect(result.healthy).toBe(false);
|
||||
const pid = Number.parseInt(await readFile(pidPath, "utf8"), 10);
|
||||
await expect(waitForExit(pid)).resolves.toBeUndefined();
|
||||
}, 10_000);
|
||||
});
|
||||
|
||||
const waitForExit = async (pid: number): Promise<void> => {
|
||||
for (let attempt = 0; attempt < 50; attempt += 1) {
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
} catch (cause: unknown) {
|
||||
if (
|
||||
cause instanceof Error &&
|
||||
"code" in cause &&
|
||||
(cause as NodeJS.ErrnoException).code === "ESRCH"
|
||||
)
|
||||
return;
|
||||
throw cause;
|
||||
}
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, 20));
|
||||
}
|
||||
throw new Error(`MCP doctor fixture process ${String(pid)} remained alive`);
|
||||
};
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, mkdir, rm, writeFile, readFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, rm, writeFile, readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { NativeMacOSProvider } from "../src/native/NativeMacOSProvider.js";
|
||||
import {
|
||||
NativeCommandFailure,
|
||||
@@ -132,7 +133,7 @@ describe("native macOS provider", () => {
|
||||
});
|
||||
|
||||
it("supports architectures, signatures, plists, and ordered demangling", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-native-"));
|
||||
directory = await createTestTempDirectory("rea-native-");
|
||||
const app = join(directory, "Fixture.app");
|
||||
const executable = join(app, "Contents/MacOS/Fixture");
|
||||
await mkdir(join(app, "Contents/MacOS"), { recursive: true });
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFile, realpath, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
executeNodeCharacterization,
|
||||
prepareNodeCharacterization,
|
||||
@@ -141,7 +142,7 @@ describe("Node runtime characterization", () => {
|
||||
});
|
||||
|
||||
const createFixture = async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-characterization-"));
|
||||
const root = await createTestTempDirectory("rea-characterization-");
|
||||
roots.push(root);
|
||||
const path = join(root, "bundle.js");
|
||||
const source = "const hidden = (value) => value.trim();";
|
||||
|
||||
@@ -26,6 +26,14 @@ describe("package installation workflows", () => {
|
||||
expect(workflow).not.toContain("npm run rebuild:native");
|
||||
for (const workflow of [realHopperLinux, realHopperMac])
|
||||
expect(workflow).toContain("npm install --global --ignore-scripts");
|
||||
for (const workflow of [realHopperLinux, realHopperMac])
|
||||
expect(workflow).toContain(
|
||||
"REA_HOPPER_CONFORMANCE_MANIFEST_PATH: ${{ github.workspace }}/build/conformance/manifest.json",
|
||||
);
|
||||
expect(realHopperLinux).not.toContain("HOPPER_TARGET_PATH");
|
||||
expect(realHopperLinux).not.toContain("HOPPER_SECOND_TARGET_PATH");
|
||||
expect(realHopperLinux).not.toContain("first_target");
|
||||
expect(realHopperLinux).not.toContain("second_target");
|
||||
});
|
||||
|
||||
it("verifies the package before publish and runs published canaries outside the checkout", async () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { mkdtemp, mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
canonicalizePermissionCeilings,
|
||||
canonicalizePermissionRequest,
|
||||
@@ -19,8 +19,8 @@ import {
|
||||
|
||||
describe("permission authority", () => {
|
||||
it("distinguishes an elicitable grant from administrator reconfiguration", async () => {
|
||||
const sandbox = await mkdtemp(
|
||||
join(tmpdir(), "rea-permission-remediation-"),
|
||||
const sandbox = await createTestTempDirectory(
|
||||
"rea-permission-remediation-",
|
||||
);
|
||||
const allowedRoot = join(sandbox, "allowed");
|
||||
const outsideRoot = join(sandbox, "outside");
|
||||
@@ -59,7 +59,7 @@ describe("permission authority", () => {
|
||||
});
|
||||
|
||||
it("accepts canonical aliases but rejects a symlink escape", async () => {
|
||||
const sandbox = await mkdtemp(join(tmpdir(), "rea-permission-"));
|
||||
const sandbox = await createTestTempDirectory("rea-permission-");
|
||||
const root = join(sandbox, "root");
|
||||
const outside = join(sandbox, "outside");
|
||||
await Promise.all([mkdir(root), mkdir(outside)]);
|
||||
@@ -125,7 +125,7 @@ describe("permission authority", () => {
|
||||
});
|
||||
|
||||
it("canonicalizes a new write through its existing parent", async () => {
|
||||
const sandbox = await mkdtemp(join(tmpdir(), "rea-permission-write-"));
|
||||
const sandbox = await createTestTempDirectory("rea-permission-write-");
|
||||
const result = await canonicalizePermissionRequest(
|
||||
{
|
||||
capability: "evidence_write",
|
||||
@@ -145,7 +145,7 @@ describe("permission authority", () => {
|
||||
});
|
||||
|
||||
it("commits a configured policy only after every grant validates", async () => {
|
||||
const sandbox = await mkdtemp(join(tmpdir(), "rea-permission-reload-"));
|
||||
const sandbox = await createTestTempDirectory("rea-permission-reload-");
|
||||
const oldRoot = join(sandbox, "old");
|
||||
const newRoot = join(sandbox, "new");
|
||||
const outsideRoot = join(sandbox, "outside");
|
||||
@@ -189,7 +189,7 @@ describe("permission authority", () => {
|
||||
});
|
||||
|
||||
it("isolates transient grants and consumption between live connections", async () => {
|
||||
const sandbox = await mkdtemp(join(tmpdir(), "rea-permission-session-"));
|
||||
const sandbox = await createTestTempDirectory("rea-permission-session-");
|
||||
const scope = evidenceScope(sandbox);
|
||||
const configured = await createPermissionAuthority([scope]);
|
||||
expect(configured.ok).toBe(true);
|
||||
@@ -254,8 +254,8 @@ describe("permission authority", () => {
|
||||
});
|
||||
|
||||
it("applies configured policy reloads to existing connections", async () => {
|
||||
const sandbox = await mkdtemp(
|
||||
join(tmpdir(), "rea-permission-live-reload-"),
|
||||
const sandbox = await createTestTempDirectory(
|
||||
"rea-permission-live-reload-",
|
||||
);
|
||||
const allowedRoot = join(sandbox, "allowed");
|
||||
const replacementRoot = join(sandbox, "replacement");
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFile, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import WebSocket from "ws";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { startLoopbackReplay } from "../src/application/LoopbackReplay.js";
|
||||
import {
|
||||
captureProcessScenario,
|
||||
@@ -814,7 +815,7 @@ describe("process capture adapter", () => {
|
||||
});
|
||||
|
||||
it("captures PTY, filesystem, descendants, HTTP replay, and redacts environment", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-harness-test-"));
|
||||
const root = await createTestTempDirectory("rea-harness-test-");
|
||||
const script = join(root, "fixture.mjs");
|
||||
await writeFile(
|
||||
script,
|
||||
@@ -889,7 +890,7 @@ describe("process capture adapter", () => {
|
||||
});
|
||||
|
||||
it("renders terminal state, records shim invocations, and captures literal checkpoints", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-v3-test-"));
|
||||
const root = await createTestTempDirectory("rea-v3-test-");
|
||||
const script = join(root, "scenario.mjs");
|
||||
await writeFile(
|
||||
script,
|
||||
@@ -979,7 +980,7 @@ describe("process capture adapter", () => {
|
||||
}, 20_000);
|
||||
|
||||
it("does not follow or disclose symlink targets outside declared roots", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-symlink-test-"));
|
||||
const root = await createTestTempDirectory("rea-symlink-test-");
|
||||
await symlink("/etc/passwd", join(root, "escape"));
|
||||
try {
|
||||
const capability = await probeProcessCaptureCapability();
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { isInputRequiredResult } from "@modelcontextprotocol/server";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { mkdir, rm } from "node:fs/promises";
|
||||
import { dirname } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { PermissionAuthority } from "../src/application/PermissionAuthority.js";
|
||||
import { createPermissionPolicy } from "../src/domain/permissionPolicy.js";
|
||||
@@ -31,7 +32,7 @@ const now = Date.parse("2026-07-18T00:00:00.000Z");
|
||||
|
||||
describe("process-capture MCP elicitation", () => {
|
||||
it("completes signed consent through the modern MCP client and server", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-elicit-mcp-"));
|
||||
const root = await createTestTempDirectory("rea-elicit-mcp-");
|
||||
const authority = new PermissionAuthority(
|
||||
createPermissionPolicy([
|
||||
{
|
||||
@@ -386,7 +387,7 @@ describe("process-capture MCP elicitation", () => {
|
||||
it.each(["result", "throw"] as const)(
|
||||
"revokes an elicited grant when final authorization ends with %s",
|
||||
async (failure) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-elicit-rollback-"));
|
||||
const root = await createTestTempDirectory("rea-elicit-rollback-");
|
||||
const scoped = { ...request, roots: [root] };
|
||||
const policy = createPermissionPolicy([
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { mkdtemp, open, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { open, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { execFile } from "node:child_process";
|
||||
@@ -7,6 +6,8 @@ import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
captureProcessScenarioFile,
|
||||
compareProcessEvidenceFiles,
|
||||
@@ -26,7 +27,7 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
const fixture = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-process-cli-"));
|
||||
const root = await createTestTempDirectory("rea-process-cli-");
|
||||
roots.push(root);
|
||||
return root;
|
||||
};
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { SUPPORTED_CLIENT_DEFINITIONS } from "../src/application/SupportedClients.js";
|
||||
import {
|
||||
ARTIFACT_GRAPH_PROVIDER,
|
||||
@@ -113,6 +114,7 @@ describe("canonical product catalog", () => {
|
||||
).toEqual([
|
||||
"commit_reconstruction_coverage",
|
||||
"compare_application_versions",
|
||||
"compare_javascript_export_shapes",
|
||||
"execute_node_characterization",
|
||||
"prepare_node_characterization",
|
||||
"query_reconstruction_coverage",
|
||||
@@ -220,7 +222,7 @@ describe("canonical product catalog", () => {
|
||||
});
|
||||
|
||||
it("fails check mode without rewriting a stale generated artifact", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-generated-check-"));
|
||||
const directory = await createTestTempDirectory("rea-generated-check-");
|
||||
temporaryRoots.push(directory);
|
||||
const path = join(directory, "catalog.json");
|
||||
await writeFile(path, "stale\n", "utf8");
|
||||
@@ -245,7 +247,7 @@ describe("canonical product catalog", () => {
|
||||
});
|
||||
|
||||
it("accepts and preserves native generated-file line endings", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-generated-eol-"));
|
||||
const directory = await createTestTempDirectory("rea-generated-eol-");
|
||||
temporaryRoots.push(directory);
|
||||
const path = join(directory, "catalog.json");
|
||||
await writeFile(path, "current\r\n", "utf8");
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { chmod, mkdtemp, stat, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { chmod, stat, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
readProjectPermissionStore,
|
||||
revokeProjectPermissionGrant,
|
||||
@@ -12,7 +13,7 @@ import {
|
||||
|
||||
describe("project permission store", () => {
|
||||
it("persists explicit project grants atomically with owner-only permissions", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-project-"));
|
||||
const project = await createTestTempDirectory("rea-policy-project-");
|
||||
const path = join(project, ".rea", "permissions.json");
|
||||
const grant = {
|
||||
grant_id: "project:evidence-read",
|
||||
@@ -38,7 +39,7 @@ describe("project permission store", () => {
|
||||
});
|
||||
|
||||
it("rejects stores readable by another user class", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-mode-"));
|
||||
const project = await createTestTempDirectory("rea-policy-mode-");
|
||||
const path = join(project, "permissions.json");
|
||||
const written = await writeProjectPermissionStore(path, project, []);
|
||||
expect(written.ok).toBe(true);
|
||||
@@ -51,8 +52,8 @@ describe("project permission store", () => {
|
||||
});
|
||||
|
||||
it("binds grants to canonical project identity", async () => {
|
||||
const first = await mkdtemp(join(tmpdir(), "rea-policy-first-"));
|
||||
const second = await mkdtemp(join(tmpdir(), "rea-policy-second-"));
|
||||
const first = await createTestTempDirectory("rea-policy-first-");
|
||||
const second = await createTestTempDirectory("rea-policy-second-");
|
||||
const path = join(first, "permissions.json");
|
||||
expect((await writeProjectPermissionStore(path, first, [])).ok).toBe(true);
|
||||
|
||||
@@ -63,7 +64,7 @@ describe("project permission store", () => {
|
||||
});
|
||||
|
||||
it("rejects a symlink even when its target is owner-only", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-symlink-"));
|
||||
const project = await createTestTempDirectory("rea-policy-symlink-");
|
||||
const target = join(project, "target.json");
|
||||
const path = join(project, "permissions.json");
|
||||
expect((await writeProjectPermissionStore(target, project, [])).ok).toBe(
|
||||
@@ -78,7 +79,7 @@ describe("project permission store", () => {
|
||||
});
|
||||
|
||||
it("round-trips managed runtime project grants", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-managed-"));
|
||||
const project = await createTestTempDirectory("rea-policy-managed-");
|
||||
const path = join(project, "permissions.json");
|
||||
const grant = {
|
||||
grant_id: "project:managed-runtime",
|
||||
@@ -103,7 +104,7 @@ describe("project permission store", () => {
|
||||
});
|
||||
|
||||
it("classifies malformed JSON as an invalid store", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-invalid-"));
|
||||
const project = await createTestTempDirectory("rea-policy-invalid-");
|
||||
const path = join(project, "permissions.json");
|
||||
await writeFile(path, "{", { mode: 0o600 });
|
||||
|
||||
@@ -114,7 +115,7 @@ describe("project permission store", () => {
|
||||
});
|
||||
|
||||
it("serializes concurrent grant revocations without losing an update", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-revoke-"));
|
||||
const project = await createTestTempDirectory("rea-policy-revoke-");
|
||||
const path = join(project, ".rea", "permissions.json");
|
||||
const grant = (grantId: string) => ({
|
||||
grant_id: grantId,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import type { AnalysisClient } from "../src/application/AnalysisProvider.js";
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { ARTIFACT_COMPARISON_EXAMPLE } from "../src/contracts/artifactComparisonExample.js";
|
||||
@@ -23,7 +24,7 @@ describe("guided prompt completion", () => {
|
||||
it("reads live documents and paged procedures without ambiguous names", async () => {
|
||||
const requests: Array<Readonly<Record<string, unknown>>> = [];
|
||||
const session = new BinarySession(() => client(requests));
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-prompt-completion-"));
|
||||
directory = await createTestTempDirectory("rea-prompt-completion-");
|
||||
const target = join(directory, "fixture.hop");
|
||||
await writeFile(target, "fixture");
|
||||
expect((await session.open(target)).ok).toBe(true);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { basename, join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { McpServer } from "@modelcontextprotocol/server";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import type { AnalysisClient } from "../src/application/AnalysisProvider.js";
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { PROMPT_CONTRACTS } from "../src/contracts/promptContracts.js";
|
||||
@@ -274,7 +275,7 @@ describe("guided prompts over MCP", () => {
|
||||
});
|
||||
|
||||
it("refreshes wire completions across open, switch, concurrency, and close", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-prompt-mcp-"));
|
||||
const directory = await createTestTempDirectory("rea-prompt-mcp-");
|
||||
temporaryDirectories.push(directory);
|
||||
const first = join(directory, "first.hop");
|
||||
const second = join(directory, "second.hop");
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
createAnalysisExecution,
|
||||
type AnalysisClient,
|
||||
@@ -322,7 +323,7 @@ const capability = (
|
||||
});
|
||||
|
||||
const databaseTarget = async (): Promise<string> => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-provider-binding-"));
|
||||
directory = await createTestTempDirectory("rea-provider-binding-");
|
||||
const path = join(directory, "fixture.hop");
|
||||
await writeFile(path, "fixture");
|
||||
return path;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
@@ -7,6 +6,8 @@ import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
createAnalysisExecution,
|
||||
type AnalysisProviderCandidate,
|
||||
@@ -32,7 +33,7 @@ afterEach(async () => {
|
||||
|
||||
describe("provider selection over MCP", () => {
|
||||
it("keeps open_binary and binary_session binding semantics exact", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-provider-mcp-"));
|
||||
directory = await createTestTempDirectory("rea-provider-mcp-");
|
||||
const target = join(directory, "fixture.hop");
|
||||
await writeFile(target, "fixture");
|
||||
const starts: string[] = [];
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFile, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { loadRealHopperFixtureTargets } from "../scripts/lib/real-hopper-fixture.mjs";
|
||||
|
||||
let root: string | undefined;
|
||||
@@ -46,7 +47,7 @@ describe("real Hopper fixture binding", () => {
|
||||
/digest/u,
|
||||
);
|
||||
|
||||
const outside = await mkdtemp(join(tmpdir(), "rea-hopper-outside-"));
|
||||
const outside = await createTestTempDirectory("rea-hopper-outside-");
|
||||
try {
|
||||
await writeFile(join(outside, "c"), "primary");
|
||||
await rm(join(root ?? "", "c"));
|
||||
@@ -79,7 +80,7 @@ describe("real Hopper fixture binding", () => {
|
||||
});
|
||||
|
||||
const fixtureManifest = async (): Promise<string> => {
|
||||
root = await mkdtemp(join(tmpdir(), "rea-hopper-fixture-"));
|
||||
root = await createTestTempDirectory("rea-hopper-fixture-");
|
||||
const primary = Buffer.from("primary");
|
||||
const secondary = Buffer.from("secondary");
|
||||
await Promise.all([
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
readReconstructionCoverageWorkspace,
|
||||
writeReconstructionCoverageWorkspace,
|
||||
@@ -385,7 +386,7 @@ describe("reconstruction coverage closure", () => {
|
||||
});
|
||||
|
||||
it("persists owner-only revisions with CAS and digest-chain enforcement", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-coverage-workspace-"));
|
||||
const root = await createTestTempDirectory("rea-coverage-workspace-");
|
||||
const path = join(root, "coverage.json");
|
||||
const first = completeWorkspace();
|
||||
const filePolicy: EvidenceFilePolicy = {
|
||||
@@ -426,7 +427,7 @@ describe("reconstruction coverage closure", () => {
|
||||
});
|
||||
|
||||
it("shares commit and fail-closed query behavior across adapters", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-coverage-service-"));
|
||||
const root = await createTestTempDirectory("rea-coverage-service-");
|
||||
const path = join(root, "coverage.json");
|
||||
const workspace = completeWorkspace();
|
||||
const filePolicy: EvidenceFilePolicy = {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { INVESTIGATION_EXAMPLES } from "../src/contracts/investigationExamples.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
@@ -21,7 +22,7 @@ const digest = (character: string): string => character.repeat(64);
|
||||
|
||||
describe("reconstruction coverage MCP parity", () => {
|
||||
it("commits and queries the same evidence-backed fail-closed workspace", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-coverage-mcp-"));
|
||||
const root = await createTestTempDirectory("rea-coverage-mcp-");
|
||||
const path = join(root, "coverage.json");
|
||||
const policy = {
|
||||
roots: [root],
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import fs from "node:fs";
|
||||
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { add, commit, init } from "isomorphic-git";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
importReferenceSource,
|
||||
normalizeHistoricalSourceParseFailures,
|
||||
@@ -123,7 +124,7 @@ describe("reference source import", () => {
|
||||
});
|
||||
|
||||
it("is relocation-stable, resolves imports, and excludes secrets before capture", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-reference-import-"));
|
||||
const parent = await createTestTempDirectory("rea-reference-import-");
|
||||
try {
|
||||
const leftRoot = await fixture(parent, "left");
|
||||
const rightRoot = await fixture(parent, "right");
|
||||
@@ -157,8 +158,8 @@ describe("reference source import", () => {
|
||||
});
|
||||
|
||||
it("fails closed outside policy and honors cancellation", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-reference-policy-"));
|
||||
const outside = await mkdtemp(join(tmpdir(), "rea-reference-outside-"));
|
||||
const parent = await createTestTempDirectory("rea-reference-policy-");
|
||||
const outside = await createTestTempDirectory("rea-reference-outside-");
|
||||
try {
|
||||
const root = await fixture(outside, "tree");
|
||||
const denied = await importTree(root, parent);
|
||||
@@ -182,7 +183,7 @@ describe("reference source import", () => {
|
||||
});
|
||||
|
||||
it("uses a valid reference root when another configured root is missing", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-reference-roots-"));
|
||||
const parent = await createTestTempDirectory("rea-reference-roots-");
|
||||
try {
|
||||
const root = await fixture(parent, "tree");
|
||||
const imported = await importTree(root, [
|
||||
@@ -196,7 +197,7 @@ describe("reference source import", () => {
|
||||
});
|
||||
|
||||
it("records bounded local Git state without invoking Git", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-reference-git-"));
|
||||
const parent = await createTestTempDirectory("rea-reference-git-");
|
||||
try {
|
||||
const root = await fixture(parent, "repo");
|
||||
await init({ fs, dir: root, defaultBranch: "main" });
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { mkdtemp, mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { readReferenceSource } from "../src/reference/ReferenceSourceReader.js";
|
||||
|
||||
const limits = {
|
||||
@@ -14,7 +16,7 @@ const limits = {
|
||||
|
||||
describe("readReferenceSource", () => {
|
||||
it("returns explicit entries in canonical code-point path order", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-reference-"));
|
||||
const root = await createTestTempDirectory("rea-reference-");
|
||||
await mkdir(join(root, "nested"));
|
||||
await writeFile(join(root, "z.js"), "z");
|
||||
await writeFile(join(root, "a.js"), "a");
|
||||
@@ -49,8 +51,8 @@ describe("readReferenceSource", () => {
|
||||
});
|
||||
|
||||
it("sanitizes internal, external, and missing symlink targets", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-reference-"));
|
||||
const outside = await mkdtemp(join(tmpdir(), "rea-outside-"));
|
||||
const root = await createTestTempDirectory("rea-reference-");
|
||||
const outside = await createTestTempDirectory("rea-outside-");
|
||||
await writeFile(join(outside, "secret"), "secret");
|
||||
await writeFile(join(root, "local"), "local");
|
||||
await symlink("local", join(root, "internal"));
|
||||
@@ -96,7 +98,7 @@ describe("readReferenceSource", () => {
|
||||
});
|
||||
|
||||
it("makes byte, file, depth, and path limits explicit per entry", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-reference-"));
|
||||
const root = await createTestTempDirectory("rea-reference-");
|
||||
await writeFile(join(root, "a"), "too large");
|
||||
await writeFile(join(root, "b"), "b");
|
||||
await mkdir(join(root, "deep"));
|
||||
@@ -130,7 +132,7 @@ describe("readReferenceSource", () => {
|
||||
});
|
||||
|
||||
it("applies maxEntries as a global limit across every entry kind", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-reference-"));
|
||||
const root = await createTestTempDirectory("rea-reference-");
|
||||
await writeFile(join(root, "a"), "a");
|
||||
await writeFile(join(root, "b"), "b");
|
||||
await writeFile(join(root, "c"), "c");
|
||||
@@ -148,7 +150,7 @@ describe("readReferenceSource", () => {
|
||||
});
|
||||
|
||||
it("applies exclusions to normalized paths before reading entries", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-reference-"));
|
||||
const root = await createTestTempDirectory("rea-reference-");
|
||||
await mkdir(join(root, "ignored"));
|
||||
await writeFile(join(root, "ignored", "secret"), "secret");
|
||||
await writeFile(join(root, "kept"), "kept");
|
||||
@@ -168,7 +170,7 @@ describe("readReferenceSource", () => {
|
||||
});
|
||||
|
||||
it("sanitizes exclusion callback failures", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-reference-"));
|
||||
const root = await createTestTempDirectory("rea-reference-");
|
||||
await writeFile(join(root, "file"), "value");
|
||||
const result = await readReferenceSource(root, limits, {
|
||||
shouldExclude: () => {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { chmod, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { chmod, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { delimiter, join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { inspectRuntimeExecutables } from "../src/application/RuntimeExecutableDiagnostics.js";
|
||||
|
||||
const roots: string[] = [];
|
||||
@@ -145,7 +146,7 @@ describe("runtime executable diagnostics", () => {
|
||||
});
|
||||
|
||||
const temporaryRoot = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-runtime-diagnostics-"));
|
||||
const root = await createTestTempDirectory("rea-runtime-diagnostics-");
|
||||
roots.push(root);
|
||||
return root;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
@@ -10,6 +9,8 @@ import {
|
||||
} from "@zip.js/zip.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { runProviderAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import { parseEvidence } from "../src/domain/evidence.js";
|
||||
import {
|
||||
@@ -19,7 +20,7 @@ import {
|
||||
|
||||
describe("runtime identification", () => {
|
||||
it("identifies APK runtime families and exposes missing semantic providers", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-runtime-"));
|
||||
const root = await createTestTempDirectory("rea-runtime-");
|
||||
const path = join(root, "Fixture.apk");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add(
|
||||
@@ -108,7 +109,7 @@ describe("runtime identification", () => {
|
||||
});
|
||||
|
||||
it("reports bounded runtime-observation truncation", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-runtime-limit-"));
|
||||
const root = await createTestTempDirectory("rea-runtime-limit-");
|
||||
const path = join(root, "Fixture.apk");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("one.js", new TextReader("one"));
|
||||
@@ -129,7 +130,7 @@ describe("runtime identification", () => {
|
||||
});
|
||||
|
||||
it("does not route nested DEX content to the APK-only provider", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-runtime-dex-"));
|
||||
const root = await createTestTempDirectory("rea-runtime-dex-");
|
||||
const path = join(root, "Fixture.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add(
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { access, mkdtemp, readFile, readdir } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { access, readFile, readdir } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { SafeOutputTree } from "../src/artifacts/SafeOutputTree.js";
|
||||
|
||||
const LIMITS = {
|
||||
@@ -19,7 +20,7 @@ const LIMITS = {
|
||||
|
||||
describe("safe artifact output tree", () => {
|
||||
it("removes only its owned tree after digest failure and proves absence", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-safe-output-"));
|
||||
const parent = await createTestTempDirectory("rea-safe-output-");
|
||||
const output = join(parent, "published");
|
||||
const tree = await SafeOutputTree.create(output, LIMITS);
|
||||
await expect(
|
||||
@@ -39,7 +40,7 @@ describe("safe artifact output tree", () => {
|
||||
});
|
||||
|
||||
it("publishes files while building and preserves them after sealing", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-safe-output-"));
|
||||
const parent = await createTestTempDirectory("rea-safe-output-");
|
||||
const output = join(parent, "published");
|
||||
const tree = await SafeOutputTree.create(output, LIMITS);
|
||||
const bytes = Buffer.from("visible before seal");
|
||||
@@ -58,7 +59,7 @@ describe("safe artifact output tree", () => {
|
||||
});
|
||||
|
||||
it("returns detached cleanup reports", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-safe-output-"));
|
||||
const parent = await createTestTempDirectory("rea-safe-output-");
|
||||
const tree = await SafeOutputTree.create(join(parent, "published"), LIMITS);
|
||||
const cleanup = await tree.rollback();
|
||||
(cleanup.residualPaths as string[]).push("/forged/path");
|
||||
|
||||
@@ -26,14 +26,14 @@ describe("server and catalog identity", () => {
|
||||
});
|
||||
expect(PRODUCT_IDENTITY.packageVersion).toBe(packageJson.version);
|
||||
expect(SDK_IDENTITY.server).toBe("2.0.0-beta.4");
|
||||
expect(CLI_COMMAND_NAMES).toHaveLength(55);
|
||||
expect(new Set(CLI_COMMAND_NAMES).size).toBe(55);
|
||||
expect(CLI_COMMAND_NAMES).toHaveLength(56);
|
||||
expect(new Set(CLI_COMMAND_NAMES).size).toBe(56);
|
||||
expect(CATALOG_IDENTITY.counts).toEqual({
|
||||
cli_commands: 55,
|
||||
cli_commands: 56,
|
||||
mcp_tools: TOOL_CONTRACTS.length,
|
||||
mcp_prompts: 6,
|
||||
mcp_resources: 2,
|
||||
mcp_resource_templates: 8,
|
||||
mcp_resource_templates: 9,
|
||||
});
|
||||
expect(CATALOG_IDENTITY.digests.combined_sha256).toMatch(/^[a-f0-9]{64}$/u);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFile, realpath, rm, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
@@ -7,6 +6,8 @@ import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { TOOL_CONTRACTS } from "../src/contracts/toolContracts.js";
|
||||
import type { AnalysisClient } from "../src/application/AnalysisProvider.js";
|
||||
@@ -42,7 +43,7 @@ afterEach(async () => {
|
||||
|
||||
describe("target-free MCP lifecycle", () => {
|
||||
it("reopens replaced content at one canonical path through MCP", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-mcp-replaced-target-"));
|
||||
directory = await createTestTempDirectory("rea-mcp-replaced-target-");
|
||||
const targetPath = join(directory, "mutable.hop");
|
||||
await writeFile(targetPath, "first");
|
||||
const closed: string[] = [];
|
||||
@@ -99,7 +100,7 @@ describe("target-free MCP lifecycle", () => {
|
||||
});
|
||||
|
||||
it("reports no-target, opens, analyzes, switches, reports status, and closes", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-mcp-session-"));
|
||||
directory = await createTestTempDirectory("rea-mcp-session-");
|
||||
const first = join(directory, "first.hop");
|
||||
const second = join(directory, "second.hop");
|
||||
await writeFile(first, "one");
|
||||
|
||||
+57
-11
@@ -12,7 +12,11 @@ import {
|
||||
type SetupProgressEvent,
|
||||
type SetupProviderEnvironment,
|
||||
} from "../src/application/Setup.js";
|
||||
import type { DoctorCheck } from "../src/application/Doctor.js";
|
||||
import type {
|
||||
DoctorCheck,
|
||||
DoctorReport,
|
||||
DoctorScope,
|
||||
} from "../src/application/Doctor.js";
|
||||
import type { LinuxDistribution } from "../src/application/LinuxHopper.js";
|
||||
|
||||
class FakeSetupHost implements SetupHost {
|
||||
@@ -33,9 +37,11 @@ class FakeSetupHost implements SetupHost {
|
||||
configurations = 0;
|
||||
skillInstalls = 0;
|
||||
doctorCalls = 0;
|
||||
doctorScopes: Array<DoctorScope | undefined> = [];
|
||||
checkedHopperPaths: Array<string | undefined> = [];
|
||||
configuredProviderEnvironments: SetupProviderEnvironment[] = [];
|
||||
doctorHealthy: boolean | undefined;
|
||||
scopedDoctorHealthy: boolean | undefined;
|
||||
linuxDemoRuntimeMissing = false;
|
||||
unsupportedHopperVersion = false;
|
||||
|
||||
@@ -108,12 +114,9 @@ class FakeSetupHost implements SetupHost {
|
||||
this.skillInstalls += 1;
|
||||
return Promise.resolve(this.skill);
|
||||
};
|
||||
doctor = (): Promise<{
|
||||
healthy: boolean;
|
||||
hopperPath?: string;
|
||||
checks: readonly DoctorCheck[];
|
||||
}> => {
|
||||
doctor = (scope?: DoctorScope): Promise<DoctorReport> => {
|
||||
this.doctorCalls += 1;
|
||||
this.doctorScopes.push(scope);
|
||||
const checks: DoctorCheck[] = [
|
||||
...(this.linuxDemoRuntimeMissing
|
||||
? ([
|
||||
@@ -135,12 +138,27 @@ class FakeSetupHost implements SetupHost {
|
||||
] as const)
|
||||
: []),
|
||||
];
|
||||
const environmentHealthy =
|
||||
this.doctorHealthy ??
|
||||
(this.hopper !== undefined &&
|
||||
!this.linuxDemoRuntimeMissing &&
|
||||
!this.unsupportedHopperVersion);
|
||||
const healthy =
|
||||
scope === undefined
|
||||
? environmentHealthy
|
||||
: (this.scopedDoctorHealthy ?? environmentHealthy);
|
||||
return Promise.resolve({
|
||||
healthy:
|
||||
this.doctorHealthy ??
|
||||
(this.hopper !== undefined &&
|
||||
!this.linuxDemoRuntimeMissing &&
|
||||
!this.unsupportedHopperVersion),
|
||||
healthy,
|
||||
environment_healthy: environmentHealthy,
|
||||
scope: {
|
||||
mode: scope === undefined ? "audit-wide" : "explicit",
|
||||
clients: scope?.clients ?? [],
|
||||
providers: scope?.providers ?? [],
|
||||
skill: scope?.skill === true,
|
||||
target: null,
|
||||
},
|
||||
scope_checks: checks,
|
||||
informational_checks: [],
|
||||
...(this.hopper === undefined ? {} : { hopperPath: this.hopper }),
|
||||
checks,
|
||||
});
|
||||
@@ -618,6 +636,34 @@ describe("setup workflow", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("uses requested readiness scope without hiding environment drift", async () => {
|
||||
const host = new FakeSetupHost();
|
||||
host.hopper = "/Applications/Hopper";
|
||||
host.doctorHealthy = false;
|
||||
host.scopedDoctorHealthy = true;
|
||||
const readinessScope = {
|
||||
clients: ["codex"],
|
||||
providers: [] as string[],
|
||||
skill: true,
|
||||
};
|
||||
|
||||
const result = await runSetup(
|
||||
{
|
||||
...options(true),
|
||||
proposeHopper: false,
|
||||
installSkill: false,
|
||||
readinessScope,
|
||||
},
|
||||
host,
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
status: "ready",
|
||||
doctor: { healthy: true, environment_healthy: false },
|
||||
});
|
||||
expect(host.doctorScopes).toEqual(expect.arrayContaining([readinessScope]));
|
||||
});
|
||||
|
||||
it("explains unsupported Node and macOS recovery", async () => {
|
||||
const platformHost = new FakeSetupHost("win32");
|
||||
expect((await runSetup(options(true), platformHost)).remediation).toBe(
|
||||
|
||||
+13
-19
@@ -1,15 +1,9 @@
|
||||
import {
|
||||
lstat,
|
||||
mkdtemp,
|
||||
readFile,
|
||||
rm,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { lstat, readFile, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { resolveClientConfigTransactionPath } from "../src/application/ClientConfigPath.js";
|
||||
import { configureJsonClient } from "../src/application/Setup.js";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
@@ -44,7 +38,7 @@ describe("JSON client configuration transaction", () => {
|
||||
});
|
||||
|
||||
it("preserves existing keys, creates a backup, and reads back the MCP entry", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
const original =
|
||||
'{"theme":"dark","mcpServers":{"other":{"command":"other"}}}\n';
|
||||
@@ -65,7 +59,7 @@ describe("JSON client configuration transaction", () => {
|
||||
});
|
||||
|
||||
it("updates a symlink target without replacing the JSON config symlink", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const targetPath = join(directory, "managed.json");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
const original = '{"theme":"dark"}\n';
|
||||
@@ -92,7 +86,7 @@ describe("JSON client configuration transaction", () => {
|
||||
});
|
||||
|
||||
it("fails before mutation when a JSON config symlink is dangling", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
await symlink(join(directory, "missing.json"), configPath);
|
||||
|
||||
@@ -107,7 +101,7 @@ describe("JSON client configuration transaction", () => {
|
||||
});
|
||||
|
||||
it("performs no write or second backup when configuration already matches", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
await writeFile(
|
||||
configPath,
|
||||
@@ -122,7 +116,7 @@ describe("JSON client configuration transaction", () => {
|
||||
});
|
||||
|
||||
it("migrates an unversioned npx registration and preserves sibling configuration", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
const original =
|
||||
'{"theme":"dark","mcpServers":{"rea":{"command":"npx","args":["-y","rea-agents","mcp"]},"other":{"command":"other"}}}\n';
|
||||
@@ -146,7 +140,7 @@ describe("JSON client configuration transaction", () => {
|
||||
});
|
||||
|
||||
it("persists a custom Hopper launcher and remains idempotent", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
const hopperPath = "/Applications/Hopper v6.app/Contents/MacOS/hopper";
|
||||
const client = { name: "cursor", configPath };
|
||||
@@ -174,7 +168,7 @@ describe("JSON client configuration transaction", () => {
|
||||
});
|
||||
|
||||
it("adds exact BYO Ghidra and Java paths without installing dependencies", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
const client = { name: "cursor", configPath };
|
||||
const environment = {
|
||||
@@ -201,7 +195,7 @@ describe("JSON client configuration transaction", () => {
|
||||
});
|
||||
|
||||
it("refuses malformed existing JSON without overwriting it", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
await writeFile(configPath, "not-json");
|
||||
expect(await configureJsonClient({ name: "cursor", configPath })).toEqual({
|
||||
@@ -214,7 +208,7 @@ describe("JSON client configuration transaction", () => {
|
||||
it.each(["null", "[]", '"value"'])(
|
||||
"refuses a non-object JSON root without overwriting %s",
|
||||
async (original) => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
await writeFile(configPath, original);
|
||||
expect(await configureJsonClient({ name: "cursor", configPath })).toEqual(
|
||||
@@ -230,7 +224,7 @@ describe("JSON client configuration transaction", () => {
|
||||
it.each(["null", "[]", '"value"'])(
|
||||
"preserves a non-object mcpServers value %s",
|
||||
async (servers) => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-setup-"));
|
||||
directory = await createTestTempDirectory("rea-setup-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
const original = `{"mcpServers":${servers}}`;
|
||||
await writeFile(configPath, original);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
copyFile,
|
||||
lstat,
|
||||
mkdtemp,
|
||||
mkdir,
|
||||
readFile,
|
||||
realpath,
|
||||
@@ -9,10 +8,11 @@ import {
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
configureTomlClient,
|
||||
detectClients,
|
||||
@@ -32,7 +32,7 @@ afterEach(async () => {
|
||||
|
||||
describe("agent lifecycle", () => {
|
||||
it("detects every supported client and skips absent clients", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-detect-"));
|
||||
const home = await createTestTempDirectory("rea-detect-");
|
||||
roots.push(home);
|
||||
for (const marker of [
|
||||
".claude",
|
||||
@@ -60,13 +60,13 @@ describe("agent lifecycle", () => {
|
||||
expect(detected.find(({ name }) => name === "devin")?.format).toBe(
|
||||
"unsupported",
|
||||
);
|
||||
const emptyHome = await mkdtemp(join(tmpdir(), "rea-empty-"));
|
||||
const emptyHome = await createTestTempDirectory("rea-empty-");
|
||||
roots.push(emptyHome);
|
||||
expect(await detectClients(emptyHome)).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves unrelated Codex TOML and supports an installed command", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-toml-"));
|
||||
const home = await createTestTempDirectory("rea-toml-");
|
||||
roots.push(home);
|
||||
const configPath = join(home, ".codex/config.toml");
|
||||
await mkdir(dirname(configPath), { recursive: true });
|
||||
@@ -106,7 +106,7 @@ describe("agent lifecycle", () => {
|
||||
});
|
||||
|
||||
it("updates a symlink target without replacing the TOML config symlink", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-toml-symlink-"));
|
||||
const home = await createTestTempDirectory("rea-toml-symlink-");
|
||||
roots.push(home);
|
||||
const configPath = join(home, ".codex/config.toml");
|
||||
const targetPath = join(home, "managed-config.toml");
|
||||
@@ -128,7 +128,7 @@ describe("agent lifecycle", () => {
|
||||
});
|
||||
|
||||
it("fails before mutation when a TOML config symlink is dangling", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-toml-symlink-"));
|
||||
const home = await createTestTempDirectory("rea-toml-symlink-");
|
||||
roots.push(home);
|
||||
const configPath = join(home, ".codex/config.toml");
|
||||
await mkdir(dirname(configPath), { recursive: true });
|
||||
@@ -144,7 +144,7 @@ describe("agent lifecycle", () => {
|
||||
});
|
||||
|
||||
it("uninstalls only owned entries and refuses purge symlinks", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-uninstall-"));
|
||||
const home = await createTestTempDirectory("rea-uninstall-");
|
||||
roots.push(home);
|
||||
const cursor = join(home, ".cursor/mcp.json");
|
||||
const skill = join(
|
||||
@@ -187,7 +187,7 @@ describe("agent lifecycle", () => {
|
||||
});
|
||||
|
||||
it("removes an owned entry through a symlink without replacing it", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-uninstall-symlink-"));
|
||||
const home = await createTestTempDirectory("rea-uninstall-symlink-");
|
||||
roots.push(home);
|
||||
const configPath = join(home, ".cursor/mcp.json");
|
||||
const targetPath = join(home, "managed-mcp.json");
|
||||
@@ -212,7 +212,7 @@ describe("agent lifecycle", () => {
|
||||
});
|
||||
|
||||
it("fails before mutation when an uninstall config symlink is dangling", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-uninstall-symlink-"));
|
||||
const home = await createTestTempDirectory("rea-uninstall-symlink-");
|
||||
roots.push(home);
|
||||
const configPath = join(home, ".cursor/mcp.json");
|
||||
await mkdir(dirname(configPath), { recursive: true });
|
||||
@@ -233,7 +233,7 @@ describe("agent lifecycle", () => {
|
||||
});
|
||||
|
||||
it("fails closed on malformed client configuration", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-uninstall-bad-"));
|
||||
const home = await createTestTempDirectory("rea-uninstall-bad-");
|
||||
roots.push(home);
|
||||
const config = join(home, ".cursor/mcp.json");
|
||||
await mkdir(dirname(config), { recursive: true });
|
||||
@@ -303,7 +303,7 @@ describe("agent lifecycle", () => {
|
||||
);
|
||||
|
||||
it("reports a managed-path removal failure", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-uninstall-remove-"));
|
||||
const home = await createTestTempDirectory("rea-uninstall-remove-");
|
||||
roots.push(home);
|
||||
const skillRoot = join(home, ".agents/skills/reverse-engineer-anything");
|
||||
await mkdir(skillRoot, { recursive: true });
|
||||
@@ -337,7 +337,7 @@ const uninstallFixture = async (): Promise<{
|
||||
readonly home: string;
|
||||
readonly config: string;
|
||||
}> => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-uninstall-failure-"));
|
||||
const home = await createTestTempDirectory("rea-uninstall-failure-");
|
||||
roots.push(home);
|
||||
const config = join(home, ".cursor/mcp.json");
|
||||
await mkdir(dirname(config), { recursive: true });
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
canonicalSkillNeedsInstall,
|
||||
installCanonicalSkill,
|
||||
@@ -17,7 +18,7 @@ afterEach(async () => {
|
||||
|
||||
describe("canonical skill transaction", () => {
|
||||
it("backs up and upgrades a stale managed skill without touching siblings", async () => {
|
||||
const home = await mkdtemp(join(tmpdir(), "rea-skill-test-"));
|
||||
const home = await createTestTempDirectory("rea-skill-test-");
|
||||
roots.push(home);
|
||||
const destination = join(
|
||||
home,
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
runCapabilityStatus,
|
||||
runProviderStatus,
|
||||
} from "../src/application/DirectAnalysis.js";
|
||||
import { projectDoctorReport } from "../src/application/DoctorProjection.js";
|
||||
import { runDoctor, type DoctorHost } from "../src/application/Doctor.js";
|
||||
import { CATALOG_IDENTITY } from "../src/catalogIdentity.js";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
|
||||
const doctorHost = (): DoctorHost => ({
|
||||
platform: "darwin",
|
||||
architecture: "x64",
|
||||
nodeVersion: "24.18.0",
|
||||
macosVersion: () => Promise.resolve("14.0"),
|
||||
linuxDistribution: () => Promise.resolve(undefined),
|
||||
validTarget: () => Promise.resolve(true),
|
||||
executable: (path) => Promise.resolve(path.includes("Hopper")),
|
||||
supportedLinuxHopper: () => Promise.resolve(true),
|
||||
linuxDemoRuntimeCheck: () =>
|
||||
Promise.resolve({
|
||||
name: "hopper-demo-runtime",
|
||||
ok: true,
|
||||
classification: "healthy",
|
||||
}),
|
||||
brewHopperPath: () => Promise.resolve(undefined),
|
||||
manualHopperPaths: () => Promise.resolve([]),
|
||||
installedSkillIdentity: () =>
|
||||
Promise.resolve({
|
||||
version: PRODUCT_IDENTITY.skillVersion,
|
||||
toolCount: CATALOG_IDENTITY.counts.mcp_tools,
|
||||
catalogDigest: CATALOG_IDENTITY.digests.combined_sha256,
|
||||
}),
|
||||
});
|
||||
|
||||
describe("purpose-specific CLI projections", () => {
|
||||
it("keeps provider and capability summaries concise with explicit full detail", async () => {
|
||||
const providers = await runProviderStatus();
|
||||
const capabilities = await runCapabilityStatus();
|
||||
const full = await runCapabilityStatus(undefined, "full");
|
||||
|
||||
expect(providers).toMatchObject({
|
||||
open: false,
|
||||
analysis_provider_candidates: expect.any(Array),
|
||||
server_identity: { catalog: { counts: expect.any(Object) } },
|
||||
});
|
||||
expect(JSON.stringify(providers)).not.toContain('"capabilities"');
|
||||
expect(JSON.stringify(providers)).not.toContain('"tools"');
|
||||
expect(capabilities).toMatchObject({
|
||||
summary: {
|
||||
total: expect.any(Number),
|
||||
available: expect.any(Number),
|
||||
unavailable: expect.any(Number),
|
||||
},
|
||||
capabilities: expect.any(Array),
|
||||
});
|
||||
expect(JSON.stringify(capabilities)).not.toContain('"effects"');
|
||||
expect(JSON.stringify(capabilities)).not.toContain('"limits"');
|
||||
expect(JSON.stringify(full)).toContain('"effects"');
|
||||
expect(JSON.stringify(full)).toContain('"catalog"');
|
||||
});
|
||||
|
||||
it("omits the catalog tool array only from the default doctor projection", async () => {
|
||||
const report = await runDoctor(undefined, doctorHost());
|
||||
const summary = projectDoctorReport(report, "summary");
|
||||
const full = projectDoctorReport(report, "full");
|
||||
|
||||
expect(summary).toMatchObject({
|
||||
healthy: true,
|
||||
environment_healthy: true,
|
||||
failed_scope_checks: [],
|
||||
informational_drift_count: 0,
|
||||
});
|
||||
expect(JSON.stringify(summary)).not.toContain('"tools"');
|
||||
expect(JSON.stringify(full)).toContain('"tools"');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { access, realpath, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
describe.sequential("test temporary directory ownership", () => {
|
||||
let completedDirectory: string | undefined;
|
||||
|
||||
it("creates a canonical directory owned by the current test", async () => {
|
||||
const directory = await createTestTempDirectory("rea-owned-temp-");
|
||||
completedDirectory = directory;
|
||||
|
||||
expect(directory).toBe(await realpath(directory));
|
||||
expect(dirname(directory)).toBe(await realpath(tmpdir()));
|
||||
await writeFile(join(directory, "nested.txt"), "owned");
|
||||
});
|
||||
|
||||
it("removes the prior test directory after that test finishes", async () => {
|
||||
const directory = completedDirectory;
|
||||
if (directory === undefined)
|
||||
throw new Error("Prior test did not create a directory");
|
||||
await expect(access(directory)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["", "../escape-", "/absolute-", "missing-dash"])(
|
||||
"rejects unsafe prefix %j",
|
||||
async (prefix) => {
|
||||
await expect(createTestTempDirectory(prefix)).rejects.toThrow(TypeError);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -51,6 +51,7 @@ describe("tool contract inventory", () => {
|
||||
expect(APPLICATION_TOOL_CONTRACTS.map(({ name }) => name)).toEqual([
|
||||
"trace_application_feature",
|
||||
"compare_application_versions",
|
||||
"compare_javascript_export_shapes",
|
||||
"run_controlled_replay",
|
||||
"prepare_node_characterization",
|
||||
"execute_node_characterization",
|
||||
|
||||
@@ -47,6 +47,46 @@ describe("tool result projection", () => {
|
||||
});
|
||||
expect(JSON.stringify(result)).not.toContain("expected Hopper");
|
||||
});
|
||||
it("projects bounded private-display coordinates without raw stderr", () => {
|
||||
const result = toCallToolResult(
|
||||
err(
|
||||
new HopperProcessError(80, {
|
||||
schema_version: 1,
|
||||
component: "hopper_private_display",
|
||||
operation: "launch",
|
||||
status: "error",
|
||||
failure_code: "x11_socket_directory_unusable",
|
||||
reason: "socket_directory_read_only",
|
||||
socket_directory: "/tmp/.X11-unix",
|
||||
socket_directory_mode: "0777",
|
||||
mount_read_only: true,
|
||||
effective_socket_directory_mode: "1777",
|
||||
effective_mount_read_only: false,
|
||||
wsl: true,
|
||||
strategy: "user-mount-namespace",
|
||||
fallback_reason: null,
|
||||
xvfb_stderr_bytes: 512,
|
||||
xvfb_stderr_truncated: false,
|
||||
}),
|
||||
),
|
||||
contract,
|
||||
);
|
||||
expect(result.structuredContent).toMatchObject({
|
||||
error: {
|
||||
details: {
|
||||
failure_code: "x11_socket_directory_unusable",
|
||||
diagnostics: {
|
||||
socket_directory: "/tmp/.X11-unix",
|
||||
mount_read_only: true,
|
||||
wsl: true,
|
||||
strategy: "user-mount-namespace",
|
||||
xvfb_stderr_truncated: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(JSON.stringify(result)).not.toContain("cookie");
|
||||
});
|
||||
it("classifies output contract failures without naming a provider", () => {
|
||||
const result = toCallToolResult(ok({ value: 42 }), contract);
|
||||
expect(result).toMatchObject({
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { readdir } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { SERIAL_INTEGRATION_TESTS } from "../vitest.config.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
|
||||
describe("Vitest project configuration", () => {
|
||||
it("collects exact disjoint parallel and serial test sets", async () => {
|
||||
const { stdout } = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
resolve("node_modules/vitest/vitest.mjs"),
|
||||
"list",
|
||||
"--filesOnly",
|
||||
"--staticParse",
|
||||
],
|
||||
{ cwd: process.cwd(), maxBuffer: 4 * 1_024 * 1_024 },
|
||||
);
|
||||
const projects = parseProjects(stdout);
|
||||
const parallel = projects.get("parallel") ?? [];
|
||||
const serial = projects.get("serial-integration") ?? [];
|
||||
const repositoryTests = await testFiles("tests");
|
||||
|
||||
expect(serial).toEqual([...SERIAL_INTEGRATION_TESTS].sort());
|
||||
expect(parallel.filter((path) => serial.includes(path))).toEqual([]);
|
||||
expect([...new Set([...parallel, ...serial])].sort()).toEqual(
|
||||
repositoryTests,
|
||||
);
|
||||
}, 20_000);
|
||||
});
|
||||
|
||||
const parseProjects = (output: string): Map<string, string[]> => {
|
||||
const projects = new Map<string, string[]>();
|
||||
for (const line of output.split("\n")) {
|
||||
const trimmed = line.trim();
|
||||
const separator = trimmed.indexOf("] ");
|
||||
if (!trimmed.startsWith("[") || separator < 2) continue;
|
||||
const project = trimmed.slice(1, separator);
|
||||
const path = trimmed.slice(separator + 2);
|
||||
if (path.length === 0) continue;
|
||||
const paths = projects.get(project) ?? [];
|
||||
paths.push(path);
|
||||
projects.set(project, paths);
|
||||
}
|
||||
for (const paths of projects.values()) paths.sort();
|
||||
return projects;
|
||||
};
|
||||
|
||||
const testFiles = async (root: string): Promise<string[]> => {
|
||||
const files: string[] = [];
|
||||
for (const entry of await readdir(root, { withFileTypes: true })) {
|
||||
const path = join(root, entry.name);
|
||||
if (entry.isDirectory()) files.push(...(await testFiles(path)));
|
||||
else if (entry.isFile() && entry.name.endsWith(".test.ts"))
|
||||
files.push(path);
|
||||
}
|
||||
return files.sort();
|
||||
};
|
||||
Reference in New Issue
Block a user