fix(cli): reject empty analyze and artifact target paths (#2687)

Squash merge of https://github.com/morluto/rea/pull/2687.

Co-authored-by: LouisChen <3361008+chqcjq@users.noreply.github.com>
Co-authored-by: morluto <morluto@users.noreply.github.com>
This commit is contained in:
LouisChen 2026-10-13 23:48:09 +08:00 committed by GitHub
parent 8b1549a264
commit 2b98fc5f51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 40 additions and 2 deletions

View File

@ -225,7 +225,7 @@ const registerInspectionCommand = (
description:
"Inspect one artifact and return all available observations and next probes",
args: z.object({
path: z.string().describe("Application or package path"),
path: z.string().min(1).describe("Application or package path"),
}),
options: z.object({
integrityPolicy: z

View File

@ -48,7 +48,10 @@ const registerOverviewCommands = (
cli.command(CLI_COMMANDS.analyze, {
description: "Get an overview of an app",
args: z.object({
path: z.string().describe("App, program, or analysis database path"),
path: z
.string()
.min(1)
.describe("App, program, or analysis database path"),
}),
options: overviewOptions.extend({
integrityPolicy: javascriptApplicationOptions.shape.integrityPolicy,

View File

@ -0,0 +1,35 @@
import { expect } from "vitest";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
import { cliTest } from "../support/cli/cliFixture.js";
cliTest.for(["analyze", "inspect-artifact"])(
"%s rejects an explicitly empty target before resolving it against cwd",
async (command, { cli }) => {
const cwd = await createTestTempDirectory("rea-empty-target-");
const result = await cli.run({
arguments: [command, "", "--json"],
cwd,
});
expect(result.exitCode).toBe(1);
expect(result.json).toMatchObject({ code: "VALIDATION_ERROR" });
expect(result.stdout).toContain("path");
expect(result.stdout).not.toContain("directory_requires_file");
},
);
cliTest(
"inspect-artifact still admits an explicitly selected current directory",
async ({ cli }) => {
const cwd = await createTestTempDirectory("rea-explicit-target-");
const result = await cli.run({
arguments: ["inspect-artifact", ".", "--json"],
cwd,
});
expect(result.exitCode).toBe(1);
expect(result.json).toMatchObject({
code: "target_unavailable",
details: { path: cwd, constraint: "directory_requires_file" },
});
},
);