Files
rea/tests/acceptance/applications/electronInvalidPaths.test.ts
f652709cac fix(cli): keep file URLs out of operator-relative path resolution (#2882)
CLI path normalization resolved every nonblank selected string against
the working directory, so executable_path "file:///opt/electron" became
an invented local path and failed with ENOENT for that location instead
of the field's local-path requirement. Leave `file:` and `scheme://`
references unchanged so the shared schema rejects them as non-local
paths. One-letter prefixes stay paths, so Windows drive paths and
relative names containing a colon resolve as before.

Fixes #2577

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 01:05:14 +08:00

107 lines
3.6 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
cliTest(
"reports every unresolved Electron path through CLI and MCP without launching",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-electron-invalid-paths-");
const application = join(root, "main.js");
await writeFile(application, "module.exports = {};\n");
const missing = {
executable_path: join(root, "missing-electron"),
application_path: join(root, "missing-application"),
application_root: join(root, "missing-root"),
};
const requestPath = join(root, "input.json");
await writeFile(requestPath, JSON.stringify(missing));
const response = await cli.run({
arguments: ["capture-electron-scenario", requestPath, "--format", "json"],
environment: { REA_LOG_LEVEL: "silent" },
});
expect(response.exitCode).toBe(1);
const expectedIssues = Object.entries(missing).map(([field, path]) => ({
path: [field],
reason: "invalid_value",
message: expect.stringContaining(path),
}));
expect(response.json).toMatchObject({
code: "invalid_request",
details: { issues: expectedIssues },
});
expect(response.stdout).toContain("ENOENT");
const { call } = await connectLocalToolsMcp();
for (const [field, path] of Object.entries(missing)) {
const result = await call("capture_electron_scenario", {
executable_path: process.execPath,
application_path: application,
application_root: root,
[field]: path,
});
expect(result.isError).toBe(true);
const content = result.content.find((item) => item.type === "text");
if (content?.type !== "text") throw new Error("Missing error response");
expect(JSON.parse(content.text)).toMatchObject({
error: {
code: "invalid_request",
details: {
issues: [
{
path: [field],
reason: "invalid_value",
message: expect.stringContaining(path),
},
],
},
},
});
expect(content.text).toContain("ENOENT");
}
const session = await call("binary_session", {});
expect(session.isError, JSON.stringify(session)).not.toBe(true);
},
);
cliTest(
"rejects a file URL path field without resolving an invented local path",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-electron-file-url-");
const application = join(root, "main.js");
await writeFile(application, "module.exports = {};\n");
const response = await cli.run({
arguments: [
"capture-electron-scenario",
JSON.stringify({
executable_path: "file:///opt/electron",
application_path: application,
}),
"--format",
"json",
],
environment: { REA_LOG_LEVEL: "silent" },
});
expect(response.exitCode).toBe(1);
expect(response.json).toMatchObject({
code: "invalid_request",
details: {
issues: [
{
path: ["executable_path"],
message: expect.stringContaining(
"must be absolute local filesystem paths",
),
},
],
},
});
expect(response.stdout).not.toContain("ENOENT");
expect(response.stdout).not.toContain("file:/opt/electron");
},
);