From dc6bf4a30651bf1e26c7c0fe06b775c8459eb3f2 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 3 Dec 2026 10:26:13 +0800 Subject: [PATCH] test(apple): share keyed archive scalar parity fixtures (#16190) --- .../keyedArchiveScalarKinds.test.ts | 117 +++++++----------- 1 file changed, 46 insertions(+), 71 deletions(-) diff --git a/tests/acceptance/applications/keyedArchiveScalarKinds.test.ts b/tests/acceptance/applications/keyedArchiveScalarKinds.test.ts index ae7bc53f914..7f1f234683a 100644 --- a/tests/acceptance/applications/keyedArchiveScalarKinds.test.ts +++ b/tests/acceptance/applications/keyedArchiveScalarKinds.test.ts @@ -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" }); }