mirror of
https://github.com/morluto/rea.git
synced 2026-11-28 15:18:49 +00:00
Tests that injected a fake runner still resolved `rizin` through the host PATH. With Rizin installed, the version probe took the fake runner's first canned result, and three tests in reverseEngineering.test.ts failed. CI has no Rizin, so they passed there. The service now takes one `processes` option: the executable lookup with either a runner or the owned-process primitive. It replaces `run` and `runOwned`, so a fake runner cannot be paired with the host lookup. Omitting it keeps the host lookup and owned execution. The lookup no longer reads the service's `stat` seam. The test service pairs a fake runner with a lookup that finds nothing unless the test passes one; the identity tests pass the real lookup explicitly. A new test puts an executable `rizin` first on PATH with a fake runner and checks that each command gets its canned result, and that the options type rejects a runner without its lookup.
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import { stat, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { expect, it, vi } from "vitest";
|
|
|
|
import { ReverseEngineeringService } from "../../src/application/reverse/ReverseEngineeringService.js";
|
|
import { analysisErrorProjectionSchema } from "../../src/contracts/errorSchemas.js";
|
|
import { projectAnalysisError } from "../../src/domain/analysisErrorProjection.js";
|
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
|
import { findsNoExecutable } from "../support/reverseEngineeringService.js";
|
|
|
|
it.each([
|
|
{ stage: "stat", cause: null },
|
|
{ stage: "stat", cause: undefined },
|
|
{ stage: "command", cause: null },
|
|
{ stage: "command", cause: undefined },
|
|
] as const)(
|
|
"preserves a $cause rejection from $stage without throwing while classifying it",
|
|
async ({ stage, cause }) => {
|
|
const root = await createTestTempDirectory("rea-reverse-unknown-failure-");
|
|
const path = join(root, "input.bin");
|
|
await writeFile(path, new Uint8Array([0x7f, 0x45, 0x4c, 0x46]));
|
|
const run = vi.fn(async () => {
|
|
throw cause;
|
|
});
|
|
const service = new ReverseEngineeringService({
|
|
stat:
|
|
stage === "stat"
|
|
? async () => {
|
|
throw cause;
|
|
}
|
|
: stat,
|
|
processes: { lookup: findsNoExecutable, run },
|
|
commands: {
|
|
objdump: () => ({
|
|
executable: "unused-objdump",
|
|
arguments: [path],
|
|
identity: { id: "test.objdump", name: "Test objdump", version: null },
|
|
}),
|
|
rizin: () => ({
|
|
executable: "unused-rizin",
|
|
arguments: [path],
|
|
identity: { id: "test.rizin", name: "Test Rizin", version: null },
|
|
}),
|
|
},
|
|
});
|
|
|
|
const result = await service.inspectWithObjdump({
|
|
path,
|
|
operation: "symbols",
|
|
});
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) throw new Error("Expected injected boundary rejection");
|
|
expect(result.error.cause).toBe(cause);
|
|
const projected = projectAnalysisError(result.error);
|
|
expect(analysisErrorProjectionSchema.safeParse(projected).success).toBe(
|
|
true,
|
|
);
|
|
expect(projected.code).toBe(
|
|
stage === "stat" ? "execution_failure" : "capability_unavailable",
|
|
);
|
|
if (stage === "stat") expect(run).not.toHaveBeenCalled();
|
|
else expect(run).toHaveBeenCalledOnce();
|
|
await service.close();
|
|
},
|
|
);
|