From 27c272bd9a42e7235c7991881196c60dbc126714 Mon Sep 17 00:00:00 2001 From: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Date: Wed, 7 Oct 2026 03:08:02 -0700 Subject: [PATCH] fix(artifacts): read AppKit connectors from flat keyed-archive NIBs (#900) * fix(artifacts): read AppKit connectors from flat keyed-archive NIBs Flat AppKit NIBs archive NSNibOutletConnector and NSNibControlConnector endpoints and the outlet or selector name under NSSource, NSDestination, and NSLabel. The keyed-archive parser read only source, destination, and label, so it skipped every such connector: XLD.app's 64 decoded NIBs had no outlet or target-action edges. The NS-prefixed keys now follow the same source and destination convention as compiled NIBArchive documents. Co-Authored-By: Claude Opus 5.5 * fix(artifacts): read AppKit control connectors from the control to its target NSNibControlConnector archives NSSource as the sending control and NSDestination as the action target. The previous commit inverted them like the unprefixed fields, so every flat AppKit action ran from the target to the control. The action trace selects a control and follows control -> action, and the graph keys the selector by its target, so neither could resolve these actions. The NS-prefixed keys are now read as source and destination for outlets and actions alike. Co-Authored-By: Claude Opus 5.5 * fix(artifacts): key AppKit connector endpoints by their node identity An NSSource or NSDestination object with an identifier field was referenced by that identifier, but its node is keyed by its authored object ID or archive UID. The connector then pointed at a synthetic unknown node. NS-prefixed endpoints now use the referenced object's node identity. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- src/domain/interfaceBuilderGraph.test.ts | 107 +++++++++++++++++++++ src/domain/interfaceBuilderKeyedArchive.ts | 19 ++++ 2 files changed, 126 insertions(+) diff --git a/src/domain/interfaceBuilderGraph.test.ts b/src/domain/interfaceBuilderGraph.test.ts index f28743322..d88547bb6 100644 --- a/src/domain/interfaceBuilderGraph.test.ts +++ b/src/domain/interfaceBuilderGraph.test.ts @@ -317,3 +317,110 @@ describe("keyed archive decoding and graph limits", () => { ); }); }); + +describe("AppKit keyed archive connectors", () => { + it("reads outlet and control connectors from NS-prefixed keys", () => { + const parsed = parseInterfaceBuilderRecords({ + $archiver: "NSKeyedArchiver", + $objects: [ + "$null", + { $class: { UID: 6 } }, + { $class: { UID: 7 }, identifier: "unrelated-identifier" }, + { + $class: { UID: 8 }, + NSSource: { UID: 1 }, + NSDestination: { UID: 2 }, + NSLabel: { UID: 5 }, + }, + { + $class: { UID: 9 }, + NSSource: { UID: 2 }, + NSDestination: { UID: 1 }, + NSLabel: { UID: 10 }, + }, + "o_button", + { + $classname: "NSCustomObject", + $classes: ["NSCustomObject", "NSObject"], + }, + { $classname: "NSButton", $classes: ["NSButton", "NSObject"] }, + { + $classname: "NSNibOutletConnector", + $classes: ["NSNibOutletConnector", "NSNibConnector", "NSObject"], + }, + { + $classname: "NSNibControlConnector", + $classes: ["NSNibControlConnector", "NSNibConnector", "NSObject"], + }, + "buttonClicked:", + ], + $top: {}, + }); + + expect(parsed.connections).toEqual([ + expect.objectContaining({ + kind: "outlet", + source_id: "1", + destination_id: "2", + label: "o_button", + }), + expect.objectContaining({ + kind: "action", + source_id: "2", + destination_id: "1", + label: "buttonClicked:", + }), + ]); + }); + + it("projects an AppKit action from the control through the selector to its target", () => { + const analysis = buildInterfaceBuilderAnalysis({ + targetSha256: hash, + toolVersion: "test", + documents: [ + { + relativePath: "MainMenu.nib", + archiveSha256: hash, + documentKind: "nib", + raw: { + $archiver: "NSKeyedArchiver", + $objects: [ + "$null", + { $class: { UID: 4 } }, + { $class: { UID: 5 } }, + { + $class: { UID: 6 }, + NSSource: { UID: 2 }, + NSDestination: { UID: 1 }, + NSLabel: "buttonClicked:", + }, + { $classname: "BuildDelegate", $classes: ["NSObject"] }, + { $classname: "NSButton", $classes: ["NSButton", "NSObject"] }, + { + $classname: "NSNibControlConnector", + $classes: ["NSNibControlConnector", "NSObject"], + }, + ], + $top: {}, + }, + }, + ], + limits: interfaceBuilderLimitsSchema.parse({}), + }); + const byId = new Map(analysis.graph.nodes.map((node) => [node.id, node])); + const action = analysis.graph.nodes.find(({ kind }) => kind === "action"); + const from = analysis.graph.edges + .filter( + ({ to, relation }) => relation === "target_action" && to === action?.id, + ) + .map(({ from: id }) => byId.get(id)?.name); + const to = analysis.graph.edges + .filter( + ({ from: id, relation }) => + relation === "target_action" && id === action?.id, + ) + .map(({ to: id }) => (id === null ? null : byId.get(id)?.kind)); + expect(from).toEqual(["NSButton"]); + expect(to).toEqual(expect.arrayContaining(["objc_selector", "unknown"])); + }); +}); diff --git a/src/domain/interfaceBuilderKeyedArchive.ts b/src/domain/interfaceBuilderKeyedArchive.ts index 24378a75c..e0ca876ae 100644 --- a/src/domain/interfaceBuilderKeyedArchive.ts +++ b/src/domain/interfaceBuilderKeyedArchive.ts @@ -216,8 +216,13 @@ const parseKeyedArchive = ( ) ) { const controlAction = /ControlConnector/iu.test(className); + // AppKit connectors (NSNibOutletConnector, NSNibControlConnector) + // archive NSSource as the outlet owner or sending control and + // NSDestination as the outlet value or action target, so they are read + // in that order without the inversion the unprefixed fields use. const source = firstObjectReference( controlAction ? fields.destination : fields.source, + archivedObjectReference(fields.NSSource), controlAction ? fields.to : fields.from, controlAction ? fields.target : fields.owner, ); @@ -229,11 +234,13 @@ const parseKeyedArchive = ( source_id: source, destination_id: firstObjectReference( controlAction ? fields.source : fields.destination, + archivedObjectReference(fields.NSDestination), controlAction ? fields.from : fields.to, controlAction ? fields.owner : fields.target, ), label: firstString( fields.label, + fields.NSLabel, fields.selector, fields.identifier, fields.action, @@ -285,6 +292,18 @@ export const firstString = (...values: unknown[]): string | null => { return null; }; +/** + * The node identity of a resolved archive reference: its authored object ID, + * otherwise its archive UID, which is how the referenced object's node is keyed. + */ +const archivedObjectReference = (value: unknown): string | null => { + const item = record(value); + if (typeof item.archiveUID !== "number") return null; + return ( + firstString(item.objectID, item["object-id"]) ?? String(item.archiveUID) + ); +}; + const firstObjectReference = (...values: unknown[]): string | null => { for (const value of values) { const direct = firstString(value);