fix: bind identity and coverage to the producing rule (#1513)

* fix: bind identity and coverage to the producing rule

Logical paths, container families, examined bytes, path-segment conventions, destination collisions, file-id leases, Mach-O CPU selection, and firmware cleanup now follow the observation that owns each rule.

* fix: fail unmatched Mach-O slices and keep firmware roots independent

A fat target whose architecture lipo did not list now stops before slice tools run. Chained fixups still count unread LC_DYLD_INFO rebase bytes, and a firmware cleanup failure no longer blocks the next workspace.

* test: cover path identity and runtime families at the projection boundary

NFC joins and segment conventions are now asserted by the path resolver, the Apple projection, and a real APK inventory instead of helper unit tests.

* test: expect unread dyld rebase bytes in the Apple dispatch fixture

The legacy LC_DYLD_INFO fixture keeps a rebase range this reader does not decode, so the public CLI and MCP check now requires that partial coverage beside the bind opcodes.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morluto
2026-10-10 17:14:47 +08:00
committed by GitHub
co-authored by Cursor Agent
parent 7a56fe6260
commit b4db35f092
48 changed files with 1251 additions and 266 deletions
@@ -33,6 +33,80 @@ describe("ZIP signature detection", () => {
},
);
it("uses ZIP magic before the filename suffix", async () => {
const root = await createTestTempDirectory("rea-zip-suffix-");
const apk = join(root, "renamed.apk");
const program = join(root, "program.apk");
await writeFile(apk, Buffer.from([0x50, 0x4b, 0x03, 0x04]));
await writeFile(program, Buffer.from([0x7f, 0x45, 0x4c, 0x46]));
expect(
(await classifyAndHashRoot(apk, false, await lstat(apk))).format,
).toBe("apk");
expect(
(await classifyAndHashRoot(program, false, await lstat(program))).format,
).toBe("elf");
});
it("requires container magic for asar, pkg, and dmg suffixes", async () => {
const root = await createTestTempDirectory("rea-container-magic-");
const asar = join(root, "app.asar");
const textAsar = join(root, "notes.asar");
const pkg = join(root, "install.pkg");
const textPkg = join(root, "notes.pkg");
const dmg = join(root, "image.dmg");
const textDmg = join(root, "notes.dmg");
const headerSize = 20;
await writeFile(
asar,
Buffer.from([
4,
0,
0,
0,
headerSize,
0,
0,
0,
headerSize - 4,
0,
0,
0,
2,
0,
0,
0,
0x7b,
0x7d,
]),
);
await writeFile(textAsar, Buffer.from("not an asar"));
await writeFile(pkg, Buffer.from("xar!"));
await writeFile(textPkg, Buffer.from("not a pkg"));
const image = Buffer.alloc(512);
image.write("koly", 0, "ascii");
await writeFile(dmg, image);
await writeFile(textDmg, Buffer.from("not a dmg"));
expect(
(await classifyAndHashRoot(asar, false, await lstat(asar))).format,
).toBe("asar");
expect(
(await classifyAndHashRoot(textAsar, false, await lstat(textAsar)))
.format,
).toBe("file");
expect(
(await classifyAndHashRoot(pkg, false, await lstat(pkg))).format,
).toBe("pkg");
expect(
(await classifyAndHashRoot(textPkg, false, await lstat(textPkg))).format,
).toBe("file");
expect(
(await classifyAndHashRoot(dmg, false, await lstat(dmg))).format,
).toBe("dmg");
expect(
(await classifyAndHashRoot(textDmg, false, await lstat(textDmg))).format,
).toBe("file");
});
it.each([[], [0x50], [0x50, 0x4b], [0x50, 0x4b, 0x03]])(
"rejects an incomplete signature %j",
async (...bytes) => {
@@ -324,7 +324,7 @@ it("cancels a waiting request promptly while keeping later launches behind the a
await assertFirmwareCleanup(fixture.launches);
});
it("retains an uncertain workspace and blocks new launches after cleanup failure", async () => {
it("retains an uncertain workspace and lets the next operation create a new root", async () => {
const fixture = await firmwareFixture("cleanup-failure");
const first = await fixture.service.execute("inspect_firmware_regions", {
path: fixture.path,
@@ -335,12 +335,18 @@ it("retains an uncertain workspace and blocks new launches after cleanup failure
});
const workspace = fixture.launches[0]?.cwd;
expect(workspace).toBeDefined();
if (workspace !== undefined) await access(workspace);
if (workspace === undefined) return;
await access(workspace);
const next = await fixture.service.execute("inspect_firmware_regions", {
path: fixture.path,
});
expect(next).toMatchObject({ ok: false, error: { cleanupIncomplete: true } });
expect(fixture.launches).toHaveLength(1);
expect(fixture.launches).toHaveLength(2);
const nextWorkspace = fixture.launches[1]?.cwd;
expect(nextWorkspace).toBeDefined();
expect(nextWorkspace).not.toBe(workspace);
await access(workspace);
if (nextWorkspace !== undefined) await access(nextWorkspace);
});
it("accepts another build on the verified release line and reports it", async () => {
+24 -8
View File
@@ -37,12 +37,14 @@ describe("Android application projection", () => {
Uint8Array.from([0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x35, 0]),
),
);
await writer.add(
"lib/arm64-v8a/libreactnativejni.so",
const elf = () =>
new Uint8ArrayReader(
Uint8Array.from([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1, 0]),
),
);
);
await writer.add("lib/arm64-v8a/libreactnativejni.so", elf());
await writer.add("lib/arm64-v8a/libflutter.so", elf());
await writer.add("lib/arm64-v8a/libunity.so", elf());
await writer.add("lib/arm64-v8a/libcommunity.so", elf());
await writer.add("assets/index.js", new TextReader("bridge();"));
await writer.add("META-INF/FIXTURE.RSA", new TextReader("opaque signing"));
await writeFile(path, await writer.close());
@@ -72,20 +74,34 @@ describe("Android application projection", () => {
});
expect(left.components.manifests).toHaveLength(1);
expect(left.components.dex).toHaveLength(1);
expect(left.components.native_libraries).toHaveLength(1);
expect(left.components.native_libraries).toHaveLength(4);
expect(left.components.javascript).toHaveLength(1);
expect(left.components.signing).toHaveLength(1);
expect(left.runtime_families).toEqual(
expect.arrayContaining([
"dalvik-art",
"flutter",
"javascript",
"native",
"react-native",
"unity",
]),
);
expect(left.bridge_candidates).toEqual([
expect.objectContaining({ basis: "react-native-convention" }),
]);
expect(left.runtime_families).not.toContain("community");
expect(left.bridge_candidates).toEqual(
expect.arrayContaining([
expect.objectContaining({ basis: "react-native-convention" }),
expect.objectContaining({ basis: "flutter-convention" }),
expect.objectContaining({ basis: "unity-convention" }),
]),
);
const community = left.bridge_candidates.filter(({ native_path }) =>
native_path.endsWith("libcommunity.so"),
);
expect(community.length).toBeGreaterThan(0);
expect(
community.every(({ basis }) => basis === "jni-library-convention"),
).toBe(true);
expect(left.limitations).toEqual(
expect.arrayContaining([
"A bridge basis is inferred from the native path and is repeated for every managed component.",