Merge origin/main into feat/signature-posture
Follow #952's layout: the code-signature lane moves to scripts/verify/apple/code-signature.mjs and uses the relocated bundle fixture builder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { createHash } from "node:crypto";
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import {
|
||||
artifactCli,
|
||||
artifactMcpResult,
|
||||
withArtifactMcp,
|
||||
} from "../../lib/artifact-e2e.mjs";
|
||||
|
||||
if (process.platform !== "darwin")
|
||||
throw new Error(
|
||||
"Asset catalog E2E requires macOS, Xcode actool and assetutil",
|
||||
);
|
||||
const exec = promisify(execFile);
|
||||
await exec("/usr/bin/xcrun", ["--find", "actool"]);
|
||||
await exec("/usr/bin/xcrun", ["--find", "clang"]);
|
||||
await exec("/usr/bin/assetutil", ["--version"]);
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-asset-e2e-"));
|
||||
try {
|
||||
const app = join(root, "Fixture.app");
|
||||
const resources = join(app, "Contents", "Resources");
|
||||
await mkdir(resources, { recursive: true });
|
||||
await mkdir(join(app, "Contents", "MacOS"), { recursive: true });
|
||||
await exec("/usr/bin/xcrun", [
|
||||
"clang",
|
||||
fileURLToPath(
|
||||
new URL(
|
||||
"../../../tests/conformance/interface-builder/fixture.c",
|
||||
import.meta.url,
|
||||
),
|
||||
),
|
||||
"-o",
|
||||
join(app, "Contents", "MacOS", "Fixture"),
|
||||
]);
|
||||
await writeFile(
|
||||
join(app, "Contents", "Info.plist"),
|
||||
'<?xml version="1.0"?><plist version="1.0"><dict><key>CFBundleExecutable</key><string>Fixture</string><key>CFBundleIdentifier</key><string>dev.rea.asset-fixture</string></dict></plist>',
|
||||
);
|
||||
await exec("/usr/bin/xcrun", [
|
||||
"actool",
|
||||
fileURLToPath(
|
||||
new URL(
|
||||
"../../../tests/conformance/native/Assets.xcassets",
|
||||
import.meta.url,
|
||||
),
|
||||
),
|
||||
"--compile",
|
||||
resources,
|
||||
"--platform",
|
||||
"macosx",
|
||||
"--minimum-deployment-target",
|
||||
"12.0",
|
||||
]);
|
||||
const raw = JSON.parse(
|
||||
(
|
||||
await exec("/usr/bin/assetutil", [
|
||||
"--info",
|
||||
join(resources, "Assets.car"),
|
||||
])
|
||||
).stdout,
|
||||
);
|
||||
const sha256 = createHash("sha256")
|
||||
.update(await readFile(join(resources, "Assets.car")))
|
||||
.digest("hex");
|
||||
const cli = await artifactCli("inspect-asset-catalog", app);
|
||||
assert.deepEqual(
|
||||
cli.records.map(({ metadata }) => metadata),
|
||||
raw,
|
||||
);
|
||||
assert.equal(cli.catalogs[0].sha256, sha256);
|
||||
assert.ok(
|
||||
cli.records.some(
|
||||
({ asset_name, metadata }) =>
|
||||
asset_name === "FixtureColor" && metadata.AssetType === "Color",
|
||||
),
|
||||
);
|
||||
await withArtifactMcp(app, async (client) => {
|
||||
assert.deepEqual(
|
||||
await artifactMcpResult(client, "inspect_asset_catalog"),
|
||||
cli,
|
||||
);
|
||||
const first = await artifactMcpResult(client, "inspect_asset_catalog", {
|
||||
limit: 1,
|
||||
});
|
||||
assert.equal(first.next_offset, 1);
|
||||
const next = await artifactMcpResult(client, "inspect_asset_catalog", {
|
||||
offset: first.next_offset,
|
||||
});
|
||||
assert.deepEqual([...first.records, ...next.records], cli.records);
|
||||
const invalid = await client.callTool({
|
||||
name: "inspect_asset_catalog",
|
||||
arguments: { offset: -1 },
|
||||
});
|
||||
assert.equal(invalid.isError, true);
|
||||
});
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({ ok: true, mocked: false, cli: true, stdio_mcp: true, records: raw.length, pagination: true, malformed_input_rejected: true })}\n`,
|
||||
);
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import {
|
||||
copyFile,
|
||||
mkdir,
|
||||
mkdtemp,
|
||||
realpath,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import {
|
||||
artifactCli,
|
||||
artifactMcpResult,
|
||||
withArtifactMcp,
|
||||
} from "../../lib/artifact-e2e.mjs";
|
||||
import {
|
||||
buildMacosBundleFixture,
|
||||
preflightMacosBundleFixture,
|
||||
} from "../../fixtures/apple/macos-bundle.mjs";
|
||||
|
||||
const exec = promisify(execFile);
|
||||
|
||||
await preflightMacosBundleFixture();
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-code-signature-"));
|
||||
|
||||
const facets = (signature) =>
|
||||
Object.fromEntries(
|
||||
signature.security_facets.map(({ facet, state }) => [facet, state]),
|
||||
);
|
||||
|
||||
/** Re-sign a copy of one fixture executable ad hoc with the given options. */
|
||||
const signedCopy = async (source, name, options) => {
|
||||
const path = join(root, name);
|
||||
await copyFile(source, path);
|
||||
await exec("/usr/bin/xcrun", [
|
||||
"codesign",
|
||||
"--force",
|
||||
"--sign",
|
||||
"-",
|
||||
...options,
|
||||
path,
|
||||
]);
|
||||
return path;
|
||||
};
|
||||
|
||||
const ENTITLEMENTS = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict>
|
||||
<key>com.apple.security.cs.disable-library-validation</key><true/>
|
||||
<key>com.apple.security.cs.allow-dyld-environment-variables</key><true/>
|
||||
<key>com.apple.security.get-task-allow</key><true/>
|
||||
<key>com.apple.security.cs.allow-jit</key><true/>
|
||||
</dict></plist>
|
||||
`;
|
||||
|
||||
try {
|
||||
const { app } = await buildMacosBundleFixture(root);
|
||||
const plain = await artifactCli("inspect-signature", app);
|
||||
assert.deepEqual(plain.code_directory.flags.names, ["adhoc"]);
|
||||
assert.equal(plain.verification.status, "valid");
|
||||
// The opened bundle is reported by its canonical path.
|
||||
assert.equal(plain.verification.path, await realpath(app));
|
||||
assert.equal(plain.stapled_ticket.status, "absent");
|
||||
assert.equal(plain.sealed_resources.status, "sealed");
|
||||
assert.deepEqual(facets(plain), {
|
||||
"library-validation": "not-enforced",
|
||||
"dyld-environment-variables": "honored",
|
||||
"debugger-attach": "allowed",
|
||||
"executable-memory": "unrestricted",
|
||||
"app-sandbox": "not-sandboxed",
|
||||
});
|
||||
// Deep verification reports the fixture's real nested code, all on disk.
|
||||
assert.ok(plain.verification.validated_nested_code.length > 0);
|
||||
assert.ok(
|
||||
!plain.limitations.some((limitation) =>
|
||||
limitation.includes("which does not exist"),
|
||||
),
|
||||
);
|
||||
await withArtifactMcp(app, async (client) => {
|
||||
const viaMcp = await artifactMcpResult(client, "inspect_signature");
|
||||
assert.deepEqual(
|
||||
{ ...viaMcp, provenance: [] },
|
||||
{ ...plain, provenance: [] },
|
||||
);
|
||||
});
|
||||
|
||||
const tool = join(app, "Contents/Helpers/rea-tool");
|
||||
const hardened = await artifactCli(
|
||||
"inspect-signature",
|
||||
await signedCopy(tool, "hardened", ["--options", "runtime"]),
|
||||
);
|
||||
assert.deepEqual(hardened.code_directory.flags.names, ["adhoc", "runtime"]);
|
||||
assert.equal(hardened.stapled_ticket.status, "not-applicable");
|
||||
assert.deepEqual(facets(hardened), {
|
||||
"library-validation": "enforced",
|
||||
"dyld-environment-variables": "ignored",
|
||||
"debugger-attach": "blocked",
|
||||
"executable-memory": "restricted",
|
||||
"app-sandbox": "not-sandboxed",
|
||||
});
|
||||
|
||||
const entitlements = join(root, "relaxed.entitlements");
|
||||
await writeFile(entitlements, ENTITLEMENTS);
|
||||
const relaxed = await artifactCli(
|
||||
"inspect-signature",
|
||||
await signedCopy(tool, "relaxed", [
|
||||
"--options",
|
||||
"runtime",
|
||||
"--entitlements",
|
||||
entitlements,
|
||||
]),
|
||||
);
|
||||
assert.deepEqual(facets(relaxed), {
|
||||
"library-validation": "disabled",
|
||||
"dyld-environment-variables": "honored",
|
||||
"debugger-attach": "allowed",
|
||||
"executable-memory": "jit-allowed",
|
||||
"app-sandbox": "not-sandboxed",
|
||||
});
|
||||
|
||||
const flagged = await artifactCli(
|
||||
"inspect-signature",
|
||||
await signedCopy(tool, "flagged", ["--options", "library,restrict"]),
|
||||
);
|
||||
assert.deepEqual(flagged.code_directory.flags.names, [
|
||||
"adhoc",
|
||||
"restrict",
|
||||
"library-validation",
|
||||
]);
|
||||
assert.equal(facets(flagged)["library-validation"], "enforced");
|
||||
assert.equal(facets(flagged)["dyld-environment-variables"], "ignored");
|
||||
|
||||
const platform = await artifactCli("inspect-signature", "/usr/bin/true");
|
||||
assert.notEqual(platform.code_directory.platform_identifier, null);
|
||||
assert.equal(platform.verification.status, "valid");
|
||||
assert.equal(facets(platform)["library-validation"], "enforced");
|
||||
// The platform rules rest on a real `anchor apple` requirement check.
|
||||
assert.ok(
|
||||
platform.provenance.some(({ command }) =>
|
||||
command.includes("-R=anchor apple"),
|
||||
),
|
||||
);
|
||||
|
||||
// Only deep verification sees a file added inside nested code.
|
||||
const nested = join(root, "Nested.app");
|
||||
await exec("/usr/bin/ditto", [app, nested]);
|
||||
await writeFile(
|
||||
join(nested, "Contents/XPCServices/Svc.xpc/Contents/added.txt"),
|
||||
"unsealed",
|
||||
);
|
||||
const nestedTamper = await artifactCli("inspect-signature", nested);
|
||||
assert.equal(nestedTamper.verification.status, "invalid");
|
||||
assert.ok(
|
||||
nestedTamper.verification.diagnostics.some((line) =>
|
||||
line.includes("Svc.xpc"),
|
||||
),
|
||||
JSON.stringify(nestedTamper.verification),
|
||||
);
|
||||
|
||||
await mkdir(join(app, "Contents/Resources"), { recursive: true });
|
||||
await writeFile(join(app, "Contents/Resources/added.txt"), "unsealed");
|
||||
const tampered = await artifactCli("inspect-signature", app);
|
||||
assert.equal(tampered.verification.status, "invalid");
|
||||
assert.ok(
|
||||
tampered.verification.diagnostics.some((line) => line.includes("added")),
|
||||
JSON.stringify(tampered.verification),
|
||||
);
|
||||
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({
|
||||
ok: true,
|
||||
mocked: false,
|
||||
cli: true,
|
||||
stdio_mcp: true,
|
||||
variants: [
|
||||
"adhoc",
|
||||
"runtime",
|
||||
"runtime+entitlements",
|
||||
"library,restrict",
|
||||
],
|
||||
platform_identifier: platform.code_directory.platform_identifier,
|
||||
tampered_verification: tampered.verification.status,
|
||||
nested_tamper_verification: nestedTamper.verification.status,
|
||||
})}\n`,
|
||||
);
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { parseBinaryTarget } from "../../../dist/application/BinaryTargetResolver.js";
|
||||
import { inspectAppleDispatchMetadata } from "../../../dist/native/AppleDispatchMetadata.js";
|
||||
|
||||
if (process.platform !== "darwin")
|
||||
throw new Error(
|
||||
"Apple dispatch verification requires macOS with a host Objective-C compiler and Foundation SDK",
|
||||
);
|
||||
const exec = promisify(execFile);
|
||||
const source = (name) =>
|
||||
fileURLToPath(
|
||||
new URL(`../../../tests/conformance/native/${name}`, import.meta.url),
|
||||
);
|
||||
|
||||
/** Both link modes: legacy LC_DYLD_INFO binds and the default chained fixups. */
|
||||
const LINK_MODES = [
|
||||
{
|
||||
mode: "dyld-info",
|
||||
flags: ["-Wl,-no_fixup_chains"],
|
||||
fixups: "LC_DYLD_INFO bind opcodes",
|
||||
swift: true,
|
||||
},
|
||||
{ mode: "chained", flags: [], fixups: "chained fixups:", swift: true },
|
||||
// arm64e uses authenticated chained pointers (DYLD_CHAINED_PTR_ARM64E_*).
|
||||
...(process.arch === "arm64"
|
||||
? [
|
||||
{
|
||||
mode: "chained-arm64e",
|
||||
flags: ["-arch", "arm64e"],
|
||||
fixups: "chained fixups: DYLD_CHAINED_PTR_ARM64E",
|
||||
swift: false,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
|
||||
const fixupCoverage = (metadata) =>
|
||||
metadata.coverage.find(({ facet }) => facet === "pointer_fixups");
|
||||
|
||||
const inspect = async (path) => {
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw target.error;
|
||||
return {
|
||||
target: target.value,
|
||||
metadata: (await inspectAppleDispatchMetadata(target.value, 5000)).result,
|
||||
};
|
||||
};
|
||||
|
||||
const checkObjc = (metadata, mode) => {
|
||||
const fixture = metadata.objc_classes.find(
|
||||
({ name, is_meta_class: meta }) => name === "ReaDispatchFixture" && !meta,
|
||||
);
|
||||
const category = metadata.objc_categories.find(
|
||||
({ name }) => name === "ReaDispatchAdditions",
|
||||
);
|
||||
const objcCoverage = metadata.coverage.find(
|
||||
({ facet }) => facet === "objc_class_method_ivar_metadata",
|
||||
);
|
||||
if (
|
||||
!metadata.objc_dispatch_implementations.some(
|
||||
(item) =>
|
||||
item.class_name === "ReaDispatchFixture" &&
|
||||
item.selector === "performAction:" &&
|
||||
item.implementation_address !== null,
|
||||
) ||
|
||||
!metadata.objc_dispatch_implementations.some(
|
||||
(item) =>
|
||||
item.selector === "fixtureVersion" && item.method_type === "class",
|
||||
) ||
|
||||
!metadata.objc_ivars.some(
|
||||
(item) => item.name === "state" && item.offset !== null,
|
||||
) ||
|
||||
!metadata.objc_protocol_records.some(
|
||||
(protocol) =>
|
||||
protocol.name === "ReaDispatchProtocol" &&
|
||||
protocol.methods.some(
|
||||
(method) => method.selector === "performAction:",
|
||||
) &&
|
||||
protocol.optional_methods.some(
|
||||
(method) => method.selector === "optionalFixtureValue",
|
||||
),
|
||||
) ||
|
||||
// The superclass lives in libobjc, so it comes from a bind fixup.
|
||||
fixture?.super_class !== "NSObject" ||
|
||||
fixture.decode.status !== "decoded" ||
|
||||
!fixture.properties.some(
|
||||
(property) =>
|
||||
property.name === "fixtureName" &&
|
||||
property.type_encoding === '@"NSString"' &&
|
||||
property.attributes.some(({ name }) => name === "C"),
|
||||
) ||
|
||||
category?.class_name !== "NSString" ||
|
||||
category.class_source !== "external" ||
|
||||
!category.instance_methods.includes("reaFixtureLength") ||
|
||||
!metadata.objc_dispatch_implementations.some(
|
||||
(item) =>
|
||||
item.class_name === "NSString" &&
|
||||
item.category === "ReaDispatchAdditions" &&
|
||||
item.selector === "reaFixtureLength",
|
||||
) ||
|
||||
objcCoverage?.status !== "complete" ||
|
||||
fixupCoverage(metadata)?.reason?.startsWith(mode.fixups) !== true
|
||||
)
|
||||
throw new Error(
|
||||
`Apple metadata fixture drifted (${mode.mode}): ${JSON.stringify(metadata)}`,
|
||||
);
|
||||
};
|
||||
|
||||
const checkSwift = (metadata, mode) => {
|
||||
if (
|
||||
!metadata.swift_dispatch_slots.some(
|
||||
(slot) =>
|
||||
slot.table_kind === "class_vtable" &&
|
||||
slot.owner === "ReaVtableFixture" &&
|
||||
slot.decode.status === "decoded",
|
||||
)
|
||||
)
|
||||
throw new Error(
|
||||
`Swift class vtable fixture unavailable (${mode.mode}): ${JSON.stringify(metadata.coverage)}`,
|
||||
);
|
||||
if (
|
||||
!metadata.swift_conformances.some(
|
||||
(item) =>
|
||||
item.type_name === "ReaWitnessFixture" &&
|
||||
item.protocol_name === "ReaWitnessFixtureProtocol",
|
||||
) ||
|
||||
!metadata.swift_dispatch_slots.some(
|
||||
(item) =>
|
||||
item.owner === "ReaWitnessFixture: ReaWitnessFixtureProtocol" &&
|
||||
item.implementation_address !== null,
|
||||
) ||
|
||||
fixupCoverage(metadata)?.reason?.startsWith(mode.fixups) !== true
|
||||
)
|
||||
throw new Error(
|
||||
`Swift metadata fixture drifted (${mode.mode}): ${JSON.stringify(metadata)}`,
|
||||
);
|
||||
};
|
||||
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-dispatch-"));
|
||||
try {
|
||||
const results = [];
|
||||
for (const mode of LINK_MODES) {
|
||||
const objcPath = join(root, `fixture-${mode.mode}`);
|
||||
await exec("/usr/bin/xcrun", [
|
||||
"clang",
|
||||
"-O2",
|
||||
"-framework",
|
||||
"Foundation",
|
||||
...mode.flags,
|
||||
source("dispatch.m"),
|
||||
"-o",
|
||||
objcPath,
|
||||
]);
|
||||
for (const variant of ["symbols", "stripped"]) {
|
||||
if (variant === "stripped")
|
||||
await exec("/usr/bin/strip", ["-x", objcPath]);
|
||||
const { target, metadata } = await inspect(objcPath);
|
||||
checkObjc(metadata, mode);
|
||||
results.push({
|
||||
variant: `objc-${mode.mode}-${variant}`,
|
||||
target_sha256: target.sha256,
|
||||
classes: metadata.objc_classes.length,
|
||||
categories: metadata.objc_categories.length,
|
||||
implementations: metadata.objc_dispatch_implementations.length,
|
||||
fixups: fixupCoverage(metadata)?.reason,
|
||||
});
|
||||
}
|
||||
if (!mode.swift) continue;
|
||||
const swiftPath = join(root, `libReaWitnessFixture-${mode.mode}.dylib`);
|
||||
await exec("/usr/bin/xcrun", [
|
||||
"swiftc",
|
||||
"-emit-library",
|
||||
"-O",
|
||||
...mode.flags
|
||||
.map((flag) => flag.replace(/^-Wl,/u, "-Xlinker\0"))
|
||||
.flatMap((flag) => flag.split("\0")),
|
||||
source("dispatch.swift"),
|
||||
"-o",
|
||||
swiftPath,
|
||||
]);
|
||||
for (const variant of ["symbols", "stripped"]) {
|
||||
if (variant === "stripped")
|
||||
await exec("/usr/bin/strip", ["-x", swiftPath]);
|
||||
const { target, metadata } = await inspect(swiftPath);
|
||||
checkSwift(metadata, mode);
|
||||
results.push({
|
||||
variant: `swift-${mode.mode}-${variant}`,
|
||||
target_sha256: target.sha256,
|
||||
conformances: metadata.swift_conformances.length,
|
||||
slots: metadata.swift_dispatch_slots.length,
|
||||
fixups: fixupCoverage(metadata)?.reason,
|
||||
});
|
||||
}
|
||||
}
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({ ok: true, target_executed: false, fixtures: results })}\n`,
|
||||
);
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { parseBinaryTarget } from "../../../dist/application/BinaryTargetResolver.js";
|
||||
import { ArtifactProvider } from "../../../dist/artifacts/ArtifactProvider.js";
|
||||
|
||||
const exec = promisify(execFile);
|
||||
const fixtureRoot = await mkdtemp(join(tmpdir(), "rea-interface-builder-"));
|
||||
const appPath = join(fixtureRoot, "Fixture.app");
|
||||
const resourcesPath = join(appPath, "Contents", "Resources");
|
||||
const executablePath = join(appPath, "Contents", "MacOS", "Fixture");
|
||||
const nibPath = join(resourcesPath, "Main.nib");
|
||||
const sourceRoot = fileURLToPath(
|
||||
new URL("../../../tests/conformance/interface-builder/", import.meta.url),
|
||||
);
|
||||
|
||||
try {
|
||||
await mkdir(join(appPath, "Contents", "MacOS"), { recursive: true });
|
||||
await mkdir(resourcesPath, { recursive: true });
|
||||
await writeFile(
|
||||
join(appPath, "Contents", "Info.plist"),
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict><key>CFBundleExecutable</key><string>Fixture</string><key>CFBundleIdentifier</key><string>dev.rea.interface-builder-fixture</string></dict></plist>\n`,
|
||||
);
|
||||
await exec("xcrun", [
|
||||
"ibtool",
|
||||
"--errors",
|
||||
"--warnings",
|
||||
"--compile",
|
||||
nibPath,
|
||||
join(sourceRoot, "Main.xib"),
|
||||
]);
|
||||
await exec("cc", [join(sourceRoot, "fixture.c"), "-o", executablePath]);
|
||||
|
||||
const target = await parseBinaryTarget(appPath);
|
||||
if (!target.ok) throw target.error;
|
||||
const execution = await new ArtifactProvider()
|
||||
.createClient(target.value)
|
||||
.execute("decode_interface_builder", {}, {});
|
||||
if (!execution.ok) throw execution.error;
|
||||
|
||||
const decoded = execution.value.result;
|
||||
assert.equal(decoded.documents.length, 1);
|
||||
assert.equal(
|
||||
decoded.documents[0]?.relative_path,
|
||||
"Contents/Resources/Main.nib",
|
||||
);
|
||||
assert.equal(decoded.documents[0]?.document_kind, "nib");
|
||||
assert.equal(decoded.documents[0]?.hierarchy_complete, true);
|
||||
assert.ok(decoded.documents[0]?.object_count > 0);
|
||||
assert.ok(decoded.documents[0]?.connection_count >= 2);
|
||||
|
||||
const button = decoded.graph.nodes.find(
|
||||
(node) => node.kind === "control" && node.name === "NSButton",
|
||||
);
|
||||
const action = decoded.graph.nodes.find(
|
||||
(node) => node.kind === "action" && node.name === "runAction:",
|
||||
);
|
||||
assert.ok(button, "compiled button control was not decoded");
|
||||
assert.ok(action, "compiled action selector was not decoded");
|
||||
assert.ok(
|
||||
decoded.graph.edges.some(
|
||||
(edge) =>
|
||||
edge.relation === "target_action" &&
|
||||
edge.resolution === "observed" &&
|
||||
(edge.from === action.id || edge.to === action.id),
|
||||
),
|
||||
"compiled target/action connection was not represented as observed",
|
||||
);
|
||||
assert.ok(
|
||||
decoded.graph.coverage.some(
|
||||
(facet) =>
|
||||
facet.facet === "archive_decode" && facet.status === "complete",
|
||||
),
|
||||
);
|
||||
assert.equal(decoded.graph.truncated, false);
|
||||
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({
|
||||
ok: true,
|
||||
fixture: "compiled-appkit-nib",
|
||||
provider: execution.value.provider,
|
||||
target_sha256: decoded.target_sha256,
|
||||
archive_sha256: decoded.documents[0].archive_sha256,
|
||||
objects: decoded.documents[0].object_count,
|
||||
connections: decoded.documents[0].connection_count,
|
||||
recovered_control: button.name,
|
||||
recovered_action: action.name,
|
||||
hierarchy_complete: decoded.documents[0].hierarchy_complete,
|
||||
truncated: decoded.graph.truncated,
|
||||
})}\n`,
|
||||
);
|
||||
} finally {
|
||||
await rm(fixtureRoot, { recursive: true, force: true });
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import assert from "node:assert/strict";
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
artifactCli,
|
||||
artifactMcpResult,
|
||||
withArtifactMcp,
|
||||
} from "../../lib/artifact-e2e.mjs";
|
||||
|
||||
if (process.platform !== "darwin")
|
||||
throw new Error(
|
||||
"Real Foundation keyed archive verification requires macOS and Xcode Swift tools",
|
||||
);
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-keyed-fixture-"));
|
||||
try {
|
||||
const archive = join(root, "model.plist");
|
||||
await promisify(execFile)("/usr/bin/xcrun", [
|
||||
"swift",
|
||||
"-module-cache-path",
|
||||
join(root, "modules"),
|
||||
fileURLToPath(
|
||||
new URL(
|
||||
"../../../tests/conformance/native/keyed-archive.swift",
|
||||
import.meta.url,
|
||||
),
|
||||
),
|
||||
archive,
|
||||
]);
|
||||
const graph = await artifactCli("inspect-keyed-archive", archive);
|
||||
const digest = createHash("sha256")
|
||||
.update(await readFile(archive))
|
||||
.digest("hex");
|
||||
assert.equal(graph.archive_sha256, digest);
|
||||
assert.equal(graph.target_sha256, digest);
|
||||
await withArtifactMcp(archive, async (client) => {
|
||||
assert.deepEqual(
|
||||
await artifactMcpResult(client, "inspect_keyed_archive"),
|
||||
graph,
|
||||
);
|
||||
const page = await artifactMcpResult(client, "inspect_keyed_archive", {
|
||||
offset: 1,
|
||||
limit: 1,
|
||||
});
|
||||
assert.deepEqual(page.objects, [graph.objects[1]]);
|
||||
assert.equal(page.next_offset, 2);
|
||||
const invalid = await client.callTool({
|
||||
name: "inspect_keyed_archive",
|
||||
arguments: { path: "../other.plist" },
|
||||
});
|
||||
assert.equal(invalid.isError, true);
|
||||
});
|
||||
const xml = join(root, "model.xml.plist");
|
||||
await promisify(execFile)("/usr/bin/plutil", [
|
||||
"-convert",
|
||||
"xml1",
|
||||
"-o",
|
||||
xml,
|
||||
archive,
|
||||
]);
|
||||
const xmlGraph = await artifactCli("inspect-keyed-archive", xml);
|
||||
const expected = JSON.parse(
|
||||
await readFile(
|
||||
new URL(
|
||||
"../../../tests/fixtures/golden/keyed-archive/graph.json",
|
||||
import.meta.url,
|
||||
),
|
||||
"utf8",
|
||||
),
|
||||
);
|
||||
assert.deepEqual(
|
||||
Object.fromEntries(
|
||||
Object.entries(xmlGraph).filter(
|
||||
([key]) =>
|
||||
!["archive_path", "archive_sha256", "target_sha256"].includes(key),
|
||||
),
|
||||
),
|
||||
expected,
|
||||
);
|
||||
assert.deepEqual(
|
||||
graph.references.map(({ source, path, target, status }) => ({
|
||||
source,
|
||||
path,
|
||||
target,
|
||||
status,
|
||||
})),
|
||||
xmlGraph.references.map(({ source, path, target, status }) => ({
|
||||
source,
|
||||
path,
|
||||
target,
|
||||
status,
|
||||
})),
|
||||
);
|
||||
if (
|
||||
graph?.archive_format !== "binary-plist" ||
|
||||
!graph.references.some(
|
||||
(link) =>
|
||||
link.source !== null &&
|
||||
link.source === link.target &&
|
||||
link.status === "resolved",
|
||||
) ||
|
||||
!graph.objects.some((item) => item.class_name?.includes("ReaArchiveRecord"))
|
||||
)
|
||||
throw new Error(
|
||||
`Real Foundation archive graph drifted: ${JSON.stringify(graph)}`,
|
||||
);
|
||||
const record = graph.objects.find((item) =>
|
||||
item.class_name?.includes("ReaArchiveRecord"),
|
||||
);
|
||||
if (
|
||||
graph.references.filter(
|
||||
(link) => link.target === record.id && link.source !== record.id,
|
||||
).length < 2
|
||||
)
|
||||
throw new Error("Real shared object identity was not preserved");
|
||||
const uidRoot = join(root, "uid-root.plist");
|
||||
await promisify(execFile)("/usr/bin/xcrun", [
|
||||
"swift",
|
||||
"-module-cache-path",
|
||||
join(root, "modules"),
|
||||
fileURLToPath(
|
||||
new URL(
|
||||
"../../../tests/conformance/native/keyed-archive-uid-root.swift",
|
||||
import.meta.url,
|
||||
),
|
||||
),
|
||||
uidRoot,
|
||||
]);
|
||||
const uidRootXml = join(root, "uid-root.xml.plist");
|
||||
await promisify(execFile)("/usr/bin/plutil", [
|
||||
"-convert",
|
||||
"xml1",
|
||||
"-o",
|
||||
uidRootXml,
|
||||
uidRoot,
|
||||
]);
|
||||
for (const path of [uidRoot, uidRootXml]) {
|
||||
const uidGraph = await artifactCli("inspect-keyed-archive", path);
|
||||
assert.deepEqual(
|
||||
uidGraph.references.map(({ source, path, target, status }) => ({
|
||||
source,
|
||||
path,
|
||||
target,
|
||||
status,
|
||||
})),
|
||||
[{ source: null, path: ["UID"], target: 1, status: "resolved" }],
|
||||
);
|
||||
}
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({ ok: true, mocked: false, cli: true, stdio_mcp: true, xml_golden: true, uid_named_root: true, format: graph.archive_format, objects: graph.total_objects, references: graph.total_references, shared_identity: true, cyclic_identity: true, target_classes_instantiated_by_reader: false })}\n`,
|
||||
);
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import {
|
||||
artifactCliEvidence,
|
||||
artifactMcpResult,
|
||||
withArtifactMcp,
|
||||
} from "../../lib/artifact-e2e.mjs";
|
||||
import {
|
||||
buildMacosBundleFixture,
|
||||
preflightMacosBundleFixture,
|
||||
} from "../../fixtures/apple/macos-bundle.mjs";
|
||||
|
||||
const exec = promisify(execFile);
|
||||
|
||||
await preflightMacosBundleFixture();
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-macos-bundle-"));
|
||||
|
||||
/** Bundle roles relative to the application root, independent of the container. */
|
||||
const anatomy = (projection, applicationRoot) => {
|
||||
const relative = (path) =>
|
||||
applicationRoot === "."
|
||||
? path
|
||||
: path === applicationRoot
|
||||
? "."
|
||||
: path.slice(applicationRoot.length + 1);
|
||||
const paths = (components) =>
|
||||
components.map(({ path }) => relative(path)).sort();
|
||||
return {
|
||||
bundles: projection.bundles.map((bundle) => ({
|
||||
path: relative(bundle.path),
|
||||
role: bundle.role,
|
||||
layout: bundle.layout,
|
||||
parent: bundle.parent_path === null ? null : relative(bundle.parent_path),
|
||||
info_plist: bundle.info_plist_path && relative(bundle.info_plist_path),
|
||||
executables: bundle.executable_candidates.map(relative),
|
||||
signing: bundle.signing_paths.map(relative),
|
||||
})),
|
||||
privileged_helpers: paths(projection.components.privileged_helpers),
|
||||
launchd_plists: projection.components.launchd_plists
|
||||
.map(({ path, domain }) => `${domain}:${relative(path)}`)
|
||||
.sort(),
|
||||
helpers: paths(projection.components.helpers),
|
||||
};
|
||||
};
|
||||
|
||||
const FRAMEWORK = "Contents/Frameworks/Core.framework";
|
||||
const EXPECTED_BUNDLES = [
|
||||
[".", "application", "macos-deep", null],
|
||||
[FRAMEWORK, "framework", "versioned-framework", "."],
|
||||
[
|
||||
`${FRAMEWORK}/Versions/A/XPCServices/FwSvc.xpc`,
|
||||
"xpc-service",
|
||||
"macos-deep",
|
||||
FRAMEWORK,
|
||||
],
|
||||
["Contents/Library/LoginItems/Login.app", "login-item", "macos-deep", "."],
|
||||
["Contents/PlugIns/Ext.appex", "app-extension", "macos-deep", "."],
|
||||
["Contents/XPCServices/Svc.xpc", "xpc-service", "macos-deep", "."],
|
||||
];
|
||||
|
||||
try {
|
||||
const { app } = await buildMacosBundleFixture(root);
|
||||
const zip = join(root, "MacFixture.zip");
|
||||
await exec("/usr/bin/ditto", ["-c", "-k", "--keepParent", app, zip]);
|
||||
const staging = join(root, "dmg-source");
|
||||
await mkdir(staging);
|
||||
await exec("/usr/bin/ditto", [app, join(staging, "MacFixture.app")]);
|
||||
await symlink("/Applications", join(staging, "Applications"));
|
||||
const dmg = join(root, "MacFixture.dmg");
|
||||
// The default APFS image attaches as an image disk plus a synthesized
|
||||
// container, which exercises detach of devices sharing one image.
|
||||
await exec("/usr/bin/hdiutil", [
|
||||
"create",
|
||||
"-quiet",
|
||||
"-srcfolder",
|
||||
staging,
|
||||
"-volname",
|
||||
"ReaFixture",
|
||||
"-format",
|
||||
"UDZO",
|
||||
dmg,
|
||||
]);
|
||||
|
||||
const containers = [
|
||||
{ target: app, format: "directory", applicationRoot: "." },
|
||||
{ target: zip, format: "zip", applicationRoot: "MacFixture.app" },
|
||||
{
|
||||
target: dmg,
|
||||
format: "dmg",
|
||||
applicationRoot: "MacFixture.dmg/ReaFixture/MacFixture.app",
|
||||
},
|
||||
];
|
||||
const anatomies = [];
|
||||
for (const { target, format, applicationRoot } of containers) {
|
||||
const inventory = await artifactCliEvidence("inspect-artifact", target);
|
||||
const input = join(root, `${format}-projection.json`);
|
||||
await writeFile(input, JSON.stringify({ inventory_evidence: [inventory] }));
|
||||
const evidence = await artifactCliEvidence(
|
||||
"project-apple-application-graph",
|
||||
input,
|
||||
);
|
||||
const projection = evidence.normalized_result;
|
||||
assert.equal(evidence.subject?.format, format);
|
||||
assert.equal(projection.root_format, format);
|
||||
assert.deepEqual(projection.platforms, ["macos"]);
|
||||
assert.deepEqual(projection.application_roots, [applicationRoot]);
|
||||
assert.equal(projection.coverage.status, "complete-within-inventory");
|
||||
const observed = anatomy(projection, applicationRoot);
|
||||
assert.deepEqual(
|
||||
observed.bundles.map(({ path, role, layout, parent }) => [
|
||||
path,
|
||||
role,
|
||||
layout,
|
||||
parent,
|
||||
]),
|
||||
EXPECTED_BUNDLES,
|
||||
`${format} bundle roles drifted`,
|
||||
);
|
||||
assert.deepEqual(observed.privileged_helpers, [
|
||||
"Contents/Library/LaunchServices/com.example.rea.helper",
|
||||
]);
|
||||
assert.deepEqual(observed.launchd_plists, [
|
||||
"agent:Contents/Library/LaunchAgents/com.example.rea.agent.plist",
|
||||
"daemon:Contents/Library/LaunchDaemons/com.example.rea.helper.plist",
|
||||
]);
|
||||
assert.deepEqual(observed.helpers, ["Contents/Helpers/rea-tool"]);
|
||||
assert.ok(
|
||||
projection.symlinks.some((path) =>
|
||||
path.endsWith(`${FRAMEWORK}/Versions/Current`),
|
||||
),
|
||||
"Versions/Current symlink was not reported",
|
||||
);
|
||||
anatomies.push(observed);
|
||||
if (format === "directory")
|
||||
await withArtifactMcp(app, async (client) => {
|
||||
assert.deepEqual(
|
||||
await artifactMcpResult(client, "project_apple_application_graph", {
|
||||
inventory_evidence: [inventory],
|
||||
}),
|
||||
projection,
|
||||
);
|
||||
});
|
||||
}
|
||||
assert.deepEqual(anatomies[1], anatomies[0], "ZIP anatomy differs");
|
||||
assert.deepEqual(anatomies[2], anatomies[0], "DMG anatomy differs");
|
||||
const { stdout: attached } = await exec("/usr/bin/hdiutil", ["info"]);
|
||||
assert.ok(!attached.includes(dmg), "DMG remained attached after inventory");
|
||||
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({
|
||||
ok: true,
|
||||
mocked: false,
|
||||
cli: true,
|
||||
stdio_mcp: true,
|
||||
containers: containers.map(({ format }) => format),
|
||||
bundles: EXPECTED_BUNDLES.length,
|
||||
dmg_detached: true,
|
||||
})}\n`,
|
||||
);
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
Reference in New Issue
Block a user