Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

test(artifacts): compare matching resource-root workflows

morluto5518363aa625
diff --git a/scripts/lib/artifact-e2e.mjs b/scripts/lib/artifact-e2e.mjs
index b0ee1c2c1..444639319 100644
--- a/scripts/lib/artifact-e2e.mjs
+++ b/scripts/lib/artifact-e2e.mjs
@@ -58,8 +58,7 @@ export async function artifactCliEvidence(
return evidence;
}
-/** Run a real stdio MCP subprocess, owning and closing its transport. */
-export async function withArtifactMcp(target, verify) {
+const withOpenedArtifactMcp = async (target, openTool, verify) => {
const transport = new StdioClientTransport({
command: process.execPath,
args: [fileURLToPath(new URL("../rea.mjs", import.meta.url)), "mcp"],
@@ -70,15 +69,27 @@ export async function withArtifactMcp(target, verify) {
try {
await client.connect(transport);
const opened = await client.callTool({
- name: "open_binary",
+ name: openTool,
arguments: { path: target },
});
assert.notEqual(opened.isError, true, JSON.stringify(opened));
+ if (openTool === "open_bundle_resources")
+ assert.equal(opened.structuredContent?.result?.caller_path, target);
await verify(client);
} finally {
await client.close();
await transport.close();
}
+};
+
+/** Run a real stdio MCP subprocess with an explicitly opened binary target. */
+export async function withArtifactMcp(target, verify) {
+ return withOpenedArtifactMcp(target, "open_binary", verify);
+}
+
+/** Run a real stdio MCP subprocess with an explicitly opened bundle resource root. */
+export async function withBundleResourcesMcp(target, verify) {
+ return withOpenedArtifactMcp(target, "open_bundle_resources", verify);
}
/** Require a successful structured MCP tool result rather than its text rendering. */
diff --git a/scripts/verify/apple/asset-catalog.mjs b/scripts/verify/apple/asset-catalog.mjs
index f29d79386..4de295f06 100644
--- a/scripts/verify/apple/asset-catalog.mjs
+++ b/scripts/verify/apple/asset-catalog.mjs
@@ -10,6 +10,7 @@ import {
artifactCli,
artifactMcpResult,
withArtifactMcp,
+ withBundleResourcesMcp,
} from "../../lib/artifact-e2e.mjs";
if (process.platform !== "darwin")
@@ -68,6 +69,9 @@ try {
const sha256 = createHash("sha256")
.update(await readFile(join(resources, "Assets.car")))
.digest("hex");
+ const executableSha256 = createHash("sha256")
+ .update(await readFile(join(app, "Contents", "MacOS", "Fixture")))
+ .digest("hex");
const cli = await artifactCli("inspect-asset-catalog", app);
assert.deepEqual(
cli.records.map(({ metadata }) => metadata),
@@ -80,7 +84,7 @@ try {
asset_name === "FixtureColor" && metadata.AssetType === "Color",
),
);
- await withArtifactMcp(app, async (client) => {
+ await withBundleResourcesMcp(app, async (client) => {
assert.deepEqual(
await artifactMcpResult(client, "inspect_asset_catalog"),
cli,
@@ -99,6 +103,17 @@ try {
});
assert.equal(invalid.isError, true);
});
+ const { resource_root, target_sha256, ...resourcePayload } = cli;
+ assert.equal(resource_root.executable_sha256, null);
+ assert.equal(target_sha256, null);
+ await withArtifactMcp(app, async (client) => {
+ const binary = await artifactMcpResult(client, "inspect_asset_catalog");
+ assert.equal(binary.target_sha256, executableSha256);
+ assert.deepEqual(binary, {
+ ...resourcePayload,
+ target_sha256: executableSha256,
+ });
+ });
report = {
ok: true,
mocked: false,
diff --git a/scripts/verify/apple/interface-builder.mjs b/scripts/verify/apple/interface-builder.mjs
index a27bf656b..1d9d3b5d9 100644
--- a/scripts/verify/apple/interface-builder.mjs
+++ b/scripts/verify/apple/interface-builder.mjs
@@ -1,8 +1,9 @@
#!/usr/bin/env node
import assert from "node:assert/strict";
+import { createHash } from "node:crypto";
import { execFile } from "node:child_process";
-import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
+import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
@@ -12,6 +13,7 @@ import {
artifactCliEvidence,
artifactMcpResult,
withArtifactMcp,
+ withBundleResourcesMcp,
} from "../../lib/artifact-e2e.mjs";
const exec = promisify(execFile);
@@ -49,7 +51,10 @@ try {
appPath,
);
const decoded = evidence.normalized_result;
- await withArtifactMcp(appPath, async (client) => {
+ const executableSha256 = createHash("sha256")
+ .update(await readFile(executablePath))
+ .digest("hex");
+ await withBundleResourcesMcp(appPath, async (client) => {
const mcp = await artifactMcpResult(client, "decode_interface_builder");
assert.deepEqual(
mcp,
@@ -57,6 +62,19 @@ try {
"CLI and MCP compiled archive results differ",
);
});
+ const { resource_root, target_sha256, ...resourcePayload } = decoded;
+ assert.equal(resource_root.executable_sha256, null);
+ assert.equal(target_sha256, null);
+ await withArtifactMcp(appPath, async (client) => {
+ const binary = await artifactMcpResult(client, "decode_interface_builder");
+ assert.equal(binary.target_sha256, executableSha256);
+ assert.equal(binary.graph.target_sha256, executableSha256);
+ assert.deepEqual(binary, {
+ ...resourcePayload,
+ target_sha256: executableSha256,
+ graph: { ...decoded.graph, target_sha256: executableSha256 },
+ });
+ });
assert.equal(decoded.documents.length, 1);
assert.equal(
decoded.documents[0]?.relative_path,
diff --git a/src/cliCommandNames.ts b/src/cliCommandNames.ts
index ec23e6508..ce6c6bf83 100644
--- a/src/cliCommandNames.ts
+++ b/src/cliCommandNames.ts
@@ -193,6 +193,8 @@ export const CLI_COMMAND_TOOL_ALIASES = Object.freeze({
/** MCP operations without a dedicated CLI command or direct command alias. */
export const MCP_TOOLS_WITHOUT_DEDICATED_CLI = Object.freeze([
+ // MCP session control selects a resource root; CLI resource commands take paths directly.
+ "open_bundle_resources",
"address_name",
"comment",
"current_address",
diff --git a/tests/acceptance/applications/interfaceBuilderHierarchyLimits.test.ts b/tests/acceptance/applications/interfaceBuilderHierarchyLimits.test.ts
index af508592c..3bcd6ce9a 100644
--- a/tests/acceptance/applications/interfaceBuilderHierarchyLimits.test.ts
+++ b/tests/acceptance/applications/interfaceBuilderHierarchyLimits.test.ts
@@ -10,7 +10,7 @@ import { parseEvidence } from "../../../src/domain/evidence.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
import { createTestMcp } from "../../support/mcp/mcpFixture.js";
-import { openArtifactTarget } from "../../support/mcp/artifactSession.js";
+import { openBundleResourcesTarget } from "../../support/mcp/artifactSession.js";
const verifyMcpParity = async (
app: string,
@@ -18,7 +18,7 @@ const verifyMcpParity = async (
): Promise<void> => {
const mcp = createTestMcp();
onTestFinished(async () => mcp.close());
- const client = await openArtifactTarget(mcp, onTestFinished, app);
+ const client = await openBundleResourcesTarget(mcp, onTestFinished, app);
const complete = await client.callTool({
name: "decode_interface_builder",
arguments: { max_objects: 2 },
diff --git a/tests/acceptance/applications/nibFieldIdentity.test.ts b/tests/acceptance/applications/nibFieldIdentity.test.ts
index 5af16f890..82aa769d1 100644
--- a/tests/acceptance/applications/nibFieldIdentity.test.ts
+++ b/tests/acceptance/applications/nibFieldIdentity.test.ts
@@ -66,7 +66,7 @@ cliTest(
try {
await client.connect(transport);
const opened = await client.callTool({
- name: "open_binary",
+ name: "open_bundle_resources",
arguments: { path: app },
});
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
diff --git a/tests/boundary/providers/native/artifactProvider.directAnalysis.test.ts b/tests/boundary/providers/native/artifactProvider.directAnalysis.test.ts
index f6fb12853..1cb7b9239 100644
--- a/tests/boundary/providers/native/artifactProvider.directAnalysis.test.ts
+++ b/tests/boundary/providers/native/artifactProvider.directAnalysis.test.ts
@@ -48,7 +48,9 @@ it("runs static .app decoding without registering native analysis engines", asyn
evidence.normalized_result,
);
expect(result.documents).toEqual([]);
- expect(result.graph.target_sha256).toBe(evidence.subject?.digest.sha256);
+ expect(result.graph.target_sha256).toBe(
+ evidence.subject?.digest.sha256 ?? null,
+ );
});
it("inspects an artifact through the direct CLI workflow without an REA grant", async () => {
diff --git a/tests/support/mcp/artifactSession.ts b/tests/support/mcp/artifactSession.ts
index 569724b9b..53ca01560 100644
--- a/tests/support/mcp/artifactSession.ts
+++ b/tests/support/mcp/artifactSession.ts
@@ -5,10 +5,10 @@ import { createArtifactBinarySession } from "../../../src/composition/binary.js"
import { createServer } from "../../../src/server/createServer.js";
import type { TestMcp } from "./mcpFixture.js";
-/** Open a static artifact target in the production artifact-only MCP composition. */
-export const openArtifactTarget = async (
+const openSessionTarget = async (
mcp: TestMcp,
onTestFinished: (handler: OnTestFinishedHandler) => void,
+ operation: "open_binary" | "open_bundle_resources",
path: string,
): Promise<Client> => {
const session = await createArtifactBinarySession(process.env);
@@ -17,9 +17,25 @@ export const openArtifactTarget = async (
});
const client = await mcp.connect(createServer({ kind: "session", session }));
const opened = await client.callTool({
- name: "open_binary",
+ name: operation,
arguments: { path },
});
expect(opened.isError, JSON.stringify(opened.content)).not.toBe(true);
return client;
};
+
+/** Open a static artifact target in the production artifact-only MCP composition. */
+export const openArtifactTarget = (
+ mcp: TestMcp,
+ onTestFinished: (handler: OnTestFinishedHandler) => void,
+ path: string,
+): Promise<Client> =>
+ openSessionTarget(mcp, onTestFinished, "open_binary", path);
+
+/** Open a caller-selected bundle resource root in the production MCP session. */
+export const openBundleResourcesTarget = (
+ mcp: TestMcp,
+ onTestFinished: (handler: OnTestFinishedHandler) => void,
+ path: string,
+): Promise<Client> =>
+ openSessionTarget(mcp, onTestFinished, "open_bundle_resources", path);