Merge origin/main into feat/artifact-integrity-policy
Keep both new MCP extraction tests, use main's relocated Apple domain imports, and regenerate the catalog metadata. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,7 @@ it("reuses immutable engine state while keeping each Evidence observation separa
|
||||
|
||||
it("bounds output per operation across a retained session rather than accumulating earlier captures", async () => {
|
||||
const { service, apk, launches, provider } = await setup("large-manifest");
|
||||
const expectedManifest = "x".repeat(1024 * 1024);
|
||||
for (let index = 0; index < 34; index += 1) {
|
||||
const result = await service.execute("inspect_android_package", {
|
||||
path: apk,
|
||||
@@ -78,8 +79,8 @@ it("bounds output per operation across a retained session rather than accumulati
|
||||
expect(
|
||||
androidResultSchemas.inspect_android_package.parse(
|
||||
result.value.normalized_result,
|
||||
).manifest.text.length,
|
||||
).toBe(1024 * 1024);
|
||||
).manifest.text,
|
||||
).toBe(expectedManifest);
|
||||
}
|
||||
expect(launches).toHaveLength(1);
|
||||
await provider.close();
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { PassThrough } from "node:stream";
|
||||
import {
|
||||
serializeMessage,
|
||||
type JSONRPCMessage,
|
||||
} from "@modelcontextprotocol/client";
|
||||
import { expect, it } from "vitest";
|
||||
import type { ProviderProcessHandle } from "../../../src/process/ProviderProcess.js";
|
||||
import {
|
||||
JadxMcpTransport,
|
||||
type JadxLauncher,
|
||||
} from "../../../src/android/JadxMcpTransport.js";
|
||||
|
||||
class FixtureProcess extends EventEmitter implements ProviderProcessHandle {
|
||||
readonly pid = 1;
|
||||
readonly stdout = new PassThrough();
|
||||
readonly stdin = new PassThrough();
|
||||
readonly stderr = new PassThrough();
|
||||
readonly exitCode = null;
|
||||
readonly signalCode = null;
|
||||
|
||||
kill(): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
it("decodes split UTF-8 and newline bytes, then routes multiple complete frames", async () => {
|
||||
const process = new FixtureProcess();
|
||||
const launcher: JadxLauncher = async ({ runId }) => ({
|
||||
process,
|
||||
ownership: {
|
||||
runId,
|
||||
leaderPid: process.pid,
|
||||
processGroupId: process.pid,
|
||||
expectedParentPid: process.pid,
|
||||
},
|
||||
cleanup: async () => {
|
||||
process.emit("exit", 0, null);
|
||||
process.emit("close", 0, null);
|
||||
process.stdout.end();
|
||||
process.stderr.end();
|
||||
process.stdin.end();
|
||||
return { cleaned: true, signaled: false };
|
||||
},
|
||||
});
|
||||
const transport = new JadxMcpTransport(
|
||||
{ command: "fixture", arguments: [] },
|
||||
launcher,
|
||||
);
|
||||
const received: JSONRPCMessage[] = [];
|
||||
transport.onmessage = (message) => received.push(message);
|
||||
|
||||
await transport.start();
|
||||
const first = {
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
result: { content: [{ type: "text", text: "snow 雪 🦊" }] },
|
||||
} satisfies JSONRPCMessage;
|
||||
const second = {
|
||||
jsonrpc: "2.0",
|
||||
id: 2,
|
||||
result: { content: [{ type: "text", text: "second" }] },
|
||||
} satisfies JSONRPCMessage;
|
||||
const third = {
|
||||
jsonrpc: "2.0",
|
||||
id: 3,
|
||||
result: { content: [{ type: "text", text: "third" }] },
|
||||
} satisfies JSONRPCMessage;
|
||||
for (const byte of Buffer.from(serializeMessage(first)))
|
||||
process.stdout.write(Buffer.from([byte]));
|
||||
process.stdout.write(
|
||||
Buffer.from(serializeMessage(second) + serializeMessage(third)),
|
||||
);
|
||||
|
||||
expect(received).toEqual([first, second, third]);
|
||||
await transport.close();
|
||||
});
|
||||
|
||||
it("accepts a complete JSON-RPC frame at the 8 MiB boundary", async () => {
|
||||
const process = new FixtureProcess();
|
||||
const launcher: JadxLauncher = async ({ runId }) => ({
|
||||
process,
|
||||
ownership: {
|
||||
runId,
|
||||
leaderPid: process.pid,
|
||||
processGroupId: process.pid,
|
||||
expectedParentPid: process.pid,
|
||||
},
|
||||
cleanup: async () => {
|
||||
process.emit("exit", 0, null);
|
||||
process.emit("close", 0, null);
|
||||
process.stdout.end();
|
||||
process.stderr.end();
|
||||
process.stdin.end();
|
||||
return { cleaned: true, signaled: false };
|
||||
},
|
||||
});
|
||||
const transport = new JadxMcpTransport(
|
||||
{ command: "fixture", arguments: [] },
|
||||
launcher,
|
||||
);
|
||||
const received: JSONRPCMessage[] = [];
|
||||
transport.onmessage = (message) => received.push(message);
|
||||
const response = {
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
result: { content: [{ type: "text", text: "" }] },
|
||||
} satisfies JSONRPCMessage;
|
||||
const emptyFrameBytes = Buffer.byteLength(serializeMessage(response)) - 1;
|
||||
const maxFrameResponse = {
|
||||
...response,
|
||||
result: {
|
||||
content: [
|
||||
{ type: "text", text: "x".repeat(8 * 1024 * 1024 - emptyFrameBytes) },
|
||||
],
|
||||
},
|
||||
} satisfies JSONRPCMessage;
|
||||
const frame = Buffer.from(serializeMessage(maxFrameResponse));
|
||||
|
||||
expect(frame.at(-1)).toBe(10);
|
||||
expect(frame.length - 1).toBe(8 * 1024 * 1024);
|
||||
await transport.start();
|
||||
process.stdout.write(frame);
|
||||
|
||||
expect(received).toEqual([maxFrameResponse]);
|
||||
await transport.close();
|
||||
});
|
||||
@@ -110,6 +110,32 @@ describe("ASAR path boundary", () => {
|
||||
});
|
||||
|
||||
describe("ASAR inventory freshness", () => {
|
||||
it("preserves missing-container I/O as an I/O failure instead of malformed format", async () => {
|
||||
const root = await createTestTempDirectory("rea-asar-missing-");
|
||||
const reader = new AsarArtifactReader(join(root, "missing.asar"));
|
||||
|
||||
await expect(
|
||||
reader.entries()[Symbol.asyncIterator]().next(),
|
||||
).rejects.toMatchObject({
|
||||
reason: "io",
|
||||
message: expect.stringContaining("ENOENT"),
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves an ASAR path replaced by a directory as a filesystem failure", async () => {
|
||||
const fixture = await archiveFixture();
|
||||
await rm(fixture.archive);
|
||||
await mkdir(fixture.archive);
|
||||
const reader = new AsarArtifactReader(fixture.archive);
|
||||
|
||||
await expect(
|
||||
reader.entries()[Symbol.asyncIterator]().next(),
|
||||
).rejects.toMatchObject({
|
||||
reason: "io",
|
||||
message: expect.stringContaining("EISDIR"),
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["archive", "bundle"] as const)(
|
||||
"refreshes a replaced archive when inventorying a %s target",
|
||||
async (target) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir, realpath, symlink, writeFile } from "node:fs/promises";
|
||||
import { chmod, mkdir, realpath, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
@@ -293,6 +293,122 @@ describe("app executable filename fidelity", () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe("iOS-style app bundle targets", () => {
|
||||
const plist = (name: string) =>
|
||||
`<plist><dict><key>CFBundleExecutable</key><string>${name}</string></dict></plist>`;
|
||||
|
||||
it("resolves a flat bundle's program file beside its Info.plist", async () => {
|
||||
const directory = await createTestTempDirectory("rea-target-");
|
||||
const app = join(directory, "Flat.app");
|
||||
await mkdir(app);
|
||||
await writeFile(join(app, "Info.plist"), plist("Flat"));
|
||||
await writeFile(join(app, "Flat"), thinMach(0xfeedfacf, 0x0100000c));
|
||||
const result = await parseBinaryTarget(app, directory, "arm64");
|
||||
expect(result.ok && result.value).toMatchObject({
|
||||
path: await realpath(join(app, "Flat")),
|
||||
bundleInfoPlist: join(await realpath(app), "Info.plist"),
|
||||
format: "mach-o",
|
||||
});
|
||||
});
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"keeps the declaring Info.plist for a symlinked program file",
|
||||
async () => {
|
||||
const directory = await createTestTempDirectory("rea-target-");
|
||||
const app = join(directory, "Linked.app");
|
||||
await mkdir(join(app, "bin"), { recursive: true });
|
||||
await writeFile(join(app, "Info.plist"), plist("Linked"));
|
||||
await writeFile(
|
||||
join(app, "bin", "real"),
|
||||
thinMach(0xfeedfacf, 0x0100000c),
|
||||
);
|
||||
await symlink("bin/real", join(app, "Linked"));
|
||||
const result = await parseBinaryTarget(app, directory, "arm64");
|
||||
expect(result.ok && result.value).toMatchObject({
|
||||
path: await realpath(join(app, "bin", "real")),
|
||||
bundleInfoPlist: join(await realpath(app), "Info.plist"),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"follows a readable Contents/Info.plist symlink",
|
||||
async () => {
|
||||
const directory = await createTestTempDirectory("rea-target-");
|
||||
const app = join(directory, "Linked.app");
|
||||
const contents = join(app, "Contents");
|
||||
await mkdir(join(contents, "MacOS"), { recursive: true });
|
||||
await writeFile(join(contents, "Real.plist"), plist("Linked"));
|
||||
await symlink("Real.plist", join(contents, "Info.plist"));
|
||||
await writeFile(
|
||||
join(contents, "MacOS", "Linked"),
|
||||
thinMach(0xfeedfacf, 0x0100000c),
|
||||
);
|
||||
const result = await parseBinaryTarget(app, directory, "arm64");
|
||||
expect(result.ok && result.value).toMatchObject({
|
||||
path: await realpath(join(contents, "MacOS", "Linked")),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
|
||||
"reports a wrapper it cannot read as a permission denial",
|
||||
async () => {
|
||||
const directory = await createTestTempDirectory("rea-target-");
|
||||
const app = join(directory, "Locked.app");
|
||||
const wrapper = join(app, "Wrapper");
|
||||
await mkdir(join(wrapper, "Locked.app"), { recursive: true });
|
||||
await chmod(wrapper, 0o000);
|
||||
try {
|
||||
const result = await parseBinaryTarget(app, directory, "arm64");
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected a permission denial");
|
||||
expect(result.error.message).toContain("permission denied");
|
||||
} finally {
|
||||
await chmod(wrapper, 0o755);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"resolves an iOS-on-Mac wrapper through its single Wrapper bundle",
|
||||
async () => {
|
||||
const directory = await createTestTempDirectory("rea-target-");
|
||||
const app = join(directory, "Phone.app");
|
||||
const wrapped = join(app, "Wrapper", "Phone.app");
|
||||
await mkdir(wrapped, { recursive: true });
|
||||
await writeFile(join(wrapped, "Info.plist"), plist("Phone"));
|
||||
await writeFile(join(wrapped, "Phone"), thinMach(0xfeedfacf, 0x0100000c));
|
||||
await symlink("Wrapper/Phone.app", join(app, "WrappedBundle"));
|
||||
const result = await parseBinaryTarget(app, directory, "arm64");
|
||||
expect(result.ok && result.value).toMatchObject({
|
||||
path: await realpath(join(wrapped, "Phone")),
|
||||
format: "mach-o",
|
||||
});
|
||||
|
||||
await mkdir(join(app, "Wrapper", "Second.app"));
|
||||
expect((await parseBinaryTarget(app, directory, "arm64")).ok).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"rejects a flat bundle program symlink that leaves the bundle",
|
||||
async () => {
|
||||
const directory = await createTestTempDirectory("rea-target-");
|
||||
const app = join(directory, "Escaping.app");
|
||||
const outside = join(directory, "outside");
|
||||
await mkdir(app);
|
||||
await writeFile(outside, thinMach(0xfeedfacf, 0x0100000c));
|
||||
await writeFile(join(app, "Info.plist"), plist("Escaping"));
|
||||
await symlink(outside, join(app, "Escaping"));
|
||||
const result = await parseBinaryTarget(app, directory, "arm64");
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected an escaping program file");
|
||||
expect(result.error.message).toContain("leaves the bundle root");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("DOS binary target I/O", () => {
|
||||
it("validates a complete DOS file beyond the initial metadata probe", async () => {
|
||||
const directory = await createTestTempDirectory("rea-dos-target-");
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
ProviderProcessSupervisor,
|
||||
spawnOwnedProviderProcess,
|
||||
} from "../../../src/process/ProviderProcess.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"rejects a FIFO replacement without blocking the owner process",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-directory-fifo-");
|
||||
await writeFile(join(root, "module.js"), "export {}\n");
|
||||
const probe = fileURLToPath(
|
||||
new URL("../../fixtures/directoryReaderFifoProbe.mjs", import.meta.url),
|
||||
);
|
||||
const readerModule = fileURLToPath(
|
||||
new URL(
|
||||
"../../../dist/artifacts/DirectoryArtifactReader.js",
|
||||
import.meta.url,
|
||||
),
|
||||
);
|
||||
const launch = await spawnOwnedProviderProcess({
|
||||
command: process.execPath,
|
||||
arguments: [probe, readerModule, root],
|
||||
runId: `rea-fifo-probe-${randomUUID()}`,
|
||||
cwd: tmpdir(),
|
||||
hostEnvironment: process.env,
|
||||
});
|
||||
const supervisor = new ProviderProcessSupervisor({
|
||||
...launch,
|
||||
ownsProcessLifetime: true,
|
||||
});
|
||||
|
||||
try {
|
||||
const closed = await supervisor.waitForOutputClose(2_000);
|
||||
expect(closed).toBe(true);
|
||||
expect(supervisor.snapshot().stdout.text.trim()).toBe("integrity");
|
||||
} finally {
|
||||
const stopped = await supervisor.stop({
|
||||
terminationGraceMs: 100,
|
||||
killGraceMs: 500,
|
||||
});
|
||||
expect(stopped.status).not.toBe("incomplete");
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -7,8 +7,8 @@ import { promisify } from "node:util";
|
||||
import { buildBinary } from "plist";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeInterfaceBuilderBundle } from "../../../src/application/InterfaceBuilderAnalysis.js";
|
||||
import { encodeNibArchiveFixture } from "../../../src/artifacts/NibArchive.fixture.js";
|
||||
import { analyzeInterfaceBuilderBundle } from "../../../src/artifacts/apple/InterfaceBuilderAnalysis.js";
|
||||
import { encodeNibArchiveFixture } from "../../../src/artifacts/apple/NibArchive.fixture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const compile = promisify(execFile);
|
||||
@@ -164,6 +164,50 @@ describe("compiled Interface Builder bundle reader", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("flat Interface Builder plist values", () => {
|
||||
it("decodes flat nib archives that hold data and date values", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-test-");
|
||||
const bundle = join(root, "Example.app");
|
||||
const resources = join(bundle, "Contents", "Resources", "English.lproj");
|
||||
await mkdir(resources, { recursive: true });
|
||||
await writeFile(
|
||||
join(resources, "Binary.nib"),
|
||||
buildBinary({
|
||||
$archiver: "NSKeyedArchiver",
|
||||
$version: 100000,
|
||||
$objects: [
|
||||
"$null",
|
||||
{ $class: { UID: 2 }, title: "Build", NSColor: { UID: 3 } },
|
||||
{ $classname: "NSButton", $classes: ["NSButton", "NSObject"] },
|
||||
{ $class: { UID: 4 }, NSWhite: Buffer.from("0.5\0", "ascii") },
|
||||
{ $classname: "NSColor", $classes: ["NSColor", "NSObject"] },
|
||||
],
|
||||
$top: { root: { UID: 1 } },
|
||||
}),
|
||||
);
|
||||
await writeFile(
|
||||
join(resources, "Xml.nib"),
|
||||
'<?xml version="1.0"?><plist version="1.0"><dict><key>$archiver</key><string>NSKeyedArchiver</string><key>$objects</key><array><string>$null</string><dict><key>NSWhite</key><data>MC41AA==</data><key>NSDate</key><date>2026-10-07T00:00:00Z</date></dict></array><key>$top</key><dict/></dict></plist>',
|
||||
);
|
||||
|
||||
const analysis = await analyzeInterfaceBuilderBundle({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "d".repeat(64),
|
||||
});
|
||||
|
||||
expect(
|
||||
analysis.documents.map(({ relative_path }) => relative_path).sort(),
|
||||
).toEqual([
|
||||
"Contents/Resources/English.lproj/Binary.nib",
|
||||
"Contents/Resources/English.lproj/Xml.nib",
|
||||
]);
|
||||
expect(analysis.graph.coverage).toContainEqual(
|
||||
expect.objectContaining({ facet: "archive_decode", status: "complete" }),
|
||||
);
|
||||
expect(analysis.graph.nodes.map(({ name }) => name)).toContain("Build");
|
||||
});
|
||||
});
|
||||
|
||||
describe("bounded Interface Builder archive decoding", () => {
|
||||
it("counts malformed archives against the document limit", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-test-");
|
||||
@@ -296,3 +340,92 @@ describe("bounded Interface Builder archive decoding", () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("compiled UIKit NIB connections", () => {
|
||||
it("projects UIKit runtime outlet and event connections", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-test-");
|
||||
const bundle = join(root, "Example.app");
|
||||
await mkdir(bundle, { recursive: true });
|
||||
await writeFile(
|
||||
join(bundle, "Cell.nib"),
|
||||
encodeNibArchiveFixture({
|
||||
classes: [
|
||||
"UIProxyObject",
|
||||
"UIClassSwapper",
|
||||
"UIButton",
|
||||
"UIRuntimeEventConnection",
|
||||
"UIRuntimeOutletConnection",
|
||||
"NSString",
|
||||
],
|
||||
objects: [
|
||||
{ classIndex: 0, values: { UIProxiedObjectIdentifier: { ref: 5 } } },
|
||||
{ classIndex: 1, values: { UIClassName: { ref: 6 } } },
|
||||
{ classIndex: 2, values: {} },
|
||||
{
|
||||
classIndex: 3,
|
||||
values: {
|
||||
UISource: { ref: 2 },
|
||||
UIDestination: { ref: 1 },
|
||||
UILabel: { ref: 7 },
|
||||
UIEventMask: 64,
|
||||
},
|
||||
},
|
||||
{
|
||||
classIndex: 4,
|
||||
values: {
|
||||
UISource: { ref: 1 },
|
||||
UIDestination: { ref: 2 },
|
||||
UILabel: { ref: 8 },
|
||||
},
|
||||
},
|
||||
{ classIndex: 5, values: { "NS.bytes": "IBFilesOwner" } },
|
||||
{ classIndex: 5, values: { "NS.bytes": "BuildCell" } },
|
||||
{ classIndex: 5, values: { "NS.bytes": "buildTapped:" } },
|
||||
{ classIndex: 5, values: { "NS.bytes": "buildButton" } },
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const analysis = await analyzeInterfaceBuilderBundle({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "e".repeat(64),
|
||||
});
|
||||
const byId = new Map(analysis.graph.nodes.map((node) => [node.id, node]));
|
||||
const named = (id: string | null) =>
|
||||
id === null ? null : (byId.get(id)?.name ?? null);
|
||||
const action = analysis.graph.nodes.find(({ kind }) => kind === "action");
|
||||
expect(action).toMatchObject({
|
||||
name: "buildTapped:",
|
||||
attributes: { ui_event_mask: 64 },
|
||||
});
|
||||
const actionEdges = analysis.graph.edges.filter(
|
||||
({ relation }) => relation === "target_action",
|
||||
);
|
||||
expect(
|
||||
actionEdges
|
||||
.filter(({ to }) => to === action?.id)
|
||||
.map(({ from }) => named(from)),
|
||||
).toEqual(["UIButton"]);
|
||||
expect(
|
||||
actionEdges
|
||||
.filter(({ from }) => from === action?.id)
|
||||
.map(({ to }) => named(to)),
|
||||
).toEqual(expect.arrayContaining(["BuildCell"]));
|
||||
const outlet = analysis.graph.nodes.find(({ kind }) => kind === "outlet");
|
||||
expect(outlet?.name).toBe("buildButton");
|
||||
expect(
|
||||
analysis.graph.edges
|
||||
.filter(
|
||||
({ relation, from }) =>
|
||||
relation === "outlet_to" && from === outlet?.id,
|
||||
)
|
||||
.map(({ to }) => named(to)),
|
||||
).toEqual(["UIButton"]);
|
||||
expect(
|
||||
analysis.graph.nodes.find(({ name }) => name === "IBFilesOwner")?.kind,
|
||||
).toBe("placeholder");
|
||||
expect(analysis.graph.nodes.map(({ name }) => name)).not.toContain(
|
||||
"UIRuntimeEventConnection",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
@@ -42,3 +42,59 @@ it.each(["\n", "\r\n", "\r", "\u2028", "\u2029"])(
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("resolves a bare source-map file name and worker URL next to the script", async () => {
|
||||
const root = await createTestTempDirectory("rea-source-map-relative-");
|
||||
await mkdir(join(root, "dist"));
|
||||
await writeFile(
|
||||
join(root, "dist", "app.js"),
|
||||
[
|
||||
'new Worker("worker.js");',
|
||||
'navigator.serviceWorker.register("sw.js");',
|
||||
"//# sourceMappingURL=app.js.map",
|
||||
].join("\n"),
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "dist", "worker.js"),
|
||||
"self.onmessage = () => {};",
|
||||
);
|
||||
await writeFile(join(root, "dist", "sw.js"), "self.onfetch = () => {};");
|
||||
await writeFile(
|
||||
join(root, "dist", "app.js.map"),
|
||||
JSON.stringify({
|
||||
version: 3,
|
||||
sources: ["../src/app.js"],
|
||||
sourcesContent: ['new Worker("worker.js");'],
|
||||
names: [],
|
||||
mappings: "AAAA",
|
||||
}),
|
||||
);
|
||||
const result = await reconstructJavaScriptArtifact({ input_path: root });
|
||||
const nodes = new Map(result.graph.nodes.map((node) => [node.node_id, node]));
|
||||
const mapEdge = result.graph.edges.find(
|
||||
({ relation, properties }) =>
|
||||
relation === "maps_to" && properties.declared_url === "app.js.map",
|
||||
);
|
||||
expect(mapEdge?.properties).toMatchObject({
|
||||
declared_url: "app.js.map",
|
||||
resolved_path: "dist/app.js.map",
|
||||
});
|
||||
expect(nodes.get(mapEdge?.target_node_id ?? "")?.identity.strategy).toBe(
|
||||
"content-digest",
|
||||
);
|
||||
const workerEdge = result.graph.edges.find(
|
||||
({ relation, source_node_id }) =>
|
||||
relation === "maps_to" && nodes.get(source_node_id)?.kind === "worker",
|
||||
);
|
||||
expect(workerEdge?.properties).toMatchObject({
|
||||
resolved_path: "dist/worker.js",
|
||||
});
|
||||
const serviceWorkerEdge = result.graph.edges.find(
|
||||
({ relation, source_node_id }) =>
|
||||
relation === "maps_to" &&
|
||||
nodes.get(source_node_id)?.kind === "service-worker",
|
||||
);
|
||||
expect(serviceWorkerEdge?.properties).toMatchObject({
|
||||
resolved_path: "dist/sw.js",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { decodeKeyedArchiveBytes } from "../../../src/artifacts/KeyedArchiveReader.js";
|
||||
import { decodeKeyedArchiveBytes } from "../../../src/artifacts/apple/KeyedArchiveReader.js";
|
||||
import {
|
||||
parseAppleAssetCatalogRecords,
|
||||
projectAppleAssetCatalogPage,
|
||||
} from "../../../src/domain/appleAssetCatalog.js";
|
||||
} from "../../../src/domain/apple/appleAssetCatalog.js";
|
||||
|
||||
const golden = (path: string) =>
|
||||
new URL(`../../fixtures/golden/${path}`, import.meta.url);
|
||||
|
||||
@@ -6,8 +6,8 @@ import { promisify } from "node:util";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { decodeNibArchive } from "../../../src/artifacts/NibArchive.js";
|
||||
import { analyzeInterfaceBuilderBundle } from "../../../src/application/InterfaceBuilderAnalysis.js";
|
||||
import { decodeNibArchive } from "../../../src/artifacts/apple/NibArchive.js";
|
||||
import { analyzeInterfaceBuilderBundle } from "../../../src/artifacts/apple/InterfaceBuilderAnalysis.js";
|
||||
|
||||
const compile = promisify(execFile);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { parseConfig } from "../../../src/config.js";
|
||||
import { createBinarySession } from "../../../src/application/runtime.js";
|
||||
import { keyedArchiveResultSchema } from "../../../src/domain/keyedArchive.js";
|
||||
import { keyedArchiveResultSchema } from "../../../src/domain/apple/keyedArchive.js";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
|
||||
@@ -224,6 +224,57 @@ it("extracts an unpacked integrity mismatch only when the caller records it", as
|
||||
}
|
||||
});
|
||||
|
||||
it("extracts a macOS app bundle through MCP", async () => {
|
||||
const root = await createTestTempDirectory("rea-artifact-extract-app-mcp-");
|
||||
const contents = join(root, "Fixture.app", "Contents");
|
||||
await mkdir(join(contents, "MacOS"), { recursive: true });
|
||||
const plist =
|
||||
'<?xml version="1.0"?><plist><dict><key>CFBundleExecutable</key><string>Fixture</string></dict></plist>';
|
||||
await writeFile(join(contents, "Info.plist"), plist);
|
||||
const header = Buffer.alloc(32);
|
||||
header.writeUInt32LE(0xfeedfacf, 0);
|
||||
header.writeUInt32LE(0x01000007, 4);
|
||||
header.writeUInt32LE(3, 8);
|
||||
header.writeUInt32LE(2, 12);
|
||||
await writeFile(join(contents, "MacOS", "Fixture"), header);
|
||||
|
||||
const session = createTestBinarySession(new ArtifactProvider());
|
||||
const server = createServer(session, session);
|
||||
const client = new Client({
|
||||
name: "artifact-extract-app-test",
|
||||
version: "1",
|
||||
});
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
let outputRoot: string | undefined;
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: join(root, "Fixture.app") },
|
||||
});
|
||||
expect(opened.isError).not.toBe(true);
|
||||
|
||||
const result = await client.callTool({
|
||||
name: "extract_artifact",
|
||||
arguments: {},
|
||||
});
|
||||
expect(result.isError).not.toBe(true);
|
||||
const normalized = z
|
||||
.object({ output_root: z.string() })
|
||||
.parse(compactResult(result.structuredContent).result);
|
||||
outputRoot = normalized.output_root;
|
||||
expect(
|
||||
await readFile(join(outputRoot, "Contents", "Info.plist"), "utf8"),
|
||||
).toBe(plist);
|
||||
} finally {
|
||||
await Promise.allSettled([client.close(), server.close(), session.close()]);
|
||||
if (outputRoot !== undefined)
|
||||
await rm(outputRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("records an explicitly continued mismatch, preserves verified siblings, and never reports equivalence", async () => {
|
||||
const root = await createTestTempDirectory("rea-asar-continue-mcp-");
|
||||
const source = join(root, "source");
|
||||
|
||||
@@ -3,7 +3,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
import { PROCEDURES, inventory, jsonResult } from "./enhancedToolsHarness.js";
|
||||
|
||||
import type { AnalysisOperationPort } from "../../../src/application/AnalysisProvider.js";
|
||||
import { MANAGED_WORKFLOW_TOOL_CONTRACTS } from "../../../src/contracts/managedWorkflowToolContracts.js";
|
||||
import { MANAGED_WORKFLOW_TOOL_CONTRACTS } from "../../../src/contracts/managed/managedWorkflowToolContracts.js";
|
||||
import { ENHANCED_TOOL_CONTRACTS } from "../../../src/contracts/enhancedToolContracts.js";
|
||||
import { SESSION_TOOL_CONTRACTS } from "../../../src/contracts/sessionToolContracts.js";
|
||||
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
|
||||
|
||||
@@ -13,7 +13,7 @@ import { composeBinarySession } from "../../../src/application/binary/BinarySess
|
||||
import type { BinarySession } from "../../../src/application/binary/BinarySession.js";
|
||||
import type { BinaryTarget } from "../../../src/domain/binaryTarget.js";
|
||||
import { SessionProviderRouter } from "../../../src/application/binary/SessionProviderRouter.js";
|
||||
import { MANAGED_NATIVE_VERIFICATION_EXAMPLE } from "../../../src/contracts/managedWorkflowExamples.js";
|
||||
import { MANAGED_NATIVE_VERIFICATION_EXAMPLE } from "../../../src/contracts/managed/managedWorkflowExamples.js";
|
||||
import { ManagedStaticProvider } from "../../../src/dotnet/ManagedStaticProvider.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { buildManagedPeFixture } from "../../../src/dotnet/ManagedPe.fixture.js";
|
||||
|
||||
@@ -6,6 +6,7 @@ import { z } from "zod";
|
||||
|
||||
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
|
||||
import { emptyArraySchema } from "../../../src/domain/emptyArraySchema.js";
|
||||
import { processScenarioSchema } from "../../../src/domain/processScenario.js";
|
||||
import { GENERATED_MCP_TOOL_CATALOG } from "../../../src/generatedMcpToolCatalog.js";
|
||||
import { toolRegistrationOptions } from "../../../src/server/toolRegistrationOptions.js";
|
||||
|
||||
@@ -27,6 +28,76 @@ function schemaErrors(tools: readonly ToolSchemas[]): string[] {
|
||||
);
|
||||
}
|
||||
|
||||
const advertiseAndEnforceProcessEnvironmentKeyConstraint =
|
||||
async (): Promise<void> => {
|
||||
const contract = TOOL_CONTRACTS.find(
|
||||
({ name }) => name === "capture_process_scenario",
|
||||
);
|
||||
if (contract === undefined)
|
||||
throw new Error("Process capture contract was not registered");
|
||||
|
||||
let handlerCalled = false;
|
||||
const server = new McpServer({ name: "process-schema", version: "0" });
|
||||
server.registerTool(
|
||||
contract.name,
|
||||
{
|
||||
title: contract.title,
|
||||
description: contract.description,
|
||||
inputSchema: processScenarioSchema.shape,
|
||||
},
|
||||
async () => {
|
||||
handlerCalled = true;
|
||||
return {
|
||||
content: [{ type: "text" as const, text: "handler ran" }],
|
||||
isError: true,
|
||||
};
|
||||
},
|
||||
);
|
||||
const client = new Client({ name: "process-schema", version: "0" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
({ name }) => name === contract.name,
|
||||
);
|
||||
if (advertised === undefined)
|
||||
throw new Error("Process capture tool was not advertised");
|
||||
|
||||
const validate = new Ajv2020({
|
||||
strict: false,
|
||||
validateFormats: false,
|
||||
}).compile(advertised.inputSchema);
|
||||
const valid = { executable: "node", environment: { APP_MODE: "test" } };
|
||||
const reserved = {
|
||||
executable: "node",
|
||||
environment: { REA_PROCESS_RUN_ID: "caller-value" },
|
||||
};
|
||||
const reservedWithTrailingNewline = {
|
||||
executable: "node",
|
||||
environment: { "REA_PROCESS_RUN_ID\n": "caller-value" },
|
||||
};
|
||||
expect(validate(valid)).toBe(true);
|
||||
expect(contract.inputSchema.safeParse(valid).success).toBe(true);
|
||||
expect(validate(reserved)).toBe(false);
|
||||
expect(contract.inputSchema.safeParse(reserved).success).toBe(false);
|
||||
expect(validate(reservedWithTrailingNewline)).toBe(true);
|
||||
expect(
|
||||
contract.inputSchema.safeParse(reservedWithTrailingNewline).success,
|
||||
).toBe(true);
|
||||
|
||||
const result = await client.callTool({
|
||||
name: contract.name,
|
||||
arguments: reserved,
|
||||
});
|
||||
expect(result.isError).toBe(true);
|
||||
expect(handlerCalled).toBe(false);
|
||||
} finally {
|
||||
await Promise.allSettled([client.close(), server.close()]);
|
||||
}
|
||||
};
|
||||
|
||||
describe("MCP JSON Schema validity", () => {
|
||||
it("preserves empty-array validation in the advertised representation", () => {
|
||||
const schema = z.toJSONSchema(emptyArraySchema);
|
||||
@@ -154,3 +225,8 @@ describe("MCP JSON Schema validity", () => {
|
||||
expect(schemaErrors(GENERATED_MCP_TOOL_CATALOG)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it(
|
||||
"advertises and enforces the process-owned environment key constraint",
|
||||
advertiseAndEnforceProcessEnvironmentKeyConstraint,
|
||||
);
|
||||
|
||||
@@ -8,12 +8,12 @@ import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js
|
||||
import {
|
||||
compareManagedMembersEvidenceValidated,
|
||||
compareManagedMemberPaths,
|
||||
} from "../../../../src/application/ManagedMemberComparisonService.js";
|
||||
} from "../../../../src/application/managed/ManagedMemberComparisonService.js";
|
||||
import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
|
||||
import { managedMemberComparisonResultSchema } from "../../../../src/domain/managedMemberComparison.js";
|
||||
import { managedMemberComparisonResultSchema } from "../../../../src/domain/managed/managedMemberComparison.js";
|
||||
import { createEvidence } from "../../../../src/domain/evidence.js";
|
||||
import { jsonValueSchema } from "../../../../src/domain/jsonValue.js";
|
||||
import { compareManagedMembersInputSchema } from "../../../../src/domain/managedMemberComparison.js";
|
||||
import { compareManagedMembersInputSchema } from "../../../../src/domain/managed/managedMemberComparison.js";
|
||||
import { inspectManagedMembersBytes } from "../../../../src/dotnet/ManagedMemberInspector.js";
|
||||
import { managedPeFixtureTarget } from "../../../../src/dotnet/ManagedPe.fixture.js";
|
||||
import { buildManagedPeFixture } from "../../../../src/dotnet/ManagedPe.fixture.js";
|
||||
|
||||
@@ -5,7 +5,7 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
compareManagedMembers,
|
||||
managedMemberComparisonResultSchema,
|
||||
} from "../../../../src/domain/managedMemberComparison.js";
|
||||
} from "../../../../src/domain/managed/managedMemberComparison.js";
|
||||
import { inspectManagedMembersBytes } from "../../../../src/dotnet/ManagedMemberInspector.js";
|
||||
import {
|
||||
buildManagedPeFixture,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { compareManagedMembers } from "../../../../src/domain/managedMemberComparison.js";
|
||||
import { compareManagedMembers } from "../../../../src/domain/managed/managedMemberComparison.js";
|
||||
import { inspectManagedMembersBytes } from "../../../../src/dotnet/ManagedMemberInspector.js";
|
||||
import {
|
||||
buildManagedPeFixture,
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
managedArtifactInspectionSchema,
|
||||
managedMemberInspectionSchema,
|
||||
managedNativeBoundaryInspectionSchema,
|
||||
} from "../../../../src/domain/managedArtifact.js";
|
||||
} from "../../../../src/domain/managed/managedArtifact.js";
|
||||
import { ManagedStaticProvider } from "../../../../src/dotnet/ManagedStaticProvider.js";
|
||||
import { buildManagedPeFixture } from "../../../../src/dotnet/ManagedPe.fixture.js";
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { join } from "node:path";
|
||||
import { buildBinary, parse } from "plist";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { inspectBundleKeyedArchive } from "../../../../src/artifacts/KeyedArchiveReader.js";
|
||||
import { inspectBundleKeyedArchive } from "../../../../src/artifacts/apple/KeyedArchiveReader.js";
|
||||
import { nativeFixture } from "../../../fixtures/nativeCommands.js";
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
|
||||
|
||||
@@ -61,6 +61,15 @@ describe("native DMG artifact reader", () => {
|
||||
run(arguments_) {
|
||||
if (arguments_[0] === "detach")
|
||||
return Promise.reject(new Error("detach failed"));
|
||||
if (arguments_[0] === "info")
|
||||
return Promise.resolve({
|
||||
stdout: build({
|
||||
images: [
|
||||
{ "system-entities": [{ "dev-entry": "/dev/disk-fixture" }] },
|
||||
],
|
||||
}),
|
||||
exitCode: 0,
|
||||
});
|
||||
if (arguments_[0] !== "attach")
|
||||
return Promise.resolve({ stdout: "", exitCode: 0 });
|
||||
return Promise.resolve({
|
||||
@@ -125,3 +134,85 @@ it("owns the canonical mount root and detaches each observed whole image once",
|
||||
["detach", "/dev/disk41"],
|
||||
]);
|
||||
});
|
||||
|
||||
describe("APFS disk image detach", () => {
|
||||
// hdiutil reports the image disk and its synthesized APFS container as two
|
||||
// whole disks; detaching the container ejects the image disk as well.
|
||||
const apfsHost = (stillListed: readonly string[]) => {
|
||||
const calls: string[][] = [];
|
||||
const host: NativeDmgHost = {
|
||||
async run(arguments_) {
|
||||
calls.push([...arguments_]);
|
||||
if (arguments_[0] === "detach" && arguments_[1] === "/dev/disk4")
|
||||
throw new Error("hdiutil: detach failed - No such file or directory");
|
||||
if (arguments_[0] === "info")
|
||||
return {
|
||||
stdout: build({
|
||||
images:
|
||||
stillListed.length === 0
|
||||
? []
|
||||
: [
|
||||
{
|
||||
"system-entities": stillListed.map((device) => ({
|
||||
"dev-entry": device,
|
||||
})),
|
||||
},
|
||||
],
|
||||
}),
|
||||
exitCode: 0,
|
||||
};
|
||||
if (arguments_[0] !== "attach") return { stdout: "", exitCode: 0 };
|
||||
const mountRoot = arguments_[arguments_.indexOf("-mountroot") + 1];
|
||||
if (mountRoot === undefined) throw new Error("missing mount root");
|
||||
const mountPoint = join(mountRoot, "Fixture");
|
||||
await mkdir(mountPoint);
|
||||
return {
|
||||
stdout: build({
|
||||
"system-entities": [
|
||||
{ "dev-entry": "/dev/disk4" },
|
||||
{ "dev-entry": "/dev/disk4s1" },
|
||||
{ "dev-entry": "/dev/disk5s1", "mount-point": mountPoint },
|
||||
{ "dev-entry": "/dev/disk5" },
|
||||
],
|
||||
}),
|
||||
exitCode: 0,
|
||||
};
|
||||
},
|
||||
};
|
||||
return { calls, host };
|
||||
};
|
||||
|
||||
it("accepts an image disk that its container detach already ejected", async () => {
|
||||
const { calls, host } = apfsHost([]);
|
||||
const reader = await NativeDmgArtifactReader.create(
|
||||
"/tmp/image.dmg",
|
||||
undefined,
|
||||
host,
|
||||
);
|
||||
await reader.close();
|
||||
expect(
|
||||
calls.filter((call) => call[0] !== "verify" && call[0] !== "attach"),
|
||||
).toEqual([
|
||||
["detach", "/dev/disk5"],
|
||||
["detach", "/dev/disk4"],
|
||||
["info", "-plist"],
|
||||
]);
|
||||
expect(reader.provenance().map(({ arguments: args }) => args[0])).toEqual([
|
||||
"verify",
|
||||
"attach",
|
||||
"detach",
|
||||
]);
|
||||
});
|
||||
|
||||
it("still fails when the device that rejected detach remains attached", async () => {
|
||||
const { host } = apfsHost(["/dev/disk4", "/dev/disk4s1"]);
|
||||
const reader = await NativeDmgArtifactReader.create(
|
||||
"/tmp/image.dmg",
|
||||
undefined,
|
||||
host,
|
||||
);
|
||||
await expect(reader.close()).rejects.toThrow(
|
||||
"DMG detach or mount-root cleanup failed",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -278,6 +278,29 @@ describe("native macOS provider inspection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("native plist defaults for iOS-style bundles", () => {
|
||||
it("defaults to the Info.plist the bundle program was resolved from", async () => {
|
||||
directory = await createTestTempDirectory("rea-native-flat-");
|
||||
const app = join(directory, "Flat.app");
|
||||
const executable = join(app, "Flat");
|
||||
await mkdir(app, { recursive: true });
|
||||
await writeFile(executable, "fixture");
|
||||
await writeFile(join(app, "Info.plist"), "fixture");
|
||||
const client = new NativeMacOSProvider(
|
||||
new FixtureRunner(),
|
||||
"darwin",
|
||||
).createClient({
|
||||
...machoTarget(executable, app),
|
||||
bundleInfoPlist: join(app, "Info.plist"),
|
||||
});
|
||||
|
||||
const plist = await client.execute("inspect_plist", {});
|
||||
expect(plist.ok && plist.value.result).toMatchObject({
|
||||
source_path: join(app, "Info.plist"),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/** Emit entitlements whose dictionary also holds a legal `__proto__` key. */
|
||||
class PrototypeEntitlementsRunner extends FixtureRunner {
|
||||
override async run(tool: string, arguments_: readonly string[]) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
import {
|
||||
TextReader,
|
||||
@@ -16,9 +16,9 @@ import {
|
||||
requireSuccessfulProjection,
|
||||
} from "../../support/applicationSessionFixture.js";
|
||||
|
||||
import { projectAppleApplicationEvidence } from "../../../src/application/AppleApplicationService.js";
|
||||
import { projectAppleApplicationEvidence } from "../../../src/application/apple/AppleApplicationService.js";
|
||||
import { runProviderAnalysis } from "../../../src/application/DirectAnalysis.js";
|
||||
import { appleApplicationProjectionResultSchema } from "../../../src/domain/appleApplication.js";
|
||||
import { appleApplicationProjectionResultSchema } from "../../../src/domain/apple/appleApplication.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
|
||||
// Real ZIP entries cross the former component and bridge-candidate limits.
|
||||
@@ -149,9 +149,33 @@ describe("Apple application projection", () => {
|
||||
expect(JSON.stringify(left)).not.toContain("opaque signing bytes");
|
||||
});
|
||||
|
||||
it("rejects non-IPA Evidence", async () => {
|
||||
it("reports a ZIP without an application bundle instead of guessing one", async () => {
|
||||
const inventory =
|
||||
await createNonApplicationZipInventory("rea-apple-invalid-");
|
||||
await createNonApplicationZipInventory("rea-apple-empty-");
|
||||
const projection = appleApplicationProjectionResultSchema.parse(
|
||||
requireSuccessfulProjection(
|
||||
projectAppleApplicationEvidence({ inventory_evidence: [inventory] }),
|
||||
).normalized_result,
|
||||
);
|
||||
expect(projection).toMatchObject({
|
||||
root_format: "zip",
|
||||
application_roots: [],
|
||||
bundles: [],
|
||||
});
|
||||
expect(projection.limitations).toContain(
|
||||
"No application bundle (Payload/*.app or *.app/Contents) was present in the supplied inventory pages.",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects inventories of non-Apple package formats", async () => {
|
||||
const root = await createTestTempDirectory("rea-apple-invalid-");
|
||||
const path = join(root, "fixture.apk");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("AndroidManifest.xml", new TextReader("<manifest/>"));
|
||||
await writeFile(path, await writer.close());
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
expect(
|
||||
projectAppleApplicationEvidence({ inventory_evidence: [inventory] }),
|
||||
).toMatchObject({
|
||||
@@ -161,6 +185,74 @@ describe("Apple application projection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("macOS application projection", () => {
|
||||
it("projects a macOS .app directory inventory with nested bundle roles", async () => {
|
||||
const root = await createTestTempDirectory("rea-apple-macos-");
|
||||
const app = join(root, "Fixture.app");
|
||||
const machO = Uint8Array.from([0xcf, 0xfa, 0xed, 0xfe, 0x0c, 0, 0, 1]);
|
||||
const files: [string, string | Uint8Array][] = [
|
||||
[
|
||||
"Contents/Info.plist",
|
||||
"<plist><dict><key>CFBundleExecutable</key><string>Fixture</string></dict></plist>",
|
||||
],
|
||||
["Contents/MacOS/Fixture", machO],
|
||||
["Contents/XPCServices/Fetch.xpc/Contents/MacOS/Fetch", machO],
|
||||
["Contents/PlugIns/Share.appex/Contents/MacOS/Share", machO],
|
||||
["Contents/Library/LoginItems/Login.app/Contents/MacOS/Login", machO],
|
||||
["Contents/Library/LaunchServices/com.example.helper", machO],
|
||||
[
|
||||
"Contents/Library/LaunchDaemons/com.example.helper.plist",
|
||||
"<plist><dict/></plist>",
|
||||
],
|
||||
["Contents/Frameworks/Core.framework/Versions/A/Core", machO],
|
||||
];
|
||||
for (const [relative, content] of files) {
|
||||
await mkdir(dirname(join(app, relative)), { recursive: true });
|
||||
await writeFile(join(app, relative), content);
|
||||
}
|
||||
await symlink(
|
||||
"A",
|
||||
join(app, "Contents/Frameworks/Core.framework/Versions/Current"),
|
||||
);
|
||||
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(app, "inventory_artifact", {}),
|
||||
);
|
||||
const result = projectAppleApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
});
|
||||
const projection = appleApplicationProjectionResultSchema.parse(
|
||||
requireSuccessfulProjection(result).normalized_result,
|
||||
);
|
||||
expect(requireSuccessfulProjection(result).subject?.format).toBe(
|
||||
"directory",
|
||||
);
|
||||
expect(projection).toMatchObject({
|
||||
root_format: "directory",
|
||||
platforms: ["macos"],
|
||||
application_roots: ["."],
|
||||
symlinks: ["Contents/Frameworks/Core.framework/Versions/Current"],
|
||||
coverage: { status: "complete-within-inventory" },
|
||||
});
|
||||
expect(projection.bundles.map(({ path, role }) => [path, role])).toEqual([
|
||||
[".", "application"],
|
||||
["Contents/Frameworks/Core.framework", "framework"],
|
||||
["Contents/Library/LoginItems/Login.app", "login-item"],
|
||||
["Contents/PlugIns/Share.appex", "app-extension"],
|
||||
["Contents/XPCServices/Fetch.xpc", "xpc-service"],
|
||||
]);
|
||||
expect(
|
||||
projection.components.privileged_helpers.map(({ path }) => path),
|
||||
).toEqual(["Contents/Library/LaunchServices/com.example.helper"]);
|
||||
expect(projection.components.launchd_plists).toEqual([
|
||||
expect.objectContaining({
|
||||
path: "Contents/Library/LaunchDaemons/com.example.helper.plist",
|
||||
domain: "daemon",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Apple application projection completeness", () => {
|
||||
it("returns every component and bridge hypothesis from fragments of a real ZIP inventory", async () => {
|
||||
const projection = await createCompleteAppleProjection();
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { projectManagedApplicationGraphEvidence } from "../../../src/application/ManagedApplicationGraphService.js";
|
||||
import { managedApplicationGraphReferenceInputSchema } from "../../../src/contracts/managedWorkflowToolContracts.js";
|
||||
import { MANAGED_APPLICATION_GRAPH_EXAMPLE } from "../../../src/contracts/managedWorkflowExamples.js";
|
||||
import { projectManagedApplicationGraphEvidence } from "../../../src/application/managed/ManagedApplicationGraphService.js";
|
||||
import { managedApplicationGraphReferenceInputSchema } from "../../../src/contracts/managed/managedWorkflowToolContracts.js";
|
||||
import { MANAGED_APPLICATION_GRAPH_EXAMPLE } from "../../../src/contracts/managed/managedWorkflowExamples.js";
|
||||
import { traceApplicationFeatureEvidence } from "../../../src/application/javascript/JavaScriptApplicationWorkflowService.js";
|
||||
import { MANAGED_STATIC_PROVIDER } from "../../../src/application/InvestigationProviders.js";
|
||||
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { parseJavaScriptApplicationGraph } from "../../../src/domain/javascript/javascriptApplicationGraph.js";
|
||||
import { managedApplicationGraphResultSchema } from "../../../src/domain/managedApplicationGraph.js";
|
||||
import { managedApplicationGraphResultSchema } from "../../../src/domain/managed/managedApplicationGraph.js";
|
||||
import { inspectManagedArtifactBytes } from "../../../src/dotnet/ManagedArtifactInspector.js";
|
||||
import { inspectManagedMembersBytes } from "../../../src/dotnet/ManagedMemberInspector.js";
|
||||
import { inspectManagedNativeBoundariesBytes } from "../../../src/dotnet/ManagedNativeBoundaryInspector.js";
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
@interface ReaDispatchFixture : NSObject <ReaDispatchProtocol> {
|
||||
int state;
|
||||
}
|
||||
@property(nonatomic, copy) NSString *fixtureName;
|
||||
- (void)performAction:(id)sender;
|
||||
+ (int)fixtureVersion;
|
||||
@end
|
||||
@@ -16,4 +17,11 @@
|
||||
- (void)performAction:(id)sender { state += sender == nil ? 1 : 2; }
|
||||
+ (int)fixtureVersion { return 1; }
|
||||
@end
|
||||
|
||||
@interface NSString (ReaDispatchAdditions)
|
||||
- (NSUInteger)reaFixtureLength;
|
||||
@end
|
||||
@implementation NSString (ReaDispatchAdditions)
|
||||
- (NSUInteger)reaFixtureLength { return self.length; }
|
||||
@end
|
||||
int main(void) { return 0; }
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
let failed: ChildBatch<Int> = captureChildValues(requestedCount: 2) { nil }
|
||||
precondition(failed.values.isEmpty, "AX retrieval failure must return no values")
|
||||
precondition(!failed.complete, "AX retrieval failure must mark traversal incomplete")
|
||||
|
||||
let short = captureChildValues(requestedCount: 3) { [10, 20] }
|
||||
precondition(short.values == [10, 20], "Short retrieval must preserve returned children")
|
||||
precondition(!short.complete, "Short retrieval must mark traversal incomplete")
|
||||
var visited: [Int] = []
|
||||
for (index, value) in short.values.enumerated() {
|
||||
visited.append(index * 10 + value)
|
||||
}
|
||||
precondition(visited == [10, 30], "Traversal must use actual returned indices")
|
||||
|
||||
let complete = captureChildValues(requestedCount: 2) { [10, 20, 30] }
|
||||
precondition(complete.values == [10, 20], "Retrieval must respect the requested node budget")
|
||||
precondition(complete.complete, "A full bounded result must remain complete")
|
||||
|
||||
print("Native UI child retrieval seam passed")
|
||||
@@ -5,7 +5,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { buildManagedPeFixture } from "../../../../scripts/lib/managed-pe-fixture.mjs";
|
||||
import { buildManagedPeFixture } from "../../../../scripts/fixtures/managed/pe.mjs";
|
||||
import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
|
||||
|
||||
const workspaces: string[] = [];
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { verifyManagedNativeBoundariesEvidence } from "../../../../src/application/ManagedNativeVerificationService.js";
|
||||
import { MANAGED_NATIVE_VERIFICATION_EXAMPLE } from "../../../../src/contracts/managedWorkflowExamples.js";
|
||||
import { verifyManagedNativeBoundariesEvidence } from "../../../../src/application/managed/ManagedNativeVerificationService.js";
|
||||
import { MANAGED_NATIVE_VERIFICATION_EXAMPLE } from "../../../../src/contracts/managed/managedWorkflowExamples.js";
|
||||
import { createEvidence } from "../../../../src/domain/evidence.js";
|
||||
import {
|
||||
managedNativeVerificationInputSchema,
|
||||
managedNativeVerificationResultSchema,
|
||||
verifyManagedNativeBoundaries,
|
||||
} from "../../../../src/domain/managedNativeVerification.js";
|
||||
import { managedNativeBoundaryInspectionSchema } from "../../../../src/domain/managedArtifact.js";
|
||||
} from "../../../../src/domain/managed/managedNativeVerification.js";
|
||||
import { managedNativeBoundaryInspectionSchema } from "../../../../src/domain/managed/managedArtifact.js";
|
||||
import { inspectMachoSchema } from "../../../../src/domain/nativeInspection.js";
|
||||
|
||||
const exampleInput = () =>
|
||||
|
||||
@@ -272,3 +272,22 @@ describe("test lane import boundaries", () => {
|
||||
if (!allowed) expect(result.stdout).toContain("no-restricted-imports");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Apple artifact producer ownership", () => {
|
||||
it.each([
|
||||
["../../application/Workflow.js", false],
|
||||
["../../composition/android.js", false],
|
||||
["../../cli.js", false],
|
||||
["../../domain/apple/plistValue.js", true],
|
||||
["../DirectoryArtifactReader.js", true],
|
||||
])("checks the producer dependency %s", (dependency, allowed) => {
|
||||
const violations = inspectModuleBoundaries(
|
||||
"src/artifacts/apple/probe.ts",
|
||||
`import type { Value } from ${JSON.stringify(dependency)};`,
|
||||
process.cwd(),
|
||||
);
|
||||
|
||||
expect(violations.length === 0).toBe(allowed);
|
||||
if (!allowed) expect(violations[0]?.boundary).toBe("artifact-acquisition");
|
||||
});
|
||||
});
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { open, unlink } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
const [modulePath, root] = process.argv.slice(2);
|
||||
if (modulePath === undefined || root === undefined)
|
||||
throw new Error("Directory reader FIFO probe requires module and root paths");
|
||||
|
||||
const { DirectoryArtifactReader } = await import(pathToFileURL(modulePath));
|
||||
const reader = new DirectoryArtifactReader(root);
|
||||
let selected;
|
||||
for await (const entry of reader.entries())
|
||||
if (entry.path === "module.js") selected = entry;
|
||||
if (selected === undefined)
|
||||
throw new Error("Expected inventoried regular file");
|
||||
|
||||
const fifo = join(root, selected.path);
|
||||
await unlink(fifo);
|
||||
execFileSync("mkfifo", [fifo]);
|
||||
|
||||
const opening = reader.open(selected).then(
|
||||
(stream) => {
|
||||
stream.destroy();
|
||||
return "opened";
|
||||
},
|
||||
(cause) =>
|
||||
typeof cause === "object" && cause !== null && "reason" in cause
|
||||
? String(cause.reason)
|
||||
: "failed",
|
||||
);
|
||||
const outcome = await Promise.race([
|
||||
opening,
|
||||
new Promise((resolve) => setTimeout(() => resolve("blocked"), 100)),
|
||||
]);
|
||||
process.stdout.write(`${String(outcome)}\n`);
|
||||
|
||||
if (outcome === "blocked") {
|
||||
const writer = await open(fifo, "w");
|
||||
await writer.close();
|
||||
await opening;
|
||||
}
|
||||
await reader.close();
|
||||
Reference in New Issue
Block a user