mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
refactor(process): give POSIX PATH search order one owner (#10891)
* refactor(process): give POSIX PATH search order one owner Program lookup, the packet-tool locator and Jadx's Java lookup each split PATH and resolved empty and relative entries themselves. They now take the candidates from posixPathCandidates in src/process/executableSearch and keep only their own probe and failure reporting. A counted architecture guard keeps new PATH splits from returning; the remaining Windows and Ghidra searches are baselined. * refactor(process): move the colon-split PATH searches onto the search owner REA's launcher-alias lookup and Ghidra's macOS Java lookup split PATH on ":" and skipped relative entries themselves; they now use posixPathCandidates with relativeEntries: "skip", and the guard counts colon splits of PATH as well. * fix(process): produce PATH candidates lazily so an unused entry cannot fail an earlier match * refactor(process): give Windows PATH/PATHEXT search order the executable search owner (#10916) * refactor(process): give Windows PATH/PATHEXT search order the executable search owner * fix(process): keep later PATH entries searchable after a stray quote or a removed working directory * fix(reverse): refuse a Windows objdump or Rizin command that PATH does not find (#10953) * fix(reverse): refuse an objdump or Rizin command Windows PATH does not find instead of launching the bare name * fix(reverse): report a Windows lookup refusal after cancellation and to capability discovery * fix(desktop): search a Windows host's PATH as Windows does when doctor looks up a program programOnPath sent every host through the POSIX PATH search, so on Windows a relative PATH entry reached absoluteCallerPath with platform linux and the Windows working directory, which resolved against itself until the stack overflowed. programOnPath now searches PATH and PATHEXT through windowsPathCandidates on a Windows host, and absoluteCallerPath refuses a non-POSIX working directory with a TypeError instead of recursing.
This commit is contained in:
1 parent
659772952d
commit
422cff00ab
23 files changed
+912
-330
No files matched your search
@@ -7,6 +7,8 @@ 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 { ok } from "../../src/domain/result.js";
|
||||
import { createReverseEngineeringCommandPort } from "../../src/composition/reverseEngineering.js";
|
||||
import { execFileOutput } from "../../src/process/ExecFileOutput.js";
|
||||
|
||||
type ExecFileOutputOptions = NonNullable<Parameters<typeof execFileOutput>[2]>;
|
||||
@@ -25,21 +27,23 @@ it("uses provider profiles supplied through the application port", async () => {
|
||||
const service = new ReverseEngineeringService({
|
||||
environment: { REA_OBJDUMP_COMMAND: "ambient-objdump" },
|
||||
commands: {
|
||||
objdump: () => ({
|
||||
executable: "injected-objdump",
|
||||
arguments: ["--injected", path],
|
||||
identity: {
|
||||
id: "test.objdump",
|
||||
name: "Injected objdump",
|
||||
version: null,
|
||||
},
|
||||
environmentOverrides: { INJECTED_PROFILE: "yes" },
|
||||
}),
|
||||
rizin: () => ({
|
||||
executable: "injected-rizin",
|
||||
arguments: ["--injected", path],
|
||||
identity: { id: "test.rizin", name: "Injected Rizin", version: null },
|
||||
}),
|
||||
objdump: () =>
|
||||
ok({
|
||||
executable: "injected-objdump",
|
||||
arguments: ["--injected", path],
|
||||
identity: {
|
||||
id: "test.objdump",
|
||||
name: "Injected objdump",
|
||||
version: null,
|
||||
},
|
||||
environmentOverrides: { INJECTED_PROFILE: "yes" },
|
||||
}),
|
||||
rizin: () =>
|
||||
ok({
|
||||
executable: "injected-rizin",
|
||||
arguments: ["--injected", path],
|
||||
identity: { id: "test.rizin", name: "Injected Rizin", version: null },
|
||||
}),
|
||||
},
|
||||
run,
|
||||
});
|
||||
@@ -77,21 +81,23 @@ it("does not reintroduce ambient variables absent from the captured provider env
|
||||
const service = new ReverseEngineeringService({
|
||||
environment: { REA_OBJDUMP_COMMAND: "captured-objdump" },
|
||||
commands: {
|
||||
objdump: () => ({
|
||||
executable: "captured-objdump",
|
||||
arguments: [path],
|
||||
identity: {
|
||||
id: "test.objdump",
|
||||
name: "Captured objdump",
|
||||
version: null,
|
||||
},
|
||||
environmentOverrides: { PROFILE_VALUE: "explicit" },
|
||||
}),
|
||||
rizin: () => ({
|
||||
executable: "captured-rizin",
|
||||
arguments: [path],
|
||||
identity: { id: "test.rizin", name: "Captured Rizin", version: null },
|
||||
}),
|
||||
objdump: () =>
|
||||
ok({
|
||||
executable: "captured-objdump",
|
||||
arguments: [path],
|
||||
identity: {
|
||||
id: "test.objdump",
|
||||
name: "Captured objdump",
|
||||
version: null,
|
||||
},
|
||||
environmentOverrides: { PROFILE_VALUE: "explicit" },
|
||||
}),
|
||||
rizin: () =>
|
||||
ok({
|
||||
executable: "captured-rizin",
|
||||
arguments: [path],
|
||||
identity: { id: "test.rizin", name: "Captured Rizin", version: null },
|
||||
}),
|
||||
},
|
||||
run,
|
||||
});
|
||||
@@ -117,20 +123,22 @@ it("projects missing and non-file objdump targets with actionable path reasons",
|
||||
const run = vi.fn(async () => ({ stdout: "", stderr: "" }));
|
||||
const service = new ReverseEngineeringService({
|
||||
commands: {
|
||||
objdump: () => ({
|
||||
executable: "unused-objdump",
|
||||
arguments: [missing],
|
||||
identity: {
|
||||
id: "test.objdump",
|
||||
name: "Test objdump",
|
||||
version: null,
|
||||
},
|
||||
}),
|
||||
rizin: ({ path }) => ({
|
||||
executable: "unused-rizin",
|
||||
arguments: [path],
|
||||
identity: { id: "test.rizin", name: "Test Rizin", version: null },
|
||||
}),
|
||||
objdump: () =>
|
||||
ok({
|
||||
executable: "unused-objdump",
|
||||
arguments: [missing],
|
||||
identity: {
|
||||
id: "test.objdump",
|
||||
name: "Test objdump",
|
||||
version: null,
|
||||
},
|
||||
}),
|
||||
rizin: ({ path }) =>
|
||||
ok({
|
||||
executable: "unused-rizin",
|
||||
arguments: [path],
|
||||
identity: { id: "test.rizin", name: "Test Rizin", version: null },
|
||||
}),
|
||||
},
|
||||
run,
|
||||
});
|
||||
@@ -191,20 +199,22 @@ it("keeps target preflight I/O failures out of invalid-input classification", as
|
||||
const service = new ReverseEngineeringService({
|
||||
stat,
|
||||
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 },
|
||||
}),
|
||||
objdump: () =>
|
||||
ok({
|
||||
executable: "unused-objdump",
|
||||
arguments: [path],
|
||||
identity: {
|
||||
id: "test.objdump",
|
||||
name: "Test objdump",
|
||||
version: null,
|
||||
},
|
||||
}),
|
||||
rizin: () =>
|
||||
ok({
|
||||
executable: "unused-rizin",
|
||||
arguments: [path],
|
||||
identity: { id: "test.rizin", name: "Test Rizin", version: null },
|
||||
}),
|
||||
},
|
||||
run,
|
||||
});
|
||||
@@ -257,20 +267,22 @@ it.each([
|
||||
const service = new ReverseEngineeringService({
|
||||
stat,
|
||||
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 },
|
||||
}),
|
||||
objdump: () =>
|
||||
ok({
|
||||
executable: "unused-objdump",
|
||||
arguments: [path],
|
||||
identity: {
|
||||
id: "test.objdump",
|
||||
name: "Test objdump",
|
||||
version: null,
|
||||
},
|
||||
}),
|
||||
rizin: () =>
|
||||
ok({
|
||||
executable: "unused-rizin",
|
||||
arguments: [path],
|
||||
identity: { id: "test.rizin", name: "Test Rizin", version: null },
|
||||
}),
|
||||
},
|
||||
run,
|
||||
});
|
||||
@@ -308,3 +320,69 @@ it.each([
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{
|
||||
operation: "inspect_with_objdump",
|
||||
environment: { PATH: "", REA_OBJDUMP_COMMAND: "rea-missing-objdump" },
|
||||
run: (service: ReverseEngineeringService, signal?: AbortSignal) =>
|
||||
service.inspectWithObjdump(
|
||||
{ path: "artifact", operation: "file_headers" },
|
||||
signal === undefined ? {} : { signal },
|
||||
),
|
||||
command: "rea-missing-objdump",
|
||||
reason: { lookup_failure: "not_found" },
|
||||
},
|
||||
{
|
||||
operation: "execute_rizin_command",
|
||||
environment: { PATH: "C:\\tools", PATHEXT: ".EXE;C:\\bad" },
|
||||
run: (service: ReverseEngineeringService, signal?: AbortSignal) =>
|
||||
service.executeRizinCommand(
|
||||
{ path: "artifact", command: "i" },
|
||||
signal === undefined ? {} : { signal },
|
||||
),
|
||||
command: "rizin",
|
||||
reason: { lookup_failure: "invalid_pathext", pathext_entry: "C:\\bad" },
|
||||
},
|
||||
])(
|
||||
"refuses $operation on Windows when the bare command is not found on PATH, launching nothing",
|
||||
async ({ operation, environment, run: execute, command, reason }) => {
|
||||
const run = vi.fn(async () => ({ stdout: "", stderr: "" }));
|
||||
const service = new ReverseEngineeringService({
|
||||
environment,
|
||||
commands: createReverseEngineeringCommandPort(environment, "win32"),
|
||||
run,
|
||||
});
|
||||
const result = await execute(service);
|
||||
if (result.ok) throw new Error("Expected a lookup refusal");
|
||||
const projection = projectAnalysisError(result.error);
|
||||
expect(analysisErrorProjectionSchema.safeParse(projection).success).toBe(
|
||||
true,
|
||||
);
|
||||
expect(projection).toMatchObject({
|
||||
code: "capability_unavailable",
|
||||
details: {
|
||||
operation,
|
||||
diagnostics: { boundary: "provider-lookup", command, ...reason },
|
||||
},
|
||||
});
|
||||
// Capability discovery reports the refusal and its repair, as it does
|
||||
// for a launch failure.
|
||||
expect(service.observedLaunchFailures()).toEqual({
|
||||
[operation]: {
|
||||
reason: projection.message,
|
||||
remediation: projection.remediation.action,
|
||||
},
|
||||
});
|
||||
// Cancellation is reported before the lookup refusal.
|
||||
const controller = new AbortController();
|
||||
const abortReason = new Error("caller stopped");
|
||||
controller.abort(abortReason);
|
||||
const cancelled = await execute(service, controller.signal);
|
||||
expect(cancelled).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCancelledError", cause: abortReason },
|
||||
});
|
||||
expect(run).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user