feat(apple): project macOS bundle anatomy in application graphs

project_apple_application_graph accepted only IPA inventories. It now
also projects macOS .app directories and ZIP or DMG inventories that
contain applications. It reports application roots, platforms, and
every nested bundle with its path-convention role, layout, parent,
Info.plist path, executable candidates, and signing paths:
- roles: app extensions, XPC services (including inside frameworks),
  frameworks, login items, system and driver extensions, plug-ins,
  resource bundles, and helper or nested applications;
- privileged helpers in Contents/Library/LaunchServices and launchd
  plists in Contents/Library/LaunchAgents or LaunchDaemons;
- direct files of Contents/Helpers;
- symlinks by path. Their targets are not inventoried, so versioned
  frameworks are described through their real Versions/<version>/
  directories.

AppleDouble sidecars (._* and __MACOSX/) are excluded from roles. A DMG
whose contents could not be inventoried is reported as partial. Other
inventory formats remain input errors. The projection still reads no
plist or CMS semantics; it points callers at inspect_plist.

The result schema is additive. projection_id now covers the new fields,
so IPA projection IDs differ from earlier versions.

verify:macos-bundle compiles a source-owned app with clang (CLT only).
It packs it as a directory, a ditto ZIP, and an APFS DMG, and checks
identical anatomy through the CLI with stdio MCP parity. It runs in the
macOS CI job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822
2026-10-07 10:06:48 +00:00
co-authored by Claude Opus 5.5
parent b72c079a9a
commit dd3e7aef0d
22 changed files with 1481 additions and 75 deletions
+372
View File
@@ -0,0 +1,372 @@
import { createHash } from "node:crypto";
import { describe, expect, it } from "vitest";
import { projectAppleApplication } from "./appleApplication.js";
import { canonicalDigest } from "./comparisonSemantics.js";
import { createEvidence, type Evidence } from "./evidence.js";
import { jsonValueSchema } from "./jsonValue.js";
type EntryKind = "file" | "directory" | "symlink";
type RootFormat = "ipa" | "zip" | "dmg" | "directory" | "asar";
interface FixtureEntry {
readonly path: string;
readonly kind?: EntryKind;
readonly format?: string;
}
const sha = (text: string): string =>
createHash("sha256").update(text).digest("hex");
const artifactId = (sha256: string): string =>
`art_${canonicalDigest({ sha256 }, "Artifact inventory")}`;
/** Build one complete, content-addressed inventory page for pure projection tests. */
const inventoryEvidence = (
rootFormat: RootFormat,
subjectName: string,
entries: readonly FixtureEntry[],
): Evidence => {
const rootSha = sha(`${rootFormat}:${subjectName}`);
const rootId = artifactId(rootSha);
const node = (sha256: string, format: string) => ({
artifact_id: artifactId(sha256),
kind: "resource",
format,
sha256,
size: 1,
media_type: null,
architecture: null,
executable: false,
content_state: "materialized",
limitations: [],
});
const occurrence = (path: string, kind: EntryKind, id: string | null) => ({
occurrence_id:
path === "."
? `occ_${canonicalDigest({ root: rootId }, "Artifact inventory")}`
: `occ_${canonicalDigest(
{ root_artifact_id: rootId, logical_path: path, entry_kind: kind },
"Artifact inventory",
)}`,
artifact_id: id,
parent_occurrence_id: null,
logical_path: path,
entry_kind: kind,
declared_size: null,
compressed_size: null,
executable: false,
encrypted: false,
hash_status: "verified",
source_location: null,
limitations: [],
});
const nodes = new Map([[rootId, node(rootSha, rootFormat)]]);
const occurrences = [occurrence(".", "file", rootId)];
for (const { path, kind = "file", format = "file" } of entries) {
if (kind === "symlink") {
occurrences.push(occurrence(path, kind, null));
continue;
}
const contentSha = sha(`${kind}:${path}`);
const id = artifactId(contentSha);
nodes.set(
id,
node(contentSha, kind === "directory" ? "directory" : format),
);
occurrences.push(occurrence(path, kind, id));
}
const sortedNodes = [...nodes.values()].sort((left, right) =>
left.artifact_id.localeCompare(right.artifact_id),
);
const sortedOccurrences = occurrences.sort((left, right) =>
left.logical_path.localeCompare(right.logical_path, "en"),
);
const graphSha256 = canonicalDigest(
{
nodes: sortedNodes,
occurrences: sortedOccurrences,
edges: [],
integrity_contradictions: [],
},
"Artifact inventory",
);
return createEvidence(
{
path: `/fixtures/${subjectName}`,
sha256: rootSha,
format: rootFormat,
},
{ id: "rea-artifact-graph", name: "fixture", version: "1" },
{
operation: "inventory_artifact",
parameters: {},
confidence: "observed",
authority: "shipped-artifact",
result: jsonValueSchema.parse({
manifest: {
manifest_id: `agm_${canonicalDigest(
{ root_artifact_id: rootId, graph_sha256: graphSha256 },
"Artifact inventory",
)}`,
root_artifact_id: rootId,
root_sha256: rootSha,
root_format: rootFormat,
graph_sha256: graphSha256,
node_count: sortedNodes.length,
occurrence_count: sortedOccurrences.length,
edge_count: 0,
},
nodes: sortedNodes,
occurrences: sortedOccurrences,
edges: [],
provenance: [],
limitations: [],
}),
},
);
};
const project = (evidence: Evidence) =>
projectAppleApplication({ inventory_evidence: [evidence] });
const macho = (path: string): FixtureEntry => ({ path, format: "mach-o" });
describe("macOS application roots and bundle roles", () => {
it("treats an inventoried .app directory as its own application root", () => {
const result = project(
inventoryEvidence("directory", "Fixture.app", [
{ path: "Contents/Info.plist" },
macho("Contents/MacOS/Fixture"),
{ path: "Contents/_CodeSignature/CodeResources" },
{ path: "Contents/embedded.provisionprofile" },
macho("Contents/Library/LaunchServices/com.example.helper"),
{ path: "Contents/Library/LaunchDaemons/com.example.helper.plist" },
{ path: "Contents/Library/LaunchAgents/com.example.agent.plist" },
macho("Contents/Helpers/tool"),
macho("Contents/Helpers/Assistant.app/Contents/MacOS/Assistant"),
macho(
"Contents/Library/SystemExtensions/com.example.filter.systemextension/Contents/MacOS/com.example.filter",
),
macho(
"Contents/Library/SystemExtensions/com.example.driver.dext/driver",
),
{ path: "Contents/PlugIns/Preview.qlgenerator", kind: "directory" },
macho("Contents/PlugIns/Bridge.bundle/Contents/MacOS/Bridge"),
{ path: "Contents/Resources/Strings.bundle/Info.plist" },
{ path: "Contents/SharedSupport/Data.bundle", kind: "directory" },
macho("Contents/Resources/Embedded.app/Contents/MacOS/Embedded"),
]),
);
expect(result).toMatchObject({
root_format: "directory",
platforms: ["macos"],
application_roots: ["."],
});
expect(
result.bundles.map(({ path, role, layout, parent_path: parent }) => ({
path,
role,
layout,
parent,
})),
).toEqual([
{ path: ".", role: "application", layout: "macos-deep", parent: null },
{
path: "Contents/Helpers/Assistant.app",
role: "helper-application",
layout: "macos-deep",
parent: ".",
},
{
path: "Contents/Library/SystemExtensions/com.example.driver.dext",
role: "driver-extension",
layout: "shallow",
parent: ".",
},
{
path: "Contents/Library/SystemExtensions/com.example.filter.systemextension",
role: "system-extension",
layout: "macos-deep",
parent: ".",
},
{
path: "Contents/PlugIns/Bridge.bundle",
role: "plug-in",
layout: "macos-deep",
parent: ".",
},
{
path: "Contents/PlugIns/Preview.qlgenerator",
role: "plug-in",
layout: "shallow",
parent: ".",
},
{
path: "Contents/Resources/Embedded.app",
role: "nested-application",
layout: "macos-deep",
parent: ".",
},
{
path: "Contents/Resources/Strings.bundle",
role: "resource-bundle",
layout: "shallow",
parent: ".",
},
{
path: "Contents/SharedSupport/Data.bundle",
role: "bundle",
layout: "shallow",
parent: ".",
},
]);
expect(result.bundles[0]).toMatchObject({
info_plist_path: "Contents/Info.plist",
executable_candidates: ["Contents/MacOS/Fixture"],
signing_paths: [
"Contents/_CodeSignature/CodeResources",
"Contents/embedded.provisionprofile",
],
});
expect(
result.components.privileged_helpers.map(({ path }) => path),
).toEqual(["Contents/Library/LaunchServices/com.example.helper"]);
expect(
result.components.launchd_plists.map(({ path, domain }) => [
path,
domain,
]),
).toEqual([
["Contents/Library/LaunchAgents/com.example.agent.plist", "agent"],
["Contents/Library/LaunchDaemons/com.example.helper.plist", "daemon"],
]);
expect(result.components.helpers.map(({ path }) => path)).toEqual([
"Contents/Helpers/tool",
]);
});
it("does not make a non-application bundle directory an application root", () => {
const result = project(
inventoryEvidence("directory", "Service.xpc", [
{ path: "Contents/Info.plist" },
macho("Contents/MacOS/Service"),
]),
);
expect(result.application_roots).toEqual([]);
expect(result.bundles).toEqual([]);
expect(result.limitations).toContain(
"No application bundle (Payload/*.app or *.app/Contents) was present in the supplied inventory pages.",
);
});
});
describe("Apple bundle layouts and containers", () => {
it("follows versioned frameworks without resolving Versions/Current", () => {
const framework = "Fixture.app/Contents/Frameworks/Core.framework";
const result = project(
inventoryEvidence("zip", "Fixture.zip", [
macho("Fixture.app/Contents/MacOS/Fixture"),
{ path: `${framework}/Core`, kind: "symlink" },
{ path: `${framework}/Versions/Current`, kind: "symlink" },
macho(`${framework}/Versions/A/Core`),
{ path: `${framework}/Versions/A/Resources/Info.plist` },
{ path: `${framework}/Versions/A/_CodeSignature/CodeResources` },
macho(
`${framework}/Versions/A/XPCServices/Fetch.xpc/Contents/MacOS/Fetch`,
),
]),
);
const core = result.bundles.find(({ path }) => path === framework);
expect(core).toEqual({
path: framework,
parent_path: "Fixture.app",
layout: "versioned-framework",
role: "framework",
role_basis: "path-convention",
info_plist_path: `${framework}/Versions/A/Resources/Info.plist`,
executable_candidates: [`${framework}/Versions/A/Core`],
signing_paths: [`${framework}/Versions/A/_CodeSignature/CodeResources`],
});
expect(
result.bundles.find(({ role }) => role === "xpc-service")?.parent_path,
).toBe(framework);
expect(result.symlinks).toEqual([
`${framework}/Core`,
`${framework}/Versions/Current`,
]);
});
it("reports an unknown Info.plist when several framework versions exist", () => {
const framework = "Fixture.app/Contents/Frameworks/Core.framework";
const result = project(
inventoryEvidence("zip", "Fixture.zip", [
macho("Fixture.app/Contents/MacOS/Fixture"),
{ path: `${framework}/Versions/A/Resources/Info.plist` },
{ path: `${framework}/Versions/B/Resources/Info.plist` },
]),
);
expect(
result.bundles.find(({ path }) => path === framework)?.info_plist_path,
).toBeNull();
expect(result.limitations).toContainEqual(
expect.stringContaining("Versions/Current selects is unknown"),
);
});
it("excludes AppleDouble sidecars from roots and roles", () => {
const result = project(
inventoryEvidence("zip", "Fixture.zip", [
macho("Fixture.app/Contents/MacOS/Fixture"),
{ path: "Fixture.app/Contents/Library/LaunchDaemons/._helper.plist" },
{ path: "Fixture.app/Contents/Library/LaunchDaemons/helper.plist" },
{ path: "__MACOSX/Other.app/Contents/._Info.plist" },
]),
);
expect(result.application_roots).toEqual(["Fixture.app"]);
expect(result.components.launchd_plists.map(({ path }) => path)).toEqual([
"Fixture.app/Contents/Library/LaunchDaemons/helper.plist",
]);
expect(result.limitations).toContainEqual(
expect.stringContaining("AppleDouble sidecar entries"),
);
});
it("reports a DMG without inventoried contents as partial", () => {
const result = project(inventoryEvidence("dmg", "Fixture.dmg", []));
expect(result.coverage).toEqual({
status: "partial",
inventory_complete: true,
});
expect(result.limitations).toContain(
"The DMG's contents were not inventoried on this host; bundle absence is unknown.",
);
});
it("keeps IPA applications shallow and iOS", () => {
const result = project(
inventoryEvidence("ipa", "Fixture.ipa", [
{ path: "Payload/Fixture.app/Info.plist" },
macho("Payload/Fixture.app/Fixture"),
{ path: "Payload/Fixture.app/embedded.mobileprovision" },
macho("Payload/Fixture.app/PlugIns/Share.appex/Share"),
]),
);
expect(result.platforms).toEqual(["ios"]);
expect(
result.bundles.map(({ path, role, layout }) => [path, role, layout]),
).toEqual([
["Payload/Fixture.app", "application", "shallow"],
["Payload/Fixture.app/PlugIns/Share.appex", "app-extension", "shallow"],
]);
expect(result.bundles[0]?.executable_candidates).toEqual([
"Payload/Fixture.app/Fixture",
]);
});
it("rejects inventories that cannot contain an Apple application", () => {
expect(() => project(inventoryEvidence("asar", "app.asar", []))).toThrow(
"Apple application projection requires IPA, directory, ZIP, or DMG inventory Evidence (got asar)",
);
});
});