* fix(apple): join recognized keys from NIBArchive field maps inspect-asset-catalog returned no resource-key matches for a decoded NIBArchive resource whose recognized image key is present in the archive. The NIBArchive projection groups an object's decoded fields under the node's nibValues attribute beside the class, label and ID it derives from the same archive, while the AppKit keyed-archive parser flattens the same fields onto the node. The catalog join read only the top level, so a recognized NSImageName on a decoded resource produced no row, and the empty-catalog limitation still claimed resource keys were reported as unmatched. Read an archive object's fields from both shapes, and give the namespace one owner by exporting NIB_VALUES_ATTRIBUTE from the projection that writes it. The recognized-field set stays in the catalog analysis, which owns that contract. Verified with 5 focused catalog tests, check:fast and verify:test-discovery on macOS arm64, and through the public CLI against the reported NIBArchive fixture. The keyed-archive control keeps its existing row, and a NIBArchive with only an unrecognized title still produces none. The ibtool-dependent native hierarchy lane requires full Xcode and was unavailable here. * fix(apple): normalize resource keys at the NIBArchive producer Fold the complementary implementation from #2256 into the earlier #2248 proposal, retaining the original contribution history. Co-authored-by: Thang Luu <76550342+thangldw@users.noreply.github.com> * fix(apple): restrict catalog joins to parsed resource nodes --------- Co-authored-by: 吴佳浩 <wujiahao@supremind.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> Co-authored-by: Thang Luu <76550342+thangldw@users.noreply.github.com>
129 lines
5.0 KiB
TypeScript
129 lines
5.0 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { buildBinary } from "plist";
|
|
|
|
import { encodeNibArchiveFixture } from "../../../src/artifacts/apple/NibArchive.fixture.js";
|
|
import { appleAssetCatalogResultSchema } from "../../../src/domain/apple/appleAssetCatalog.js";
|
|
import { interfaceBuilderAnalysisSchema } from "../../../src/domain/apple/interfaceBuilderGraph.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";
|
|
|
|
// Exact rooted NIBArchive bytes from #2176; inert parser fixture, not ibtool output.
|
|
const reportedArchive = Buffer.from(
|
|
"TklCQXJjaGl2ZQEAAAAKAAAABAAAADIAAAAEAAAAPgAAAAQAAABgAAAABAAAAHwAAACAgIGBgYGCgoGDg4GGTlNSb290hWltYWdli05TSW1hZ2VOYW1liE5TLmJ5dGVzgAoBAAAAgQoCAAAAggoDAAAAgwiHVG9vbGJhco6ATlNJQk9iamVjdERhdGGLgE5TSW1hZ2VWaWV3h4BOU0ltYWdliIBOU1N0cmluZw==",
|
|
"base64",
|
|
);
|
|
const resourceArchive = (field: string) =>
|
|
encodeNibArchiveFixture({
|
|
classes: ["NSIBObjectData", "NSImageView", "NSImage", "NSString"],
|
|
objects: [
|
|
{ classIndex: 0, values: { NSRoot: { ref: 1 } } },
|
|
{ classIndex: 1, values: { image: { ref: 2 } } },
|
|
{ classIndex: 2, values: { [field]: { ref: 3 } } },
|
|
{ classIndex: 3, values: { "NS.bytes": "Toolbar" } },
|
|
],
|
|
});
|
|
|
|
const keyedArchive = (nested: boolean) =>
|
|
buildBinary({
|
|
$archiver: "NSKeyedArchiver",
|
|
$version: 100000,
|
|
$top: { root: { UID: 1 } },
|
|
$objects: [
|
|
"$null",
|
|
{
|
|
$class: { UID: 2 },
|
|
...(nested
|
|
? { nibValues: { NSImageName: "Toolbar" } }
|
|
: { NSImageName: "Toolbar" }),
|
|
},
|
|
{ $classname: "NSImage", $classes: ["NSImage", "NSObject"] },
|
|
],
|
|
});
|
|
|
|
cliTest.skipIf(process.platform !== "darwin")(
|
|
"retains recognized NIBArchive resource keys and provenance through CLI and MCP without a catalog",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-asset-resource-keys-");
|
|
const { call } = await connectLocalToolsMcp();
|
|
for (const [name, field, archive, recognized] of [
|
|
["reported", "NSImageName", reportedArchive, true],
|
|
["alias", "imageName", resourceArchive("imageName"), true],
|
|
["title", "title", resourceArchive("title"), false],
|
|
["keyed-direct", "NSImageName", keyedArchive(false), true],
|
|
["keyed-nested", "NSImageName", keyedArchive(true), false],
|
|
] as const) {
|
|
const app = join(root, `${name}.app`);
|
|
const contents = join(app, "Contents");
|
|
await mkdir(join(contents, "Resources"), { recursive: true });
|
|
await mkdir(join(contents, "MacOS"));
|
|
const mach = Buffer.alloc(32);
|
|
mach.writeUInt32LE(0xfeedfacf, 0);
|
|
mach.writeUInt32LE(0x0100000c, 4);
|
|
mach.writeUInt32LE(2, 12);
|
|
await writeFile(join(contents, "MacOS", "App"), mach);
|
|
await writeFile(
|
|
join(contents, "Info.plist"),
|
|
"<plist><dict><key>CFBundleExecutable</key><string>App</string></dict></plist>",
|
|
);
|
|
await writeFile(join(contents, "Resources", "Panel.nib"), archive);
|
|
const decoded = await cli.run({
|
|
arguments: ["decode-interface-builder", app, "--json"],
|
|
});
|
|
expect(decoded.exitCode, decoded.stderr).toBe(0);
|
|
const graph = interfaceBuilderAnalysisSchema.parse(
|
|
parseEvidence(decoded.json).normalized_result,
|
|
).graph;
|
|
expect(graph.truncated).toBe(false);
|
|
const resource = graph.nodes.find(
|
|
(node) =>
|
|
node.kind === "resource" && node.attributes.class_name === "NSImage",
|
|
);
|
|
expect(
|
|
name === "keyed-direct"
|
|
? resource?.attributes
|
|
: resource?.attributes.nibValues,
|
|
).toMatchObject({
|
|
[field]: "Toolbar",
|
|
});
|
|
const inspected = await cli.run({
|
|
arguments: ["inspect-asset-catalog", app, "--json"],
|
|
});
|
|
expect(inspected.exitCode, inspected.stderr).toBe(0);
|
|
const result = appleAssetCatalogResultSchema.parse(
|
|
parseEvidence(inspected.json).normalized_result,
|
|
);
|
|
expect(result.catalogs).toEqual([]);
|
|
expect(result.resource_key_matches).toEqual(
|
|
!recognized
|
|
? []
|
|
: [
|
|
{
|
|
source_node_id: resource?.id,
|
|
source_path: "Contents/Resources/Panel.nib",
|
|
source_archive_sha256: createHash("sha256")
|
|
.update(archive)
|
|
.digest("hex"),
|
|
field,
|
|
key: "Toolbar",
|
|
status: "unmatched",
|
|
renditions: [],
|
|
},
|
|
],
|
|
);
|
|
const opened = await call("open_binary", { path: app });
|
|
expect(opened.isError).not.toBe(true);
|
|
const mcp = await call("inspect_asset_catalog", {});
|
|
expect(mcp.isError).not.toBe(true);
|
|
expect(parseEvidence(mcp.structuredContent).normalized_result).toEqual(
|
|
result,
|
|
);
|
|
}
|
|
},
|
|
30_000,
|
|
);
|