fix(cli): align structured output guard with native flags (#777)

Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-07 10:51:21 +08:00
committed by GitHub
parent 5a0e0ba3b8
commit e9fac56232
2 changed files with 21 additions and 5 deletions
+2 -5
View File
@@ -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;
+19
View File
@@ -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 }) => {