From d511e8baf1a6729b033318e449b2156357b143b6 Mon Sep 17 00:00:00 2001 From: RRFZ <247457381+Plastic-time@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:04:33 -0500 Subject: [PATCH] fix(cli): reject extra shell completion arguments (#11767) --- src/cli/completions.ts | 6 +++++- src/cli/discovery.ts | 5 +++++ tests/boundary/cli/completions.test.ts | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/cli/completions.ts b/src/cli/completions.ts index c53dcda282..e49e6ae727 100644 --- a/src/cli/completions.ts +++ b/src/cli/completions.ts @@ -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)); diff --git a/src/cli/discovery.ts b/src/cli/discovery.ts index 3c9c4fadc6..20e04c1eb8 100644 --- a/src/cli/discovery.ts +++ b/src/cli/discovery.ts @@ -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`, { diff --git a/tests/boundary/cli/completions.test.ts b/tests/boundary/cli/completions.test.ts index 8a58bd1814..118be77b03 100644 --- a/tests/boundary/cli/completions.test.ts +++ b/tests/boundary/cli/completions.test.ts @@ -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 }) => {