mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +00:00
fix(cli): refuse csv and tsv formats on --llms, --llms-full, and --schema (#11778)
* fix(cli): refuse csv and tsv formats on --llms, --llms-full, and --schema * fix(cli): validate discovery row-format refusals at the shared output boundary
This commit is contained in:
1 parent
e44f0077c9
commit
ab904c793c
3 files changed
+79
-3
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
CLI_OUTPUT_FORMATS,
|
||||
readCliOutputArguments,
|
||||
renderCliDocument,
|
||||
renderCliOutputArgumentError,
|
||||
type CliOutputFormat,
|
||||
} from "../cliOutput.js";
|
||||
import { formatCliOutput } from "./cliOutputFormatter.js";
|
||||
@@ -227,7 +228,9 @@ const llmsAnswer = (
|
||||
global: CliGlobalArguments,
|
||||
full: boolean,
|
||||
): DiscoveryAnswer => {
|
||||
const { format, formatExplicit } = readCliOutputArguments(global);
|
||||
const { format, formatExplicit, validation } = readCliOutputArguments(global);
|
||||
if (!validation.ok)
|
||||
return renderedAnswer(renderCliOutputArgumentError(validation), 1);
|
||||
const scoped = cliCommands(cli).find(
|
||||
({ name }) => name === global.command[0],
|
||||
);
|
||||
@@ -269,7 +272,9 @@ const schemaAnswer = (
|
||||
});
|
||||
return answer(`Error: ${failure.message}`, 1);
|
||||
}
|
||||
const { format, formatExplicit } = readCliOutputArguments(global);
|
||||
const { format, formatExplicit, validation } = readCliOutputArguments(global);
|
||||
if (!validation.ok)
|
||||
return renderedAnswer(renderCliOutputArgumentError(validation), 1);
|
||||
return documentAnswer(
|
||||
commandSchemaDocument(entry, CLI_CUSTOM_GLOBAL_OPTIONS),
|
||||
formatExplicit ? format : "toon",
|
||||
|
||||
+24
-1
@@ -221,7 +221,7 @@ export const readCliOutputArguments = (
|
||||
};
|
||||
return {
|
||||
...controls,
|
||||
validation: validateCliOutputControls(controls, rootVersion),
|
||||
validation: validateCliOutputControls(controls, rootVersion, global),
|
||||
versionReportFormat:
|
||||
rootVersion &&
|
||||
versionEligible &&
|
||||
@@ -240,6 +240,20 @@ export const readCliOutputArguments = (
|
||||
export const missingCliOutputValueMessage = (flag: string): string =>
|
||||
`${flag} requires a value, as in ${flag} <value> or ${flag}=<value>.`;
|
||||
|
||||
const discoveryRowFormatFlag = (
|
||||
global: CliGlobalArguments,
|
||||
): "--llms" | "--llms-full" | "--schema" | undefined => {
|
||||
const { command, flags } = global;
|
||||
const help = flags.has("--help") || flags.has("-h");
|
||||
if ((flags.has("--update") && !help) || flags.has("--mcp")) return undefined;
|
||||
if (flags.has("--llms-full")) return "--llms-full";
|
||||
if (flags.has("--llms")) return "--llms";
|
||||
if (flags.has("--version") && !help) return undefined;
|
||||
if (command.length === 0 || help) return undefined;
|
||||
if (flags.has("--schema")) return "--schema";
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/** Reject output controls that cannot safely produce a complete result. */
|
||||
const validateCliOutputControls = (
|
||||
{
|
||||
@@ -253,6 +267,7 @@ const validateCliOutputControls = (
|
||||
tokenCount,
|
||||
}: CliOutputControls,
|
||||
rootVersion: boolean,
|
||||
global: CliGlobalArguments,
|
||||
): CliOutputArgumentValidation => {
|
||||
if (invalidValue !== undefined)
|
||||
return {
|
||||
@@ -279,6 +294,14 @@ const validateCliOutputControls = (
|
||||
code: "MISSING_OUTPUT_VALUE",
|
||||
message: missingCliOutputValueMessage(missingValue),
|
||||
};
|
||||
const discoveryFlag = delimited ? discoveryRowFormatFlag(global) : undefined;
|
||||
if (delimited && discoveryFlag !== undefined)
|
||||
return {
|
||||
ok: false,
|
||||
format: "json",
|
||||
code: "UNSUPPORTED_OUTPUT_COMBINATION",
|
||||
message: `${discoveryFlag} returns a complete document and does not support --format ${format}. Use --format json, yaml, md, toon, or jsonl; CSV/TSV output is available only for selected row collections.`,
|
||||
};
|
||||
if (delimited && rootVersion)
|
||||
return {
|
||||
ok: false,
|
||||
|
||||
@@ -188,3 +188,51 @@ cliTest(
|
||||
expect(reply.stdout).toContain("MCP_MODE_REMOVED");
|
||||
},
|
||||
);
|
||||
|
||||
it.for([
|
||||
[["--llms", "--format", "csv"], "--llms", "csv"],
|
||||
[["--llms", "--format", "tsv"], "--llms", "tsv"],
|
||||
[["--llms-full", "--format", "csv"], "--llms-full", "csv"],
|
||||
[["--llms-full", "--format", "tsv"], "--llms-full", "tsv"],
|
||||
[["fixture", "--schema", "--format", "csv"], "--schema", "csv"],
|
||||
[["fixture", "--schema", "--format", "tsv"], "--schema", "tsv"],
|
||||
] as const)(
|
||||
"refuses row-only output formats on discovery manifests and schemas: %j",
|
||||
async ([arguments_, flag, format]) => {
|
||||
const reply = await serveInProcessCli(shell(), arguments_);
|
||||
expect(reply.exitCode).toBe(1);
|
||||
expect(JSON.parse(reply.stdout)).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
code: "UNSUPPORTED_OUTPUT_COMBINATION",
|
||||
message: expect.stringMatching(
|
||||
new RegExp(`${flag}.*--format ${format}`, "u"),
|
||||
),
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"refuses bare CSV/TSV discovery requests through the public CLI without suggesting row flags",
|
||||
async ({ cli }) => {
|
||||
for (const [arguments_, flag, format] of [
|
||||
[["--llms", "--format", "csv"], "--llms", "csv"],
|
||||
[["--llms-full", "--format", "tsv"], "--llms-full", "tsv"],
|
||||
[["doctor", "--schema", "--format", "csv"], "--schema", "csv"],
|
||||
] as const) {
|
||||
const reply = await cli.run({ arguments: arguments_ });
|
||||
expect(reply.exitCode).toBe(1);
|
||||
expect(reply.json).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
code: "UNSUPPORTED_OUTPUT_COMBINATION",
|
||||
message: expect.stringMatching(
|
||||
new RegExp(`${flag}.*--format ${format}`, "u"),
|
||||
),
|
||||
},
|
||||
});
|
||||
expect(reply.stdout).not.toContain("--filter-output");
|
||||
}
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user