fix(artifacts): project compiled AppKit actions from the control to its target
NSNibControlConnector archives the sending control as NSSource and the action target as NSDestination; a nil target is the first responder. The NIBArchive projection swapped them for control connectors, so every compiled AppKit action ran from its target to the control. The action trace, which follows control -> action, could not find them, and the selector node was keyed by the control instead of the target class. When the target was nil, the swapped source was null and the action was dropped: Chess lost 29 menu actions, KeepingYouAwake 7. Connectors now keep NSSource -> NSDestination. The NIBArchive test encoder moves to a fixture module so a bundle test can build compiled NIBs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f430c416c7
commit
b08228d19f
@@ -8,6 +8,7 @@ import { buildBinary } from "plist";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeInterfaceBuilderBundle } from "../../../src/application/InterfaceBuilderAnalysis.js";
|
||||
import { encodeNibArchiveFixture } from "../../../src/artifacts/NibArchive.fixture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const compile = promisify(execFile);
|
||||
@@ -71,6 +72,84 @@ describe("compiled Interface Builder bundle reader", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("projects compiled AppKit actions from the control to their target", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-test-");
|
||||
const bundle = join(root, "Example.app");
|
||||
const resources = join(bundle, "Contents", "Resources");
|
||||
await mkdir(resources, { recursive: true });
|
||||
// NSNibControlConnector archives the sending control as NSSource and its
|
||||
// target as NSDestination; a nil target is the first responder.
|
||||
await writeFile(
|
||||
join(resources, "Panel.nib"),
|
||||
encodeNibArchiveFixture({
|
||||
classes: [
|
||||
"NSNibExternalObjectPlaceholder",
|
||||
"NSButton",
|
||||
"NSNibControlConnector",
|
||||
"NSString",
|
||||
"NSMenuItem",
|
||||
],
|
||||
objects: [
|
||||
{ classIndex: 0, values: {} },
|
||||
{ classIndex: 1, values: {} },
|
||||
{
|
||||
classIndex: 2,
|
||||
values: {
|
||||
NSSource: { ref: 1 },
|
||||
NSDestination: { ref: 0 },
|
||||
NSLabel: { ref: 3 },
|
||||
},
|
||||
},
|
||||
{ classIndex: 3, values: { "NS.bytes": "doOK:" } },
|
||||
{ classIndex: 4, values: {} },
|
||||
{
|
||||
classIndex: 2,
|
||||
values: {
|
||||
NSSource: { ref: 4 },
|
||||
NSDestination: null,
|
||||
NSLabel: { ref: 6 },
|
||||
},
|
||||
},
|
||||
{ classIndex: 3, values: { "NS.bytes": "arrangeInFront:" } },
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const analysis = await analyzeInterfaceBuilderBundle({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "e".repeat(64),
|
||||
});
|
||||
const byId = new Map(analysis.graph.nodes.map((node) => [node.id, node]));
|
||||
const routes = analysis.graph.nodes
|
||||
.filter(({ kind }) => kind === "action")
|
||||
.map((action) => ({
|
||||
action: action.name,
|
||||
from: analysis.graph.edges
|
||||
.filter(
|
||||
({ relation, to }) =>
|
||||
relation === "target_action" && to === action.id,
|
||||
)
|
||||
.map(({ from }) => byId.get(from)?.name),
|
||||
to: analysis.graph.edges
|
||||
.filter(
|
||||
({ relation, from, to }) =>
|
||||
relation === "target_action" &&
|
||||
from === action.id &&
|
||||
(to === null || byId.get(to)?.kind !== "objc_selector"),
|
||||
)
|
||||
.map(({ to }) => (to === null ? null : byId.get(to)?.name)),
|
||||
}))
|
||||
.sort((left, right) => left.action.localeCompare(right.action));
|
||||
expect(routes).toEqual([
|
||||
{ action: "arrangeInFront:", from: ["NSMenuItem"], to: [null] },
|
||||
{
|
||||
action: "doOK:",
|
||||
from: ["NSButton"],
|
||||
to: ["NSNibExternalObjectPlaceholder"],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("honors cancellation during directory traversal", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-test-");
|
||||
const controller = new AbortController();
|
||||
|
||||
Reference in New Issue
Block a user