Files
rea/tests/support/reverseEngineeringService.ts
T
Entrpi 41d291bfc4 fix(rizin): replace the service's lookup and execution together
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.
2026-10-28 21:32:06 +11:00

63 lines
1.9 KiB
TypeScript

import { createReverseEngineeringCommandPort } from "../../src/composition/reverseEngineering.js";
import {
ReverseEngineeringService,
type ReverseEngineeringServiceOptions,
} from "../../src/application/reverse/ReverseEngineeringService.js";
type Processes = NonNullable<ReverseEngineeringServiceOptions["processes"]>;
type Lookup = Processes["lookup"];
/**
* A fake runner with the lookup it should use. Without one it finds nothing,
* so a fake runner never consults the host PATH; a lookup alone would feed
* real execution and is not accepted.
*/
type TestProcesses =
| {
readonly run?: undefined;
readonly runOwned?: undefined;
readonly lookup?: undefined;
}
| {
readonly run: NonNullable<Processes["run"]>;
readonly runOwned?: undefined;
readonly lookup?: Lookup;
}
| {
readonly runOwned: NonNullable<Processes["runOwned"]>;
readonly run?: undefined;
readonly lookup?: Lookup;
};
type TestServiceOptions = Omit<
ReverseEngineeringServiceOptions,
"commands" | "processes"
> &
Partial<Pick<ReverseEngineeringServiceOptions, "commands">> &
TestProcesses;
/** The lookup of a fake process boundary: no host executable is found. */
export const findsNoExecutable: Lookup = async () => ({
status: "missing",
checked: [],
});
/** Compose the production provider profiles while allowing service-boundary fakes. */
export class TestReverseEngineeringService extends ReverseEngineeringService {
constructor(options: TestServiceOptions = {}) {
const { run, runOwned, lookup = findsNoExecutable, ...rest } = options;
const environment = options.environment ?? process.env;
super({
...rest,
environment,
commands:
options.commands ?? createReverseEngineeringCommandPort(environment),
...(run !== undefined
? { processes: { lookup, run } }
: runOwned !== undefined
? { processes: { lookup, runOwned } }
: {}),
});
}
}