Files
reverse-engineering-anything/tests/acceptance/applications/resourceOnlyPlistSelection.test.ts
T
8c7977f174 fix(native)!: require separate inspection for plists outside bundles (#9754)
* fix(native): record inspected plist bytes and refuse files outside the bundle

An open app session keeps the executable as the Evidence subject for
inspect_plist, same as the other bundle-resource tools, but the result had
no digest of the plist bytes and any absolute path was sealed under that
subject. Record source_sha256 for the bytes read, and refuse a selection
that resolves outside the opened bundle.

Fixes #9479

* fix(native)!: scope plist selection to the opened bundle

BREAKING CHANGE: To inspect a plist outside an opened app bundle or resource root, open the plist as a separate target.

* fix(native): report plist snapshot filesystem effects

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-11-19 21:35:17 -05:00

115 lines
4.1 KiB
TypeScript

import { mkdir, readFile, rename, symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { buildBinary } from "plist";
import { expect, it } from "vitest";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it.skipIf(process.platform !== "darwin")(
"resource-only MCP plist selections retain symlink-parent and directory semantics",
async () => {
const root = await createTestTempDirectory("rea-resource-plist-selection-");
const app = join(root, "Fixture.app");
const contents = join(app, "Contents");
const physical = join(contents, "physical");
await mkdir(join(physical, "child"), { recursive: true });
const defaultPath = join(contents, "Info.plist");
const sourcePath = join(physical, "Selected.plist");
const decoyPath = join(contents, "Selected.plist");
const source = buildBinary({ Marker: "physical source" });
const decoy = buildBinary({ Marker: "lexical decoy" });
await writeFile(
defaultPath,
buildBinary({ CFBundleIdentifier: "fixture" }),
);
await writeFile(sourcePath, source);
await writeFile(decoyPath, decoy);
await symlink("physical/child", join(contents, "alias"));
const outside = join(root, "Outside.plist");
await writeFile(outside, source);
await symlink(outside, join(contents, "Outside.plist"));
const { call } = await connectLocalToolsMcp({
HOME: root,
USERPROFILE: root,
});
expect(
(await call("open_bundle_resources", { path: app })).isError,
).not.toBe(true);
const defaultResult = await call("inspect_plist", {});
expect(defaultResult.isError).not.toBe(true);
expect(
parseEvidence(defaultResult.structuredContent).normalized_result,
).toMatchObject({
source_path: defaultPath,
value: { CFBundleIdentifier: "fixture" },
});
for (const requested of [
"Contents/alias/../Selected.plist",
`${contents}/alias/../Selected.plist`,
sourcePath,
]) {
const response = await call("inspect_plist", { path: requested });
expect(response.isError, JSON.stringify(response.content)).not.toBe(true);
expect(
parseEvidence(response.structuredContent).normalized_result,
).toMatchObject({
source_path: requested.startsWith("/")
? requested
: `${app}/${requested}`,
value: { Marker: "physical source" },
resource_root: { canonical_path: app, executable_sha256: null },
});
}
expect(
parseMcpToolError(
await call("inspect_plist", { path: "Contents/Selected.plist/" }),
).error,
).toMatchObject({
code: "invalid_request",
details: { issues: [{ path: ["path"] }] },
});
for (const requested of [
outside,
"../Outside.plist",
"Contents/Outside.plist",
])
expect(
parseMcpToolError(await call("inspect_plist", { path: requested }))
.error,
).toMatchObject({
code: "invalid_request",
details: { issues: [{ path: ["path"] }] },
});
const retired = join(root, "Retired.app");
await rename(app, retired);
expect(
parseMcpToolError(await call("inspect_plist", {})).error,
).toMatchObject({
code: "artifact_changed",
details: { path: app },
});
expect((await call("open_binary", { path: outside })).isError).not.toBe(
true,
);
const standalone = await call("inspect_plist", {});
expect(standalone.isError).not.toBe(true);
expect(
parseEvidence(standalone.structuredContent).normalized_result,
).toMatchObject({
source_path: outside,
value: { Marker: "physical source" },
});
await rename(retired, app);
expect(
Buffer.compare(await readFile(sourcePath), Buffer.from(source)),
).toBe(0);
expect(Buffer.compare(await readFile(decoyPath), Buffer.from(decoy))).toBe(
0,
);
},
);