diff --git a/src/cliOutput.ts b/src/cliOutput.ts index 862de8b5b..0d029337c 100644 --- a/src/cliOutput.ts +++ b/src/cliOutput.ts @@ -36,7 +36,8 @@ export const validateCliOutputArguments = ( let tokenWindow = false; for (let index = 0; index < arguments_.length; index += 1) { const argument = arguments_[index]; - if (argument === "--") break; + // Incur scans builtins across `--` and accepts only the spaced --format form. + // Mirror its effective format so malformed requests still emit complete JSON. if (argument === "--json") { format = "json"; continue; @@ -49,10 +50,6 @@ export const validateCliOutputArguments = ( } continue; } - if (argument?.startsWith("--format=")) { - format = argument.slice("--format=".length); - continue; - } if (argument === "--token-limit" || argument === "--token-offset") { if (arguments_[index + 1] !== undefined) { tokenWindow = true; diff --git a/tests/boundary/cli/cliOutput.test.ts b/tests/boundary/cli/cliOutput.test.ts index 771cd34db..4ca3d913d 100644 --- a/tests/boundary/cli/cliOutput.test.ts +++ b/tests/boundary/cli/cliOutput.test.ts @@ -57,6 +57,25 @@ describe("CLI output argument and sanitization boundary", () => { ).toEqual({ ok: true }); }); + workspaceCliTest( + "preserves complete JSON errors when native builtin flags follow unusual arguments", + async ({ cli }) => { + for (const arguments_ of [ + ["providers", "--", "--json", "--token-limit", "5"], + ["providers", "--json", "--format=toon", "--token-limit", "5"], + ]) { + const result = await cli.run({ arguments: arguments_ }); + expect(result.exitCode).toBe(1); + expect(result.stdout).not.toContain("[truncated:"); + expect(JSON.parse(result.stdout)).toMatchObject({ + ok: false, + error: { code: "UNSUPPORTED_OUTPUT_COMBINATION" }, + }); + } + }, + CLI_INTEGRATION_TIMEOUT_MS, + ); + workspaceCliTest( "fails before emitting a truncated JSON document", async ({ cli }) => {