From 4d038b69fb59b0ae9234abd22ec13c35fea93dd9 Mon Sep 17 00:00:00 2001 From: youdie006 Date: Fri, 30 Oct 2026 17:15:41 +0900 Subject: [PATCH] fix: refuse a blank --tool instead of sending without a tool `--tool " "` (an empty script variable, say) was accepted, and the prompt went out with no tool and no warning (measured 2026-10-29). MCP pro_consult passes its tools as --tool, so a blank entry there did the same. A tool is opened by its label, so a value of only spaces names none; the send now stops before the browser with "--tool is blank". Verified: tsc, build, npm test (1844 passed, 3 skipped). The new CLI and MCP tests fail without the change. The built CLI refuses `--tool " "` with exit 1 and never takes the browser send lock. Claude-Session: https://claude.ai/code/session_01EMqNwnnhHXznd2P2PDsaDV --- CHANGELOG.md | 5 +++++ src/cli-pro.ts | 5 +++++ tests/cli-pro-browser-send.test.ts | 18 ++++++++++++++++++ tests/mcp-consult.test.ts | 6 ++++++ 4 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 782a099c..8dd7ee89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed +- `--tool " "` (a tool name of only spaces, such as an empty script variable) was accepted, and the prompt went out with no tool and no warning. Measured 2026-10-29. MCP `pro_consult` with a blank entry in `tools` did the same. Both now stop before the browser with "--tool is blank". + ## 0.40.48 ### Fixed diff --git a/src/cli-pro.ts b/src/cli-pro.ts index 3fea6ab9..a56f9f66 100644 --- a/src/cli-pro.ts +++ b/src/cli-pro.ts @@ -1371,6 +1371,11 @@ export async function runAskProCommand( // --tool turns on a composer tool (deep-research, web-search, // create-image, or any label the menu shows) for this send. const tools = readRepeatedFlag(parsedAskPro.optionArgs, "--tool"); + // A tool is opened by its label, so a value that is only spaces names none: + // the prompt went out with no tool and nothing said so. + if (tools.some((tool) => !tool.trim())) { + throw new Error("--tool is blank; name a composer tool (web-search, create-image), or leave the option out."); + } if (tools.length > 0 && !hasSendMode) { throw new Error("--tool only applies when sending (`prodex pro browser ask`); the dry-run preview cannot open ChatGPT's tools menu."); } diff --git a/tests/cli-pro-browser-send.test.ts b/tests/cli-pro-browser-send.test.ts index 8adeff61..f7b14fec 100644 --- a/tests/cli-pro-browser-send.test.ts +++ b/tests/cli-pro-browser-send.test.ts @@ -3573,3 +3573,21 @@ describe("blank project names", () => { await expect(runCli(["setup", "--project", " "], io(cwd))).rejects.toThrow(/--project .*blank/); }); }); + +describe("blank composer tools", () => { + // Measured 2026-10-29: `--tool " "` (a script's empty variable, say) was + // accepted and the prompt went out with no tool at all, so a send that asked + // for a tool got none without a word. MCP pro_consult passes its tools here. + const io = (cwd: string) => ({ cwd, stdout: () => {}, stderr: () => {} }); + beforeEach(() => { + sendChatGptPromptMock.mockClear(); + }); + + it.each([" ", "\t"])("refuses --tool %j before touching the browser", async (value) => { + const cwd = await mkdtemp(path.join(tmpdir(), "prodex-pro-send-")); + await expect(runCli(["pro", "browser", "ask", "--send", "--tool", "web-search", "--tool", value, "Review this"], io(cwd))).rejects.toThrow( + /--tool .*blank/ + ); + expect(sendChatGptPromptMock).not.toHaveBeenCalled(); + }); +}); diff --git a/tests/mcp-consult.test.ts b/tests/mcp-consult.test.ts index 7d9f509d..b14dbe93 100644 --- a/tests/mcp-consult.test.ts +++ b/tests/mcp-consult.test.ts @@ -271,6 +271,12 @@ describe("pro_consult MCP tool registration", () => { }); describe("performBrowserConsultForMcp", () => { + it("refuses a blank tool before sending", async () => { + const cwd = await mkdtemp(path.join(tmpdir(), "prodex-mcp-consult-")); + await expect(performBrowserConsultForMcp(cwd, { prompt: "Question", tools: [" "] })).rejects.toThrow(/--tool .*blank/); + expect(sendChatGptPromptMock).not.toHaveBeenCalled(); + }); + it("threads selection options into the send and returns structured fields", async () => { const cwd = await mkdtemp(path.join(tmpdir(), "prodex-mcp-consult-")); sendChatGptPromptMock.mockResolvedValueOnce({