mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
* 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>
139 lines
4.6 KiB
TypeScript
139 lines
4.6 KiB
TypeScript
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
import type { AnalysisOperationPort } from "../../../src/ports/AnalysisProvider.js";
|
|
import { NATIVE_TOOL_CONTRACTS } from "../../../src/contracts/native/nativeToolContracts.js";
|
|
import type { JsonValue } from "../../../src/domain/jsonValue.js";
|
|
import { ok } from "../../../src/domain/result.js";
|
|
import { createAnalysisExecution } from "../../../src/ports/AnalysisProvider.js";
|
|
import { createServer } from "../../../src/server/createServer.js";
|
|
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
|
|
|
const provider = {
|
|
id: "fixture-native",
|
|
name: "Fixture native provider",
|
|
version: "1",
|
|
} as const;
|
|
|
|
const plistResult = {
|
|
format: "xml",
|
|
value: {},
|
|
bundle: {
|
|
identifier: null,
|
|
executable: null,
|
|
name: null,
|
|
version: null,
|
|
short_version: null,
|
|
},
|
|
source_path: "/Applications/Fixture.app/Contents/Info.plist",
|
|
provenance: [],
|
|
limitations: [],
|
|
};
|
|
|
|
const resources: Array<{ close(): Promise<void> }> = [];
|
|
|
|
const connect = async (
|
|
execute: AnalysisOperationPort["execute"],
|
|
): Promise<Client> => {
|
|
const server = createServer({ kind: "fixed", analysis: { execute } });
|
|
const client = new Client(
|
|
{ name: "native-contract-test", version: "1" },
|
|
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
|
);
|
|
const [clientTransport, serverTransport] =
|
|
InMemoryTransport.createLinkedPair();
|
|
resources.push(client, server);
|
|
await server.connect(serverTransport);
|
|
await client.connect(clientTransport);
|
|
return client;
|
|
};
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
resources.splice(0).map(async (resource) => resource.close()),
|
|
);
|
|
});
|
|
|
|
describe("native MCP input contracts", () => {
|
|
it("advertises the temporary plist snapshot write to MCP clients", async () => {
|
|
const client = await connect(() =>
|
|
Promise.resolve(ok(createAnalysisExecution(plistResult, provider))),
|
|
);
|
|
const { tools } = await client.listTools();
|
|
expect(tools.find(({ name }) => name === "inspect_plist")).toMatchObject({
|
|
description: expect.stringContaining("private temporary copy"),
|
|
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
});
|
|
expect(
|
|
NATIVE_TOOL_CONTRACTS.find(({ name }) => name === "inspect_plist")
|
|
?.effects,
|
|
).toMatchObject({ writesFilesystem: true, mutatesTarget: false });
|
|
});
|
|
|
|
it("rejects a misspelled plist path before dispatch and preserves omission", async () => {
|
|
const calls: Array<{
|
|
readonly operation: string;
|
|
readonly parameters: Readonly<Record<string, JsonValue>>;
|
|
}> = [];
|
|
const client = await connect((operation, parameters) => {
|
|
calls.push({ operation, parameters });
|
|
return Promise.resolve(
|
|
ok(createAnalysisExecution(plistResult, provider)),
|
|
);
|
|
});
|
|
|
|
const tools = new Map(
|
|
(await client.listTools()).tools.map((tool) => [tool.name, tool]),
|
|
);
|
|
for (const nativeContract of NATIVE_TOOL_CONTRACTS)
|
|
expect(tools.get(nativeContract.name)?.inputSchema).toHaveProperty(
|
|
"additionalProperties",
|
|
false,
|
|
);
|
|
|
|
const contract = NATIVE_TOOL_CONTRACTS.find(
|
|
({ name }) => name === "inspect_plist",
|
|
);
|
|
const advertised = tools.get("inspect_plist");
|
|
if (contract === undefined || advertised === undefined)
|
|
throw new Error("inspect_plist was not registered");
|
|
|
|
const validate = new Ajv2020({
|
|
strict: false,
|
|
validateFormats: false,
|
|
}).compile(advertised.inputSchema);
|
|
const typoInput = { pth: "/tmp/Other.plist" };
|
|
expect(validate(typoInput)).toBe(false);
|
|
expect(contract.inputSchema.safeParse(typoInput).success).toBe(false);
|
|
expect(validate({})).toBe(true);
|
|
expect(contract.inputSchema.safeParse({}).success).toBe(true);
|
|
|
|
const defaulted = await client.callTool({
|
|
name: "inspect_plist",
|
|
arguments: {},
|
|
});
|
|
expect(defaulted.isError).not.toBe(true);
|
|
expect(calls[0]).toEqual({ operation: "inspect_plist", parameters: {} });
|
|
|
|
const selectedPath = "/tmp/Other.plist";
|
|
const explicit = await client.callTool({
|
|
name: "inspect_plist",
|
|
arguments: { path: selectedPath },
|
|
});
|
|
expect(explicit.isError).not.toBe(true);
|
|
expect(calls[1]).toEqual({
|
|
operation: "inspect_plist",
|
|
parameters: { path: selectedPath },
|
|
});
|
|
|
|
const beforeTypo = calls.length;
|
|
const rejected = await client.callTool({
|
|
name: "inspect_plist",
|
|
arguments: typoInput,
|
|
});
|
|
expect(rejected.isError).toBe(true);
|
|
expect(calls).toHaveLength(beforeTypo);
|
|
});
|
|
});
|