test(apple): share keyed archive scalar parity fixtures (#16190)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-03 02:26:13 +00:00
1 parent 1018091955
commit dc6bf4a306
1 file changed
+46 -71
@@ -8,7 +8,41 @@ import { expect } from "vitest";
import { keyedArchiveResultSchema } from "../../../src/domain/apple/keyedArchive.js";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
import { cliTest, type TestCli } from "../../support/cli/cliFixture.js";
const readKeyedArchiveCli = async (
cli: TestCli,
path: string,
arguments_: readonly string[] = [],
) => {
const output = await cli.run({
arguments: ["inspect-keyed-archive", path, ...arguments_, "--json"],
environment: {
REA_LOG_LEVEL: "silent",
REA_ANALYSIS_PROVIDER: "auto",
},
});
expect(output.exitCode, output.stderr).toBe(0);
return keyedArchiveResultSchema.parse(
parseEvidence(output.json).normalized_result,
);
};
const readKeyedArchiveOnBothSurfaces = async (cli: TestCli, path: string) => {
const result = await readKeyedArchiveCli(cli, path);
const call = await cli.sharedMcpCall?.();
if (call === undefined) throw new Error("Expected a stdio MCP session");
const opened = await call("open_binary", { path });
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
const mcp = await call("inspect_keyed_archive", {});
expect(mcp.isError, JSON.stringify(mcp)).not.toBe(true);
expect(
keyedArchiveResultSchema.parse(
parseEvidence(mcp.structuredContent).normalized_result,
),
).toEqual(result);
return result;
};
cliTest.for(["xml", "binary"] as const)(
"distinguishes serialized scalar objects from lookalike dictionaries in a %s keyed archive",
@@ -43,31 +77,7 @@ cliTest.for(["xml", "binary"] as const)(
const path = join(root, "archive.plist");
await writeFile(path, bytes);
const digest = createHash("sha256").update(bytes).digest("hex");
const run = async (arguments_: readonly string[] = []) => {
const output = await cli.run({
arguments: ["inspect-keyed-archive", path, ...arguments_, "--json"],
environment: {
REA_LOG_LEVEL: "silent",
REA_ANALYSIS_PROVIDER: "auto",
},
});
expect(output.exitCode, output.stderr).toBe(0);
return keyedArchiveResultSchema.parse(
parseEvidence(output.json).normalized_result,
);
};
const result = await run();
const call = await cli.sharedMcpCall?.();
if (call === undefined) throw new Error("Expected a stdio MCP session");
const opened = await call("open_binary", { path });
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
const mcp = await call("inspect_keyed_archive", {});
expect(mcp.isError, JSON.stringify(mcp)).not.toBe(true);
expect(
keyedArchiveResultSchema.parse(
parseEvidence(mcp.structuredContent).normalized_result,
),
).toEqual(result);
const result = await readKeyedArchiveOnBothSurfaces(cli, path);
expect(result.archive_sha256).toBe(digest);
expect(result.archive_format).toBe(
format === "binary" ? "binary-plist" : "xml-plist",
@@ -131,7 +141,14 @@ cliTest.for(["xml", "binary"] as const)(
expect.stringMatching(/\b1 non-finite real value.*JSON number/iu),
);
const page = await run(["--root", "data", "--offset", "1", "--limit", "2"]);
const page = await readKeyedArchiveCli(cli, path, [
"--root",
"data",
"--offset",
"1",
"--limit",
"2",
]);
expect(page.objects).toEqual(result.objects.slice(1, 3));
expect(page).toMatchObject({
archive_sha256: digest,
@@ -197,28 +214,7 @@ cliTest.for(["xml", "binary"] as const)(
}
const path = join(root, "archive.plist");
await writeFile(path, bytes);
const output = await cli.run({
arguments: ["inspect-keyed-archive", path, "--json"],
environment: {
REA_LOG_LEVEL: "silent",
REA_ANALYSIS_PROVIDER: "auto",
},
});
expect(output.exitCode, output.stderr).toBe(0);
const result = keyedArchiveResultSchema.parse(
parseEvidence(output.json).normalized_result,
);
const call = await cli.sharedMcpCall?.();
if (call === undefined) throw new Error("Expected a stdio MCP session");
const opened = await call("open_binary", { path });
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
const mcp = await call("inspect_keyed_archive", {});
expect(mcp.isError, JSON.stringify(mcp)).not.toBe(true);
expect(
keyedArchiveResultSchema.parse(
parseEvidence(mcp.structuredContent).normalized_result,
),
).toEqual(result);
const result = await readKeyedArchiveOnBothSurfaces(cli, path);
const [, negative, positive, control] = result.objects;
expect(negative).toMatchObject({
kind: "scalar",
@@ -367,28 +363,7 @@ cliTest(
const bytes = Buffer.from(xml);
const path = join(root, "archive.plist");
await writeFile(path, bytes);
const output = await cli.run({
arguments: ["inspect-keyed-archive", path, "--json"],
environment: {
REA_LOG_LEVEL: "silent",
REA_ANALYSIS_PROVIDER: "auto",
},
});
expect(output.exitCode, output.stderr).toBe(0);
const result = keyedArchiveResultSchema.parse(
parseEvidence(output.json).normalized_result,
);
const call = await cli.sharedMcpCall?.();
if (call === undefined) throw new Error("Expected a stdio MCP session");
const opened = await call("open_binary", { path });
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
const mcp = await call("inspect_keyed_archive", {});
expect(mcp.isError, JSON.stringify(mcp)).not.toBe(true);
expect(
keyedArchiveResultSchema.parse(
parseEvidence(mcp.structuredContent).normalized_result,
),
).toEqual(result);
const result = await readKeyedArchiveOnBothSurfaces(cli, path);
for (const object of result.objects.slice(1)) {
expect(object).toMatchObject({ kind: "scalar", status: "observed" });
}