From 7fb8b0dc3a7522ec11fbef92f52214c23b521d8b Mon Sep 17 00:00:00 2001 From: Sangjin Park Date: Fri, 29 Aug 2025 07:36:31 +0900 Subject: [PATCH] fix: `browser_tabs` select action with index 0 failing due to falsy check (#964) --- src/tools/tabs.ts | 2 +- tests/tabs.spec.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/tools/tabs.ts b/src/tools/tabs.ts index f92177d..7332f9f 100644 --- a/src/tools/tabs.ts +++ b/src/tools/tabs.ts @@ -49,7 +49,7 @@ const browserTabs = defineTool({ return; } case 'select': { - if (!params.index) + if (params.index === undefined) throw new Error('Tab index is required'); await context.selectTab(params.index); response.setIncludeSnapshot(); diff --git a/tests/tabs.spec.ts b/tests/tabs.spec.ts index a194c3b..ddd873d 100644 --- a/tests/tabs.spec.ts +++ b/tests/tabs.spec.ts @@ -103,6 +103,19 @@ test('select tab', async ({ client }) => { - generic [active] [ref=e1]: Body one \`\`\``), }); + + expect(await client.callTool({ + name: 'browser_tabs', + arguments: { + action: 'select', + index: 0, + }, + })).toHaveResponse({ + tabs: `- 0: (current) [] (about:blank) +- 1: [Tab one] (data:text/html,Tab oneBody one) +- 2: [Tab two] (data:text/html,Tab twoBody two)`, + pageState: expect.stringContaining(`- Page URL: about:blank`), + }); }); test('close tab', async ({ client }) => {