fix(interface-builder): preserve budget-omitted destination evidence (#13674)

This commit is contained in:
morluto authored and GitHub committed 2026-11-22 22:37:20 +00:00
1 parent 6024860903
commit e1be55dcaf
2 files changed
+198 -188

No files matched your search

+164 -129
View File
@@ -44,6 +44,7 @@ describe("compiled Interface Builder graph projection", () => {
next: { customClass: "BuildViewController" },
},
"com.apple.ibtool.document.connections": {
earlierSource: [{ type: "segue", destinationId: "next" }],
button: [
{
type: "action",
@@ -54,6 +55,11 @@ describe("compiled Interface Builder graph projection", () => {
],
controller: [
{ type: "outlet", label: "buildButton", destinationId: "button" },
{
type: "segue",
identifier: "reuseSource",
destinationId: "earlierSource",
},
],
},
"com.apple.ibtool.document.hierarchy": [
@@ -64,9 +70,11 @@ describe("compiled Interface Builder graph projection", () => {
const decoded = parseInterfaceBuilderRecords(raw);
expect(decoded.objects).toHaveLength(3);
expect(decoded.connections.map(({ kind }) => kind)).toEqual([
"segue",
"action",
"segue",
"outlet",
"segue",
]);
const result = buildInterfaceBuilderAnalysis({
targetSha256: hash,
@@ -88,12 +96,17 @@ describe("compiled Interface Builder graph projection", () => {
artifact_path: "Views/Main.storyboardc/scene.nib/objects.nib",
artifact_sha256: hash,
});
expect(result.graph.edges).toContainEqual(
expect.objectContaining({
relation: "segue_to",
resolution: "observed",
}),
const source = result.graph.nodes.find(
({ name }) => name === "earlierSource",
);
const edge = result.graph.edges.find(({ evidence }) =>
evidence.some(({ description }) => description === "segue reuseSource"),
);
expect(edge).toMatchObject({
relation: "segue_to",
resolution: "observed",
to: source?.id,
});
expect(result.graph.coverage).toContainEqual(
expect.objectContaining({
facet: "hierarchy:Views/Main.storyboardc/scene.nib/objects.nib",
@@ -102,60 +115,6 @@ describe("compiled Interface Builder graph projection", () => {
);
});
it("keeps missing external destinations as unresolved evidence", () => {
const result = buildInterfaceBuilderAnalysis({
targetSha256: hash,
toolVersion: "test",
documents: [
{
relativePath: "Legacy.nib",
archiveSha256: hash,
documentKind: "nib",
raw: {
"com.apple.ibtool.document.objects": {
button: { class: "UIButton" },
},
"com.apple.ibtool.document.connections": {
button: [
{ type: "action", label: "save:", destinationId: "external" },
],
},
},
},
],
limits: interfaceBuilderLimitsSchema.parse({ max_objects: 3 }),
});
expect(result.graph.edges).toContainEqual(
expect.objectContaining({
relation: "target_action",
resolution: "unresolved",
reason: "endpoint_omitted_by_object_limit",
evidence: [
expect.objectContaining({
kind: "interface_builder_resource",
artifact_path: "Legacy.nib",
artifact_sha256: hash,
}),
],
}),
);
const retainedNodes = new Set(result.graph.nodes.map(({ id }) => id));
expect(
result.graph.edges.every(
({ from, to }) =>
retainedNodes.has(from) && (to === null || retainedNodes.has(to)),
),
).toBe(true);
expect(result.graph.coverage).toContainEqual(
expect.objectContaining({
facet: "graph_nodes",
status: "partial",
reason: "max_objects_reached",
}),
);
expect(result.graph.truncated).toBe(true);
});
it("reads recognized objects from a compiled NSKeyedArchiver object table", () => {
const parsed = parseInterfaceBuilderRecords({
$archiver: "NSKeyedArchiver",
@@ -181,6 +140,73 @@ describe("compiled Interface Builder graph projection", () => {
});
});
it("keeps an external action destination distinct from an omitted selector", () => {
const result = buildInterfaceBuilderAnalysis({
targetSha256: hash,
toolVersion: "test",
documents: [
{
relativePath: "Legacy.nib",
archiveSha256: hash,
documentKind: "nib",
raw: {
"com.apple.ibtool.document.objects": {
button: { class: "UIButton" },
},
"com.apple.ibtool.document.connections": {
button: [
{ type: "action", label: "save:", destinationId: "external" },
],
},
},
},
],
limits: interfaceBuilderLimitsSchema.parse({ max_objects: 3 }),
});
expect(result.graph.edges).toContainEqual(
expect.objectContaining({
relation: "target_action",
resolution: "unresolved",
to: null,
reason: "endpoint_omitted_by_object_limit",
evidence: [
expect.objectContaining({
kind: "interface_builder_resource",
description: "selector save:",
artifact_path: "Legacy.nib",
artifact_sha256: hash,
}),
],
}),
);
const destination = result.graph.edges.find(({ evidence }) =>
evidence.some(
({ description }) => description === "action destination external",
),
);
expect(destination).toMatchObject({
relation: "target_action",
resolution: "unresolved",
to: null,
reason: "destination_object_missing_or_external",
});
const retainedNodes = new Set(result.graph.nodes.map(({ id }) => id));
expect(
result.graph.edges.every(
({ from, to }) =>
retainedNodes.has(from) && (to === null || retainedNodes.has(to)),
),
).toBe(true);
expect(result.graph.coverage).toContainEqual(
expect.objectContaining({
facet: "graph_nodes",
status: "partial",
reason: "max_objects_reached",
}),
);
expect(result.graph.truncated).toBe(true);
});
describe("keyed archive objects with unresolved classes", () => {
it("keeps an archived object whose class reference cannot be resolved", () => {
const parsed = parseInterfaceBuilderRecords({
@@ -508,7 +534,7 @@ describe("Interface Builder graph limits", () => {
});
it.each([
{ relativePath: "Main.nib", sourceId: "missing" },
{ relativePath: "Main.nib", sourceId: "omitted" },
{ relativePath: "Views/:hierarchy:/Main.nib", sourceId: "missing" },
{ relativePath: "Main.nib", sourceId: "missing:hierarchy:source" },
])(
@@ -525,6 +551,9 @@ it.each([
raw: {
"com.apple.ibtool.document.objects": {
kept: { class: "UIView" },
...(sourceId === "omitted"
? { omitted: { class: "UIButton" } }
: {}),
},
"com.apple.ibtool.document.hierarchy": [{ objectID: "kept" }],
"com.apple.ibtool.document.connections": {
@@ -1197,47 +1226,86 @@ describe("keyed archive unresolved connectors", () => {
});
});
it("names the archive once per evidence record", () => {
it("attributes an omitted segue destination to the object budget and retains archive evidence", () => {
const relativePath = "Views/Main.storyboardc/scene.nib/objects.nib";
const result = buildInterfaceBuilderAnalysis({
targetSha256: hash,
toolVersion: "test",
documents: [
{
relativePath,
archiveSha256: hash,
documentKind: "storyboard_scene",
raw: {
"com.apple.ibtool.document.objects": {
controller: { customClass: "StoreViewController" },
next: { customClass: "BuildViewController" },
},
"com.apple.ibtool.document.connections": {
controller: [
{ type: "segue", identifier: "showBuild", destinationId: "next" },
],
},
},
const document = {
relativePath,
archiveSha256: hash,
documentKind: "storyboard_scene" as const,
raw: {
"com.apple.ibtool.document.objects": {
controller: { customClass: "StoreViewController" },
next: { customClass: "BuildViewController" },
},
],
limits: interfaceBuilderLimitsSchema.parse({}),
});
const evidence = [...result.graph.nodes, ...result.graph.edges].flatMap(
"com.apple.ibtool.document.connections": {
controller: [
{ type: "segue", identifier: "showBuild", destinationId: "next" },
{ type: "segue", identifier: "outside", destinationId: "external" },
],
},
},
};
const inspect = (max_objects: number) =>
buildInterfaceBuilderAnalysis({
targetSha256: hash,
toolVersion: "test",
documents: [document],
limits: interfaceBuilderLimitsSchema.parse({ max_objects }),
}).graph;
const complete = inspect(3);
const next = complete.nodes.find(
({ name }) => name === "BuildViewController",
);
const external = {
relation: "segue_to",
resolution: "unresolved",
to: null,
reason: "destination_scene_missing",
};
expect(complete.edges).toMatchObject([
{ relation: "segue_to", resolution: "observed", to: next?.id },
external,
]);
const limited = inspect(2);
expect(limited.edges).toMatchObject([
{
relation: "segue_to",
resolution: "unresolved",
to: null,
reason: "endpoint_omitted_by_object_limit",
evidence: complete.edges[0]?.evidence,
},
external,
]);
expect(
[complete, limited].map(({ coverage }) =>
coverage.find(({ facet }) => facet === `connections:${relativePath}`),
),
).toMatchObject([
{ status: "complete", reason: null, examined: 2, omitted: 0 },
{
status: "partial",
reason: "object_limit_reached",
examined: 2,
omitted: 0,
},
]);
const evidence = [...complete.nodes, ...complete.edges].flatMap(
(item) => item.evidence,
);
expect(new Set(evidence.map(({ artifact_path }) => artifact_path))).toEqual(
new Set([relativePath]),
);
expect(evidence.map(({ description }) => description)).toEqual(
expect.arrayContaining([
"compiled document",
"object controller",
"segue showBuild",
]),
);
expect(evidence.map(({ description }) => description)).toEqual([
"compiled document",
"object controller",
"object next",
"segue showBuild",
"segue outside",
]);
expect(
evidence.filter(({ description }) => description.includes(relativePath)),
).toEqual([]);
evidence.every(
({ artifact_path, artifact_sha256 }) =>
artifact_path === relativePath && artifact_sha256 === hash,
),
).toBe(true);
});
it("states each object's class, label, and ID once", () => {
@@ -1268,36 +1336,3 @@ it("states each object's class, label, and ID once", () => {
}),
]);
});
it("attributes connection omissions caused by missing source nodes to the object limit", () => {
const result = buildInterfaceBuilderAnalysis({
targetSha256: hash,
toolVersion: "test",
limits: interfaceBuilderLimitsSchema.parse({ max_objects: 1 }),
documents: [
{
relativePath: "Main.nib",
archiveSha256: hash,
documentKind: "nib",
raw: {
"com.apple.ibtool.document.objects": {
source: { class: "UIButton" },
destination: { class: "UIView" },
},
"com.apple.ibtool.document.connections": {
source: [
{ type: "action", label: "tap:", destinationId: "destination" },
],
},
},
},
],
});
expect(result.graph.coverage).toContainEqual(
expect.objectContaining({
facet: "connections:Main.nib",
status: "partial",
reason: "object_limit_reached",
}),
);
});
+34 -59
View File
@@ -330,8 +330,13 @@ export const buildInterfaceBuilderAnalysis = (input: {
attributes: { interface_builder_object_id: item.source_id },
evidence: evidenceFor(`connection source ${item.source_id}`),
});
const destinationId =
item.destination_id === null ? null : objectNodeId(item.destination_id);
let destinationId: string | null = null;
if (item.destination_id !== null) {
const id = objectNodeId(item.destination_id);
// A decoded local object can still be omitted by the graph budget.
if (objectIds.has(item.destination_id) || nodes.has(id))
destinationId = id;
}
if (item.kind === "action") {
const actionId = graphId("action", [item.id]);
const selectorId =
@@ -376,25 +381,15 @@ export const buildInterfaceBuilderAnalysis = (input: {
`selector ${item.label}`,
);
}
if (destinationId === null || !nodes.has(destinationId))
connect(
"connection",
graphId("action-edge", [item.id, "destination"]),
actionId,
null,
"target_action",
`action destination ${item.destination_id ?? "missing"}`,
"destination_object_missing_or_external",
);
else
connect(
"connection",
graphId("action-edge", [item.id, "destination"]),
actionId,
destinationId,
"target_action",
`action destination ${item.destination_id}`,
);
connect(
"connection",
graphId("action-edge", [item.id, "destination"]),
actionId,
destinationId,
"target_action",
`action destination ${item.destination_id ?? "missing"}`,
"destination_object_missing_or_external",
);
} else if (item.kind === "outlet") {
const outletId = graphId("outlet", [item.id]);
addNode({
@@ -413,45 +408,25 @@ export const buildInterfaceBuilderAnalysis = (input: {
"contains",
`outlet source ${item.source_id}`,
);
if (destinationId === null || !nodes.has(destinationId))
connect(
"connection",
graphId("outlet-edge", [item.id, "destination"]),
outletId,
null,
"outlet_to",
`outlet ${item.label ?? item.id}`,
"destination_object_missing_or_external",
);
else
connect(
"connection",
graphId("outlet-edge", [item.id, "destination"]),
outletId,
destinationId,
"outlet_to",
`outlet ${item.label ?? item.id}`,
);
connect(
"connection",
graphId("outlet-edge", [item.id, "destination"]),
outletId,
destinationId,
"outlet_to",
`outlet ${item.label ?? item.id}`,
"destination_object_missing_or_external",
);
} else if (item.kind === "segue") {
if (destinationId === null || !nodes.has(destinationId))
connect(
"connection",
graphId("segue", [index]),
sourceId,
null,
"segue_to",
`segue ${item.label ?? item.id}`,
"destination_scene_missing",
);
else
connect(
"connection",
graphId("segue", [index]),
sourceId,
destinationId,
"segue_to",
`segue ${item.label ?? item.id}`,
);
connect(
"connection",
graphId("segue", [index]),
sourceId,
destinationId,
"segue_to",
`segue ${item.label ?? item.id}`,
"destination_scene_missing",
);
} else {
connect(
"connection",