mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 13:11:18 -05:00
6ac87697e7
* fix(errors)!: make retry_class the only retry field of a target failure A target failure reported two retry fields: its own `retry` hint (`none | backoff | after_change`) and the `retry_class` every error carries. They mapped one to one, so readers had to reconcile both. `retry_class` is now the single owner: the target-failure table declares it directly, the projection no longer emits `retry`, the error schema no longer accepts it, and the CLI recovery rewrite reads `retry_class`. BREAKING CHANGE: target failures no longer include `retry`, and the error schema rejects it. Read `retry_class` instead: `backoff` is `same_call`, `after_change` is `change_first` and `none` is `never`. * test(errors): readers reject the removed target-failure retry field
126 lines
5.2 KiB
TypeScript
126 lines
5.2 KiB
TypeScript
import { fileIdentity } from "../../fixtures/evidenceSubject.js";
|
|
import { createHash } from "node:crypto";
|
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { thinMach } from "../../../src/domain/binaryTarget.fixture.js";
|
|
import { interfaceBuilderAnalysisSchema } from "../../../src/domain/apple/interfaceBuilderGraph.js";
|
|
import { keyedArchiveResultSchema } from "../../../src/domain/apple/keyedArchive.js";
|
|
import { inspectPlistSchema } from "../../../src/domain/native/nativeInspection.js";
|
|
import { parseEvidence } from "../../../src/domain/evidence.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
|
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
cliTest.for([
|
|
"decode_interface_builder",
|
|
"inspect_keyed_archive",
|
|
...(process.platform === "darwin"
|
|
? ["inspect_asset_catalog", "inspect_plist"]
|
|
: []),
|
|
] as const)(
|
|
"binds live %s Evidence to the open executable through stdio MCP",
|
|
async (operation) => {
|
|
const root = await createTestTempDirectory("rea-bundle-resource-identity-");
|
|
const app = join(root, "Probe.app");
|
|
const contents = join(app, "Contents");
|
|
const resources = join(contents, "Resources");
|
|
await mkdir(resources, { recursive: true });
|
|
await mkdir(join(contents, "MacOS"));
|
|
const executable = join(contents, "MacOS", "Probe");
|
|
const original = thinMach(0xfeedfacf, 0x0100000c);
|
|
await writeFile(executable, original);
|
|
await writeFile(
|
|
join(contents, "Info.plist"),
|
|
"<plist><dict><key>CFBundleExecutable</key><string>Probe</string></dict></plist>",
|
|
);
|
|
const nib = await readFile(
|
|
join(process.cwd(), "tests/fixtures/interface-builder/UIKitOutlet.xml"),
|
|
"utf8",
|
|
);
|
|
const nibPath = join(resources, "Main.nib");
|
|
await writeFile(nibPath, nib);
|
|
const { call } = await connectLocalToolsMcp();
|
|
const parameters =
|
|
operation === "inspect_keyed_archive"
|
|
? { path: "Contents/Resources/Main.nib" }
|
|
: {};
|
|
expect((await call("open_binary", { path: app })).isError).not.toBe(true);
|
|
const before = await call(operation, parameters);
|
|
expect(before.isError).not.toBe(true);
|
|
const initial = parseEvidence(before.structuredContent);
|
|
expect(fileIdentity(initial.subject).sha256).toBe(
|
|
createHash("sha256").update(original).digest("hex"),
|
|
);
|
|
|
|
const changed = Buffer.from(original);
|
|
changed[31] = 1;
|
|
await writeFile(executable, changed);
|
|
const changedNib = nib.replaceAll("UIViewController", "ChangedController");
|
|
expect(changedNib).not.toBe(nib);
|
|
await writeFile(nibPath, changedNib);
|
|
const changedPlist =
|
|
"<plist><dict><key>CFBundleExecutable</key><string>Probe</string><key>Marker</key><string>ChangedController</string></dict></plist>";
|
|
if (operation === "inspect_plist")
|
|
await writeFile(join(contents, "Info.plist"), changedPlist);
|
|
const stale = await call(operation, parameters);
|
|
// The open session keeps the admitted digest, so repeating this request
|
|
// cannot observe the replacement. Reopening is what acquires it.
|
|
const staleError = parseMcpToolError(stale).error;
|
|
expect(staleError).toMatchObject({
|
|
code: "artifact_operation_failed",
|
|
category: "integrity_mismatch",
|
|
retryable: false,
|
|
details: {
|
|
reason: "integrity",
|
|
integrity_check: "admitted-identity",
|
|
},
|
|
});
|
|
expect(staleError.retry_class).not.toBe("same_call");
|
|
|
|
expect((await call("open_binary", { path: app })).isError).not.toBe(true);
|
|
const after = await call(operation, parameters);
|
|
expect(after.isError).not.toBe(true);
|
|
const refreshed = parseEvidence(after.structuredContent);
|
|
expect(fileIdentity(refreshed.subject).sha256).toBe(
|
|
createHash("sha256").update(changed).digest("hex"),
|
|
);
|
|
const nibHash = createHash("sha256").update(changedNib).digest("hex");
|
|
if (operation === "inspect_plist") {
|
|
const inspected = inspectPlistSchema.parse(refreshed.normalized_result);
|
|
expect(inspected.value).toMatchObject({ Marker: "ChangedController" });
|
|
expect(inspected.source_sha256).toBe(
|
|
createHash("sha256").update(changedPlist).digest("hex"),
|
|
);
|
|
}
|
|
if (operation === "decode_interface_builder") {
|
|
const report = interfaceBuilderAnalysisSchema.parse(
|
|
refreshed.normalized_result,
|
|
);
|
|
expect(report.documents).toContainEqual(
|
|
expect.objectContaining({
|
|
relative_path: "Contents/Resources/Main.nib",
|
|
archive_sha256: nibHash,
|
|
}),
|
|
);
|
|
expect(report.graph.nodes).toContainEqual(
|
|
expect.objectContaining({
|
|
attributes: expect.objectContaining({
|
|
class_name: "ChangedController",
|
|
}),
|
|
}),
|
|
);
|
|
}
|
|
if (operation === "inspect_keyed_archive") {
|
|
const report = keyedArchiveResultSchema.parse(
|
|
refreshed.normalized_result,
|
|
);
|
|
expect(report.archive_sha256).toBe(nibHash);
|
|
expect(report.objects).toContainEqual(
|
|
expect.objectContaining({ class_name: "ChangedController" }),
|
|
);
|
|
}
|
|
},
|
|
);
|