fix(cli): reject extra shell completion arguments (#11767)

This commit is contained in:
RRFZ authored and GitHub committed 2026-11-16 15:04:33 -05:00
1 parent bc8b3c4cfa
commit d511e8baf1
3 files changed
+28 -1

No files matched your search

+5 -1
View File
@@ -175,7 +175,11 @@ export const createCliCompletions = (
const selected = CLI_COMPLETION_SHELLS.find(
(value) => value === command[offset + 1],
);
if (command[offset] !== "completions" || selected === undefined)
if (
command[offset] !== "completions" ||
selected === undefined ||
command.length !== offset + 2
)
return false;
// Help, manifests and server controls precede a completion script.
const values = new Set(global.outputValues.map(({ index }) => index));
+5
View File
@@ -442,6 +442,11 @@ const discoveryAnswer = (
),
1,
);
if (!help && command.length > completions + 2)
return answer(
"Error (PARSE_ERROR): completions expects exactly one shell. Use 'rea completions --help' for usage.",
1,
);
return help || shell === undefined
? answer(
formatCommandHelp(`${cli.name} completions`, {
+18
View File
@@ -4,6 +4,7 @@ import { z } from "zod";
import { expect, it } from "vitest";
import { registerCliCommand } from "../../../src/cli/commandRegistry.js";
import { createCliShell } from "../../../src/cli/cliShell.js";
import { createCliCompletions } from "../../../src/cli/completions.js";
import type { CliInstance } from "../../../src/cli/types.js";
import { parseCliGlobalArguments } from "../../../src/cliBuiltinArguments.js";
@@ -147,6 +148,23 @@ it("shares Bash registration across ordinary and protocol routes while retaining
}
});
it("refuses a second shell without writing a completion script", async () => {
const cli = createCliShell({ selectedEnvironment: {}, registrations: [] });
let output = "";
let exitCode: number | undefined;
await cli.serve(["completions", "bash", "fish"], {
stdout: (text) => {
output += text;
},
exit: (code) => {
exitCode = code;
},
});
expect(exitCode).toBe(1);
expect(output).toContain("completions expects exactly one shell");
expect(output).not.toContain("_incur_complete_rea");
});
workspaceCliTest(
"explains zsh completion initialization in public help",
async ({ processes, workspace }) => {