Files
reverse-engineering-anything/src/artifacts/nodeSea/NodeSeaHashWork.test.ts
T
4491c84c82 fix(node-sea): bound duplicate blob verification work (#11736)
* fix(node-sea): bound duplicate blob verification work

* test(mcp): observe cleanup failures at their current delivery boundary

* fix(mcp): preserve workflow completion progress through delivery

* test(setup): keep the Windows Kimi profile fixture on a supported profile

The Windows-only case at `clientConfigurationEnvironment.test.ts:226` wrote
`rea_mcp_input_schema_profile: "full"`. That profile was retired: the reader
now refuses it ("REA_MCP_INPUT_SCHEMA_PROFILE accepts only \"compact\" …"),
so `configureClientConfiguration` returned `failed/readback` before writing
and the case failed on every Windows run, including main's own
`Windows capability and package lane`.

The case has no Windows dependency — it passes an explicit `configPath` and
the Kimi write dialect is the same everywhere — so it now runs on every
platform, which is what let the stale value rot unnoticed. The fixture keeps
the lowercase explicit key the case is about, with the supported value.

Verified on `main` `d6bcfc10`: the same fixture driven through
`configureClientConfiguration(..., "win32")` on this host reproduced
`{"status":"failed","reason":"readback"}` with the retired value and now
returns `{"status":"configured"}` with `compact`. The file's 75 cases pass
here (66 run, 9 platform-conditioned skips) and `check:fast` passes.

* test(ci): restore verifier and MCP contract regressions

* test(captures): assert adapter-owned input issue field names

* fix(ghidra): avoid Java probes for missing installations

* test(ghidra): drop duplicate absent-installation coverage

Merging main reapplied the #11732 case beside the copy already on main.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* test(node-sea): assert duplicate-blob refusal without stdout prose

The CLI coverage already checks the truncated code and limit details.

Co-authored-by: morluto <morluto@users.noreply.github.com>

---------

Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
Co-authored-by: g0at <50488370+g1at@users.noreply.github.com>
Co-authored-by: IvenKooLab <276572622@qq.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <morluto@users.noreply.github.com>
2026-11-19 11:25:23 -05:00

97 lines
3.1 KiB
TypeScript

import { open, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it, vi } from "vitest";
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
import { nodeSeaMachO } from "./NodeSea.fixture.js";
import { nodeSeaOverlappingMachO } from "../../../tests/fixtures/nodeSeaOverlapping.js";
import { locateNodeSea } from "./NodeSeaLocation.js";
it("bounds verification of distinct overlapping SEA declarations by carrier bytes", async () => {
const { bytes: image, payloadAt } = nodeSeaOverlappingMachO();
const root = await createTestTempDirectory("rea-sea-hash-work-");
const path = join(root, "carrier");
await writeFile(path, image);
const handle = await open(path, "r");
const read = handle.read.bind(handle);
let hashBytes = 0;
vi.spyOn(handle, "read").mockImplementation((async (
buffer: Buffer,
offset: number,
length: number,
position: number,
) => {
const result = await read(buffer, offset, length, position);
hashBytes += Math.max(
0,
Math.min(position + result.bytesRead, image.length) -
Math.max(position, payloadAt),
);
return result;
}) as typeof handle.read);
try {
let failure: unknown;
try {
await locateNodeSea(handle, image.length);
} catch (cause) {
failure = cause;
}
expect(hashBytes).toBeLessThanOrEqual(image.length);
expect(failure).toMatchObject({ reason: "limit" });
} finally {
await handle.close();
}
});
it.each(["exact aliases", "disjoint copies"] as const)(
"still accepts identical SEA bytes in %s",
async (kind) => {
const blob = Buffer.alloc(16 * 1024);
const image =
kind === "exact aliases"
? nodeSeaOverlappingMachO(true).bytes
: nodeSeaMachO({ blob, extraBlobs: [blob] });
const root = await createTestTempDirectory("rea-sea-hash-control-");
const path = join(root, "carrier");
await writeFile(path, image);
const handle = await open(path, "r");
try {
await expect(locateNodeSea(handle, image.length)).resolves.toMatchObject({
carrier: "mach-o",
blobLength: blob.length,
});
} finally {
await handle.close();
}
},
);
it("rejects unequal blob lengths before hashing either copy", async () => {
const image = nodeSeaMachO({
blob: Buffer.alloc(16 * 1024),
extraBlobs: [Buffer.alloc(16 * 1024 + 1)],
});
const root = await createTestTempDirectory("rea-sea-hash-lengths-");
const path = join(root, "carrier");
await writeFile(path, image);
const handle = await open(path, "r");
const read = handle.read.bind(handle);
let payloadReads = 0;
vi.spyOn(handle, "read").mockImplementation((async (
buffer: Buffer,
offset: number,
length: number,
position: number,
) => {
if (length >= 16 * 1024) payloadReads++;
return read(buffer, offset, length, position);
}) as typeof handle.read);
try {
await expect(locateNodeSea(handle, image.length)).rejects.toMatchObject({
reason: "format",
});
expect(payloadReads).toBe(0);
} finally {
await handle.close();
}
});