mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
test(apple): share Interface Builder document setup (#15990)
This commit is contained in:
1 parent
19b9c89e88
commit
43f5417cc2
1 file changed
+116
-199
@@ -3,11 +3,25 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildInterfaceBuilderAnalysis,
|
||||
interfaceBuilderLimitsSchema,
|
||||
type InterfaceBuilderDocumentInput,
|
||||
} from "./interfaceBuilderGraph.js";
|
||||
import { parseInterfaceBuilderRecords } from "./interfaceBuilderKeyedArchive.js";
|
||||
|
||||
const hash = "a".repeat(64);
|
||||
|
||||
const analyzeDocument = (
|
||||
relativePath: string,
|
||||
documentKind: InterfaceBuilderDocumentInput["documentKind"],
|
||||
raw: unknown,
|
||||
limits = interfaceBuilderLimitsSchema.parse({}),
|
||||
) =>
|
||||
buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [{ relativePath, archiveSha256: hash, documentKind, raw }],
|
||||
limits,
|
||||
});
|
||||
|
||||
it("requires resource-root provenance when executable identity is unknown", () => {
|
||||
const resourceRoot = {
|
||||
caller_path: "/tmp/Fixture.app",
|
||||
@@ -93,19 +107,11 @@ describe("compiled Interface Builder graph projection", () => {
|
||||
"outlet",
|
||||
"segue",
|
||||
]);
|
||||
const result = buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [
|
||||
{
|
||||
relativePath: "Views/Main.storyboardc/scene.nib/objects.nib",
|
||||
archiveSha256: hash,
|
||||
documentKind: "storyboard_scene",
|
||||
raw,
|
||||
},
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse({}),
|
||||
});
|
||||
const result = analyzeDocument(
|
||||
"Views/Main.storyboardc/scene.nib/objects.nib",
|
||||
"storyboard_scene",
|
||||
raw,
|
||||
);
|
||||
expect(result.graph.nodes.some(({ name }) => name === "buildTapped:")).toBe(
|
||||
true,
|
||||
);
|
||||
@@ -158,28 +164,19 @@ 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" },
|
||||
],
|
||||
},
|
||||
},
|
||||
const result = analyzeDocument(
|
||||
"Legacy.nib",
|
||||
"nib",
|
||||
{
|
||||
"com.apple.ibtool.document.objects": {
|
||||
button: { class: "UIButton" },
|
||||
},
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse({ max_objects: 3 }),
|
||||
});
|
||||
"com.apple.ibtool.document.connections": {
|
||||
button: [{ type: "action", label: "save:", destinationId: "external" }],
|
||||
},
|
||||
},
|
||||
interfaceBuilderLimitsSchema.parse({ max_objects: 3 }),
|
||||
);
|
||||
expect(result.graph.edges).toContainEqual(
|
||||
expect.objectContaining({
|
||||
relation: "target_action",
|
||||
@@ -254,28 +251,16 @@ describe("keyed archive objects with unresolved classes", () => {
|
||||
});
|
||||
|
||||
it("keeps an unresolved hierarchy root's label and coverage in the graph", () => {
|
||||
const result = buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [
|
||||
{
|
||||
relativePath: "Main.nib",
|
||||
archiveSha256: hash,
|
||||
documentKind: "nib",
|
||||
raw: {
|
||||
$archiver: "NSKeyedArchiver",
|
||||
$version: 100000,
|
||||
$objects: [
|
||||
"$null",
|
||||
{ $class: { CF$UID: 99 }, label: "Unresolved object" },
|
||||
{ $classname: "UIView", $classes: ["UIView", "NSObject"] },
|
||||
{ $class: { CF$UID: 2 }, "NS.string": "ok" },
|
||||
],
|
||||
$top: { root: { CF$UID: 1 } },
|
||||
},
|
||||
},
|
||||
const result = analyzeDocument("Main.nib", "nib", {
|
||||
$archiver: "NSKeyedArchiver",
|
||||
$version: 100000,
|
||||
$objects: [
|
||||
"$null",
|
||||
{ $class: { CF$UID: 99 }, label: "Unresolved object" },
|
||||
{ $classname: "UIView", $classes: ["UIView", "NSObject"] },
|
||||
{ $class: { CF$UID: 2 }, "NS.string": "ok" },
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse({}),
|
||||
$top: { root: { CF$UID: 1 } },
|
||||
});
|
||||
const objectNodes = result.graph.nodes.filter(
|
||||
({ attributes }) => attributes.interface_builder_object_id !== undefined,
|
||||
@@ -324,19 +309,11 @@ describe("Interface Builder parser bounds", () => {
|
||||
expect(parsed.connections).toHaveLength(40_000);
|
||||
expect(parsed.omittedConnections).toBe(1);
|
||||
|
||||
const result = buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [
|
||||
{
|
||||
relativePath: "Main.storyboardc/scene.nib",
|
||||
archiveSha256: hash,
|
||||
documentKind: "storyboard_scene",
|
||||
raw,
|
||||
},
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse({}),
|
||||
});
|
||||
const result = analyzeDocument(
|
||||
"Main.storyboardc/scene.nib",
|
||||
"storyboard_scene",
|
||||
raw,
|
||||
);
|
||||
expect(result.graph.coverage).toContainEqual(
|
||||
expect.objectContaining({
|
||||
facet: "connections:Main.storyboardc/scene.nib",
|
||||
@@ -456,46 +433,39 @@ describe("Interface Builder graph limits", () => {
|
||||
|
||||
it("keeps hierarchy edges out of the connection edge budget", () => {
|
||||
const relativePath = "Main.nib";
|
||||
const result = buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [
|
||||
{
|
||||
relativePath,
|
||||
archiveSha256: hash,
|
||||
documentKind: "nib",
|
||||
raw: {
|
||||
"com.apple.ibtool.document.objects": {
|
||||
button: { class: "UIButton" },
|
||||
controller: { customClass: "MainViewController" },
|
||||
parent: { class: "UIView" },
|
||||
child: { class: "UIView" },
|
||||
const result = analyzeDocument(
|
||||
relativePath,
|
||||
"nib",
|
||||
{
|
||||
"com.apple.ibtool.document.objects": {
|
||||
button: { class: "UIButton" },
|
||||
controller: { customClass: "MainViewController" },
|
||||
parent: { class: "UIView" },
|
||||
child: { class: "UIView" },
|
||||
},
|
||||
"com.apple.ibtool.document.connections": {
|
||||
button: [
|
||||
{
|
||||
type: "action",
|
||||
label: "run:",
|
||||
destinationId: "controller",
|
||||
},
|
||||
"com.apple.ibtool.document.connections": {
|
||||
button: [
|
||||
{
|
||||
type: "action",
|
||||
label: "run:",
|
||||
destinationId: "controller",
|
||||
},
|
||||
],
|
||||
},
|
||||
"com.apple.ibtool.document.hierarchy": [
|
||||
{
|
||||
objectID: "parent",
|
||||
children: [
|
||||
{ objectID: "child", children: [{ objectID: "button" }] },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
"com.apple.ibtool.document.hierarchy": [
|
||||
{
|
||||
objectID: "parent",
|
||||
children: [
|
||||
{ objectID: "child", children: [{ objectID: "button" }] },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse({
|
||||
],
|
||||
},
|
||||
interfaceBuilderLimitsSchema.parse({
|
||||
max_objects: 20,
|
||||
max_connections: 1,
|
||||
}),
|
||||
});
|
||||
);
|
||||
|
||||
expect(
|
||||
result.graph.edges.filter(({ relation }) => relation === "target_action"),
|
||||
@@ -557,32 +527,23 @@ it.each([
|
||||
])(
|
||||
"keeps connection omissions separate from complete hierarchy for $relativePath / $sourceId",
|
||||
({ relativePath, sourceId }) => {
|
||||
const result = buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [
|
||||
{
|
||||
relativePath,
|
||||
archiveSha256: hash,
|
||||
documentKind: "nib",
|
||||
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": {
|
||||
[sourceId]: [
|
||||
{ type: "outlet", label: "view", destinationId: "kept" },
|
||||
],
|
||||
},
|
||||
},
|
||||
const result = analyzeDocument(
|
||||
relativePath,
|
||||
"nib",
|
||||
{
|
||||
"com.apple.ibtool.document.objects": {
|
||||
kept: { class: "UIView" },
|
||||
...(sourceId === "omitted" ? { omitted: { class: "UIButton" } } : {}),
|
||||
},
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse({ max_objects: 2 }),
|
||||
});
|
||||
"com.apple.ibtool.document.hierarchy": [{ objectID: "kept" }],
|
||||
"com.apple.ibtool.document.connections": {
|
||||
[sourceId]: [
|
||||
{ type: "outlet", label: "view", destinationId: "kept" },
|
||||
],
|
||||
},
|
||||
},
|
||||
interfaceBuilderLimitsSchema.parse({ max_objects: 2 }),
|
||||
);
|
||||
expect(result.documents[0]?.hierarchy_complete).toBe(true);
|
||||
expect(result.graph.nodes).toHaveLength(2);
|
||||
expect(result.graph.edges).toHaveLength(1);
|
||||
@@ -651,24 +612,17 @@ describe("Interface Builder hierarchy record limits", () => {
|
||||
maxObjects?: number,
|
||||
objects: Record<string, unknown> = {},
|
||||
) =>
|
||||
buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [
|
||||
{
|
||||
relativePath: "Main.nib",
|
||||
archiveSha256: hash,
|
||||
documentKind: "nib",
|
||||
raw: {
|
||||
"com.apple.ibtool.document.objects": objects,
|
||||
"com.apple.ibtool.document.hierarchy": hierarchy,
|
||||
},
|
||||
},
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse(
|
||||
analyzeDocument(
|
||||
"Main.nib",
|
||||
"nib",
|
||||
{
|
||||
"com.apple.ibtool.document.objects": objects,
|
||||
"com.apple.ibtool.document.hierarchy": hierarchy,
|
||||
},
|
||||
interfaceBuilderLimitsSchema.parse(
|
||||
maxObjects === undefined ? {} : { max_objects: maxObjects },
|
||||
),
|
||||
});
|
||||
);
|
||||
const hierarchyFacet = (result: ReturnType<typeof analyze>) =>
|
||||
result.graph.coverage.find(({ facet }) => facet === "hierarchy:Main.nib");
|
||||
|
||||
@@ -923,19 +877,7 @@ describe("unsupported keyed archive connections", () => {
|
||||
"other",
|
||||
]);
|
||||
|
||||
const analysis = buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [
|
||||
{
|
||||
relativePath: "MainMenu.nib",
|
||||
archiveSha256: hash,
|
||||
documentKind: "nib",
|
||||
raw,
|
||||
},
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse({}),
|
||||
});
|
||||
const analysis = analyzeDocument("MainMenu.nib", "nib", raw);
|
||||
expect(analysis.documents[0]?.connection_count).toBe(3);
|
||||
expect(analysis.graph.coverage).toContainEqual(
|
||||
expect.objectContaining({
|
||||
@@ -1036,38 +978,26 @@ describe("keyed archive class identity", () => {
|
||||
|
||||
describe("AppKit control connectors", () => {
|
||||
it("projects an AppKit action from the control through the selector to its target", () => {
|
||||
const analysis = buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [
|
||||
const analysis = analyzeDocument("MainMenu.nib", "nib", {
|
||||
$archiver: "NSKeyedArchiver",
|
||||
$objects: [
|
||||
"$null",
|
||||
{ $class: { CF$UID: 4 } },
|
||||
{ $class: { CF$UID: 5 } },
|
||||
{
|
||||
relativePath: "MainMenu.nib",
|
||||
archiveSha256: hash,
|
||||
documentKind: "nib",
|
||||
raw: {
|
||||
$archiver: "NSKeyedArchiver",
|
||||
$objects: [
|
||||
"$null",
|
||||
{ $class: { CF$UID: 4 } },
|
||||
{ $class: { CF$UID: 5 } },
|
||||
{
|
||||
$class: { CF$UID: 6 },
|
||||
NSSource: { CF$UID: 2 },
|
||||
NSDestination: { CF$UID: 1 },
|
||||
NSLabel: "buttonClicked:",
|
||||
},
|
||||
{ $classname: "BuildDelegate", $classes: ["NSObject"] },
|
||||
{ $classname: "NSButton", $classes: ["NSButton", "NSObject"] },
|
||||
{
|
||||
$classname: "NSNibControlConnector",
|
||||
$classes: ["NSNibControlConnector", "NSObject"],
|
||||
},
|
||||
],
|
||||
$top: {},
|
||||
},
|
||||
$class: { CF$UID: 6 },
|
||||
NSSource: { CF$UID: 2 },
|
||||
NSDestination: { CF$UID: 1 },
|
||||
NSLabel: "buttonClicked:",
|
||||
},
|
||||
{ $classname: "BuildDelegate", $classes: ["NSObject"] },
|
||||
{ $classname: "NSButton", $classes: ["NSButton", "NSObject"] },
|
||||
{
|
||||
$classname: "NSNibControlConnector",
|
||||
$classes: ["NSNibControlConnector", "NSObject"],
|
||||
},
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse({}),
|
||||
$top: {},
|
||||
});
|
||||
const byId = new Map(analysis.graph.nodes.map((node) => [node.id, node]));
|
||||
const action = analysis.graph.nodes.find(({ kind }) => kind === "action");
|
||||
@@ -1129,20 +1059,7 @@ describe("keyed archive unresolved connectors", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const project = (raw: unknown) =>
|
||||
buildInterfaceBuilderAnalysis({
|
||||
targetSha256: hash,
|
||||
toolVersion: "test",
|
||||
documents: [
|
||||
{
|
||||
relativePath: "Main.nib",
|
||||
archiveSha256: hash,
|
||||
documentKind: "nib",
|
||||
raw,
|
||||
},
|
||||
],
|
||||
limits: interfaceBuilderLimitsSchema.parse({}),
|
||||
});
|
||||
const project = (raw: unknown) => analyzeDocument("Main.nib", "nib", raw);
|
||||
|
||||
it("covers a resolvable connector as a complete examined connection", () => {
|
||||
const raw = rootedOutletArchive({
|
||||
|
||||
Reference in new issue
Block a user