fix(cli): reject an empty JavaScript application path (#5265)

This commit is contained in:
Vishal Tambi authored and GitHub committed 2026-10-22 03:50:52 +08:00
1 parent d8199ab6af
commit 1a945ce9ff
2 files changed
+28 -1

No files matched your search

+3 -1
View File
@@ -297,7 +297,9 @@ const registerJavaScriptApplicationCommand = (
logCliCommand(logger, CLI_COMMANDS.analyzeJavaScriptApplication, () =>
runCliJavaScriptApplicationAnalysis(
{
input_path: absoluteCallerPath(args.path),
// An empty path names no file; leave it for input validation.
input_path:
args.path === "" ? args.path : absoluteCallerPath(args.path),
format: options.artifactFormat,
integrity_policy: options.integrityPolicy,
...(options.maxSemanticNodes === undefined
@@ -140,3 +140,28 @@ cliTest(
).toBe(true);
},
);
// Anchoring must not turn an empty selection into the working directory.
cliTest.for([
{
command: "analyze-javascript-application",
rejection: {
code: "invalid_request",
details: { issues: [expect.objectContaining({ path: ["input_path"] })] },
},
},
{ command: "analyze", rejection: { code: "VALIDATION_ERROR" } },
])(
"$command rejects an empty path instead of analyzing the working directory",
async ({ command, rejection }, { cli }) => {
const root = await createTestTempDirectory("rea-js-empty-path-");
await writeFile(join(root, "main.js"), "export const value = 7;\n");
const response = await cli.run({
arguments: [command, "", "--json"],
cwd: root,
environment: { REA_LOG_LEVEL: "silent" },
});
expect(response.exitCode, response.stderr).toBe(1);
expect(response.json).toMatchObject(rejection);
},
);