From 2b4f70c7fdbfd8f88c5962bc7e4f046d18b1b55d Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 20 Aug 2026 10:18:29 -0700 Subject: [PATCH 1/2] fix(cli): parse negative numbers as arguments Fixes: https://github.com/microsoft/playwright/issues/42321 --- .../src/tools/cli-client/minimist.ts | 3 ++- tests/mcp/cli-parsing.spec.ts | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/playwright-core/src/tools/cli-client/minimist.ts b/packages/playwright-core/src/tools/cli-client/minimist.ts index 28e6f75257b22..ecb1f7c1c94b6 100644 --- a/packages/playwright-core/src/tools/cli-client/minimist.ts +++ b/packages/playwright-core/src/tools/cli-client/minimist.ts @@ -94,7 +94,8 @@ export function minimist(args: string[], opts?: MinimistOptions): MinimistArgs { } else { setArg(key, strings[key] ? '' : true); } - } else if ((/^-[^-]+/).test(arg)) { + } else if ((/^-[A-Za-z]/).test(arg)) { + // Short flags are letters, so '-100' and '-.5' are arguments, not flags. const letters = arg.slice(1, -1).split(''); let broken = false; diff --git a/tests/mcp/cli-parsing.spec.ts b/tests/mcp/cli-parsing.spec.ts index 8b65fbcba86c8..bd711b04bb211 100644 --- a/tests/mcp/cli-parsing.spec.ts +++ b/tests/mcp/cli-parsing.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './cli-fixtures'; +import { test, expect, eventsPage } from './cli-fixtures'; test('unknown option', async ({ cli, server }) => { const { error, exitCode } = await cli('open', '--some-option', 'value', 'about:blank'); @@ -73,6 +73,17 @@ test('wrong argument type', async ({ cli, server }) => { expect(press.exitCode).toBe(0); }); +test('negative number arguments', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42321' } }, async ({ cli, server }) => { + server.setContent('/', eventsPage, 'text/html'); + await cli('open', server.PREFIX); + + expect((await cli('mousewheel', '0', '-100')).exitCode).toBe(0); + await expect.poll(() => cli('snapshot').then(result => result.inlineSnapshot)).toContain('wheel 0 -100'); + + expect((await cli('mousewheel', '-1.5', '-.5')).exitCode).toBe(0); + await expect.poll(() => cli('snapshot').then(result => result.inlineSnapshot)).toContain('wheel -1.5 -0.5'); +}); + test('should preserve leading zeros in string arguments', async ({ cli, server }) => { server.setContent('/', ``, 'text/html'); await cli('open', server.PREFIX); From 3fe7b837322ef5f68449d9171ae5a7ef869b1fed Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 20 Aug 2026 11:27:15 -0700 Subject: [PATCH 2/2] test(cli): make the negative number test browser-independent Webkit quantizes wheel deltas to integers, so asserting on fractional deltas tested the browser rather than the parser. Assert on the argument error instead, and move the mouse into the page before scrolling. --- tests/mcp/cli-parsing.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/mcp/cli-parsing.spec.ts b/tests/mcp/cli-parsing.spec.ts index bd711b04bb211..947da89cb216e 100644 --- a/tests/mcp/cli-parsing.spec.ts +++ b/tests/mcp/cli-parsing.spec.ts @@ -76,12 +76,13 @@ test('wrong argument type', async ({ cli, server }) => { test('negative number arguments', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42321' } }, async ({ cli, server }) => { server.setContent('/', eventsPage, 'text/html'); await cli('open', server.PREFIX); + await cli('mousemove', '50', '50'); expect((await cli('mousewheel', '0', '-100')).exitCode).toBe(0); await expect.poll(() => cli('snapshot').then(result => result.inlineSnapshot)).toContain('wheel 0 -100'); - expect((await cli('mousewheel', '-1.5', '-.5')).exitCode).toBe(0); - await expect.poll(() => cli('snapshot').then(result => result.inlineSnapshot)).toContain('wheel -1.5 -0.5'); + const { error } = await cli('mousewheel', '-.5'); + expect(error).toContain(`error: 'dy' argument: expected number, received 'undefined'`); }); test('should preserve leading zeros in string arguments', async ({ cli, server }) => {