fix(process): preserve invalid runtime path selections as input errors
Classify unresolvable and unusable executable or working-directory selections before launch, retaining field paths, attempted candidates and OS diagnostics. Preserve tagged analysis errors through capture lifecycle handling. Replace duplicate missing-path source assertions with public CLI/MCP regression coverage and retain distinct permission, file-kind and PATH checks.
This commit is contained in:
1 parent
b123b2e51c
commit
cecc6ecbff
4 files changed
+220
-44
No files matched your search
@@ -19,6 +19,25 @@ const electron = {
|
||||
executable_path: "/tmp/Electron",
|
||||
application_path: "/tmp/main.js",
|
||||
};
|
||||
|
||||
const runCliExpectingInputError = async (
|
||||
scenarioPath: string,
|
||||
): Promise<unknown> => {
|
||||
const failure = await execute(process.execPath, [
|
||||
cli,
|
||||
"capture-process",
|
||||
scenarioPath,
|
||||
"--json",
|
||||
]).then(
|
||||
() => undefined,
|
||||
(cause: unknown) => cause,
|
||||
);
|
||||
expect(failure).toMatchObject({ code: 1 });
|
||||
if (!(failure instanceof Error) || !("stdout" in failure))
|
||||
throw new Error("Expected the CLI to report an input error on stdout");
|
||||
return JSON.parse(String(failure.stdout)) as unknown;
|
||||
};
|
||||
|
||||
const pathRequests: readonly [string, Record<string, unknown>][] = [
|
||||
["open_binary", { path: nul }],
|
||||
["open_binary", { path: process.execPath, snapshot_path: nul }],
|
||||
@@ -235,25 +254,80 @@ captureTest(
|
||||
});
|
||||
expect(parseMcpToolError(failed)).toMatchObject({
|
||||
error: {
|
||||
code: "process_capture_failed",
|
||||
message: expect.stringContaining(missing),
|
||||
details: { execution_failure: expect.stringContaining(missing) },
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
operation: "capture_process_scenario",
|
||||
issues: [
|
||||
{
|
||||
path: ["executable"],
|
||||
message: expect.stringContaining(`${missing} (ENOENT)`),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
await writeFile(
|
||||
join(root, "scenario.json"),
|
||||
JSON.stringify({ executable: missing }),
|
||||
);
|
||||
await expect(
|
||||
execute(process.execPath, [
|
||||
cli,
|
||||
"capture-process",
|
||||
join(root, "scenario.json"),
|
||||
"--json",
|
||||
]),
|
||||
).rejects.toMatchObject({
|
||||
code: 1,
|
||||
stdout: expect.stringContaining(missing),
|
||||
const executableCliFailure = await runCliExpectingInputError(
|
||||
join(root, "scenario.json"),
|
||||
);
|
||||
expect(executableCliFailure).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
operation: "capture_process_scenario",
|
||||
issues: [
|
||||
{
|
||||
path: ["executable"],
|
||||
message: expect.stringContaining(`${missing} (ENOENT)`),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const missingWorkingDirectory = join(root, "missing-working-directory");
|
||||
const cwdFailure = await call("capture_process_scenario", {
|
||||
executable: process.execPath,
|
||||
working_directory: missingWorkingDirectory,
|
||||
});
|
||||
expect(parseMcpToolError(cwdFailure)).toMatchObject({
|
||||
error: {
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
operation: "capture_process_scenario",
|
||||
issues: [
|
||||
{
|
||||
path: ["working_directory"],
|
||||
message: expect.stringContaining(
|
||||
`${missingWorkingDirectory} (ENOENT)`,
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
const cwdScenario = join(root, "missing-working-directory.json");
|
||||
await writeFile(
|
||||
cwdScenario,
|
||||
JSON.stringify({
|
||||
executable: process.execPath,
|
||||
working_directory: missingWorkingDirectory,
|
||||
}),
|
||||
);
|
||||
expect(await runCliExpectingInputError(cwdScenario)).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
operation: "capture_process_scenario",
|
||||
issues: [
|
||||
{
|
||||
path: ["working_directory"],
|
||||
message: expect.stringContaining(
|
||||
`${missingWorkingDirectory} (ENOENT)`,
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
},
|
||||
60_000,
|
||||
|
||||
Reference in new issue
Block a user