fix(cli): preserve spaced output flag values (#4823)

* fix(cli): preserve spaced output flag values

* docs(readme): fix French heading spacing

* fix(ci): retain portable build cache until snapshot upload

* test(browser): assert composed Electron cleanup failures

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
ShuaixinHuang
2026-10-18 04:02:45 +08:00
committed by GitHub
parent fd6da70920
commit 9e372c6bc9
2 changed files with 50 additions and 7 deletions
+17 -7
View File
@@ -18,15 +18,25 @@ const VALUED_OUTPUT_FLAGS = new Set([
*/
export const normalizeCliOutputArguments = (
arguments_: readonly string[],
): string[] =>
arguments_.flatMap((argument) => {
): string[] => {
const normalized: string[] = [];
for (let index = 0; index < arguments_.length; index += 1) {
const argument = arguments_[index]!;
if (VALUED_OUTPUT_FLAGS.has(argument) && arguments_[index + 1]) {
// Incur consumes a nonempty spaced value before looking for more flags.
// Its contents belong to that option, even when they look like a flag.
normalized.push(argument, arguments_[index + 1]!);
index += 1;
continue;
}
const separator = argument.indexOf("=");
if (separator < 0) return [argument];
const flag = argument.slice(0, separator);
return VALUED_OUTPUT_FLAGS.has(flag)
? [flag, argument.slice(separator + 1)]
: [argument];
});
if (separator >= 0 && VALUED_OUTPUT_FLAGS.has(flag))
normalized.push(flag, argument.slice(separator + 1));
else normalized.push(argument);
}
return normalized;
};
export type CliOutputArgumentValidation =
| { readonly ok: true }
+33
View File
@@ -60,6 +60,39 @@ describe("CLI output argument boundary", () => {
});
describe("CLI output flag value forms", () => {
it.each(["--filter-output", "--format", "--token-limit", "--token-offset"])(
"preserves a flag-shaped spaced value owned by %s",
(flag) => {
expect(
normalizeCliOutputArguments([
flag,
"--format=json",
"providers",
"--json",
]),
).toEqual([flag, "--format=json", "providers", "--json"]);
},
);
workspaceCliTest(
"keeps a flag-shaped filter value equivalent in spaced and equals forms",
async ({ cli }) => {
for (const filter of [
["--filter-output", "--format=json"],
["--filter-output=--format=json"],
]) {
const result = await cli.run({
arguments: [...filter, "providers", "--json"],
timeoutMs: 10_000,
});
expect(result.exitCode).toBe(0);
expect(JSON.parse(result.stdout)).toEqual({});
expect(result.stderr).toBe("");
}
},
CLI_INTEGRATION_TIMEOUT_MS,
);
it("splits only the equals forms of valued output flags", () => {
expect(
normalizeCliOutputArguments([