test(perf): reuse keyed archive CLI and MCP sessions

This commit is contained in:
morluto
2026-10-24 06:37:26 +08:00
parent 91c28e2735
commit 1a808dd2a2
@@ -7,9 +7,8 @@ import { expect } from "vitest";
import { keyedArchiveResultSchema } from "../../../src/domain/apple/keyedArchive.js";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
import { cliTest, runFileCli } from "../../support/cli/cliFixture.js";
cliTest.for([
{ name: "plain real", element: "<real>1.25</real>", expected: 1.25 },
@@ -73,11 +72,9 @@ cliTest.for([
);
const path = join(root, "archive.plist");
await writeFile(path, bytes);
const { call } = await connectLocalToolsMcp({
HOME: root,
USERPROFILE: root,
});
const output = await cli.run({
const call = await cli.sharedMcpCall?.();
if (call === undefined) throw new Error("Missing file-scoped MCP session");
const output = await runFileCli(cli, {
arguments: [
"inspect-keyed-archive",
path,
@@ -89,7 +86,7 @@ cliTest.for([
"1",
"--json",
],
environment: { HOME: root, USERPROFILE: root, REA_LOG_LEVEL: "silent" },
environment: { REA_LOG_LEVEL: "silent" },
});
expect(output.exitCode, output.stderr).toBe(0);
const result = keyedArchiveResultSchema.parse(
@@ -141,10 +138,8 @@ cliTest(
"refuses invalid data without publishing observed bytes through CLI and MCP",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-keyed-data-refusal-");
const { call } = await connectLocalToolsMcp({
HOME: root,
USERPROFILE: root,
});
const call = await cli.sharedMcpCall?.();
if (call === undefined) throw new Error("Missing file-scoped MCP session");
for (const [name, element, reason] of [
["non-ascii", "<data>AQ\u0085ID</data>", "non-ascii"],
["markup", "<data>A<!-- ignored -->QID</data>", "markup"],
@@ -160,9 +155,9 @@ cliTest(
}).replace("<string>__VALUE__</string>", element),
);
await writeFile(path, bytes);
const output = await cli.run({
const output = await runFileCli(cli, {
arguments: ["inspect-keyed-archive", path, "--json"],
environment: { HOME: root, USERPROFILE: root, REA_LOG_LEVEL: "silent" },
environment: { REA_LOG_LEVEL: "silent" },
});
expect(output.exitCode).toBe(1);
expect(output.json).toMatchObject({