macOS 11 and later ship system libraries only inside the dyld shared cache. trace_dylib_resolution therefore left every /usr/lib and /System load undetermined, and REA had no way to see what a cache contains. inspect_dyld_shared_cache (CLI inspect-dyld-shared-cache) reads a cache file set selected by path, without an open target. Its pure TypeScript reader parses modern and legacy dyld_cache_header layouts and reports: - UUID, architecture, platform, OS version, Mac Catalyst alternate, cache type, shared region, max slide; - every VM mapping; - each subcache by file suffix, checked by UUID. A missing or mismatched subcache makes coverage partial; - the complete image list. For each requested install path it reads that image's load commands through the cache mappings with the existing Mach-O reader. trace_dylib_resolution accepts an optional shared_cache. Absolute candidates found in a cache that serves the process's CPU family resolve with the new outcome and status `shared-cache`. That status also takes precedence over later in-bundle fallbacks such as a back-deployed libswiftCore. The result names the cache UUID and OS version it used. verify:dyld-shared-cache checks every image in the host cache (3,649 on macOS 26.6), with dependencies and their re-export, weak, upward and delay-init attributes, against `dyld_info -all_dyld_cache -linked_dylibs`. It also checks CLI/MCP parity, and that each shared-cache edge in the fixture trace is a library dyld actually loads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
|
import { afterEach, expect, it } from "vitest";
|
|
import { z } from "zod";
|
|
|
|
import { dyldCacheFixture } from "../../../src/artifacts/DyldSharedCache.fixture.js";
|
|
import {
|
|
FILE_TYPE,
|
|
LC,
|
|
dylibCommand,
|
|
machoImage,
|
|
} from "../../../src/artifacts/MachoImage.fixture.js";
|
|
import { dyldSharedCacheResultSchema } from "../../../src/domain/dyldSharedCache.js";
|
|
import { createServer } from "../../../src/server/createServer.js";
|
|
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
const resources: Array<{ close(): Promise<unknown> }> = [];
|
|
afterEach(async () => {
|
|
for (const resource of resources.splice(0)) await resource.close();
|
|
});
|
|
|
|
it("inspects a dyld shared cache through MCP without a target", async () => {
|
|
const session = createTestBinarySession(() => {
|
|
throw new Error("shared cache inspection must not launch a provider");
|
|
});
|
|
const server = createServer(session, session);
|
|
const client = new Client({ name: "dyld-shared-cache-test", version: "1" });
|
|
resources.push(client, server, session);
|
|
const [a, b] = InMemoryTransport.createLinkedPair();
|
|
await server.connect(b);
|
|
await client.connect(a);
|
|
|
|
const directory = await createTestTempDirectory("rea-dyld-cache-mcp-");
|
|
const path = join(directory, "dyld_shared_cache_arm64e");
|
|
const fixture = dyldCacheFixture([
|
|
{
|
|
path: "/usr/lib/libSystem.B.dylib",
|
|
bytes: machoImage({
|
|
fileType: FILE_TYPE.dylib,
|
|
commands: [dylibCommand(LC.ID_DYLIB, "/usr/lib/libSystem.B.dylib")],
|
|
}),
|
|
},
|
|
]);
|
|
await writeFile(path, fixture.main);
|
|
|
|
const tools = await client.listTools();
|
|
expect(tools.tools.map(({ name }) => name)).toContain(
|
|
"inspect_dyld_shared_cache",
|
|
);
|
|
const called = await client.callTool({
|
|
name: "inspect_dyld_shared_cache",
|
|
arguments: { cache_path: path, images: ["/usr/lib/libSystem.B.dylib"] },
|
|
});
|
|
expect(called.isError, JSON.stringify(called.structuredContent)).not.toBe(
|
|
true,
|
|
);
|
|
const result = dyldSharedCacheResultSchema.parse(
|
|
z.object({ result: z.unknown() }).parse(called.structuredContent).result,
|
|
);
|
|
expect(result).toMatchObject({
|
|
architecture: "arm64e",
|
|
images_total: 1,
|
|
inspected_images: [
|
|
{ path: "/usr/lib/libSystem.B.dylib", status: "parsed" },
|
|
],
|
|
});
|
|
const missing = await client.callTool({
|
|
name: "inspect_dyld_shared_cache",
|
|
arguments: { cache_path: join(directory, "absent") },
|
|
});
|
|
expect(missing.isError).toBe(true);
|
|
});
|