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:
+2
-5
@@ -36,7 +36,8 @@ export const validateCliOutputArguments = (
|
|||||||
let tokenWindow = false;
|
let tokenWindow = false;
|
||||||
for (let index = 0; index < arguments_.length; index += 1) {
|
for (let index = 0; index < arguments_.length; index += 1) {
|
||||||
const argument = arguments_[index];
|
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") {
|
if (argument === "--json") {
|
||||||
format = "json";
|
format = "json";
|
||||||
continue;
|
continue;
|
||||||
@@ -49,10 +50,6 @@ export const validateCliOutputArguments = (
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (argument?.startsWith("--format=")) {
|
|
||||||
format = argument.slice("--format=".length);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (argument === "--token-limit" || argument === "--token-offset") {
|
if (argument === "--token-limit" || argument === "--token-offset") {
|
||||||
if (arguments_[index + 1] !== undefined) {
|
if (arguments_[index + 1] !== undefined) {
|
||||||
tokenWindow = true;
|
tokenWindow = true;
|
||||||
|
|||||||
@@ -57,6 +57,25 @@ describe("CLI output argument and sanitization boundary", () => {
|
|||||||
).toEqual({ ok: true });
|
).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(
|
workspaceCliTest(
|
||||||
"fails before emitting a truncated JSON document",
|
"fails before emitting a truncated JSON document",
|
||||||
async ({ cli }) => {
|
async ({ cli }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user