Chrome DevTools for coding agents
fix: accept multiple file paths for upload_file in the CLI (#2668)
u9g9ab482a7b1c0
diff --git a/src/bin/chrome-devtools.ts b/src/bin/chrome-devtools.tsindex a55e8f92..8d4d4c04 100644--- a/src/bin/chrome-devtools.ts+++ b/src/bin/chrome-devtools.ts@@ -30,6 +30,7 @@ import {hideBin, yargs, type CallToolResult} from '../third_party/index.js';import {checkForUpdates} from '../utils/check-for-updates.js';import {VERSION} from '../version.js';+import {buildCommand} from '../config/cli-commands.js';import {commands} from '../config/cli-options.js';import {mcpOptions,@@ -212,27 +213,13 @@ y.command(for (const [commandName, commandDef] of Object.entries(commands)) {const args = commandDef.args;- const requiredArgNames = Object.keys(args).filter(- name => args[name].required,- );-- const optionalArgNames = Object.keys(args).filter(- name => !args[name].required,- );-- let commandStr = commandName;- for (const arg of requiredArgNames) {- commandStr += ` <${arg}>`;- }-- for (const arg of optionalArgNames) {- commandStr += ` [--${arg}]`;- }+ const {command, usage} = buildCommand(commandName, args);y.command(- commandStr,+ command,commandDef.description,y => {+ y.usage(usage);y.option('output-format', {choices: ['md', 'json'],default: 'md',diff --git a/src/config/cli-commands.ts b/src/config/cli-commands.tsnew file mode 100644index 00000000..36805b98--- /dev/null+++ b/src/config/cli-commands.ts@@ -0,0 +1,31 @@+/**+ * @license+ * Copyright 2026 Google LLC+ * SPDX-License-Identifier: Apache-2.0+ */++import type {ArgDef} from './cli-options.js';++/**+ * Builds the yargs command string and usage line for a CLI command.+ *+ * Optional args are rendered as `[--flag]` in the usage line only: as part of+ * the command string yargs parses each one as a trailing positional, and a+ * variadic positional has to be the last one.+ */+export function buildCommand(+ commandName: string,+ args: Record<string, ArgDef>,+): {command: string; usage: string} {+ let command = commandName;+ let flags = '';+ for (const [name, arg] of Object.entries(args)) {+ if (arg.required) {+ command += arg.type === 'array' ? ` <${name}..>` : ` <${name}>`;+ } else {+ flags += ` [--${name}]`;+ }+ }++ return {command, usage: `$0 ${command}${flags}`};+}diff --git a/tests/cli.test.ts b/tests/cli.test.tsindex badf6d4c..7a589930 100644--- a/tests/cli.test.ts+++ b/tests/cli.test.ts@@ -10,6 +10,8 @@ import fs from 'node:fs';import os from 'node:os';import path from 'node:path';+import {buildCommand} from '../src/config/cli-commands.js';+import {commands} from '../src/config/cli-options.js';import {DEFAULT_FILESYSTEM_ROOT,mcpOptions,@@ -548,3 +550,54 @@ describe('cli args parsing', () => {assert.strictEqual(args.devtoolsComments, true);});});++describe('cli command strings', () => {+ it('renders a required array arg as a variadic positional', () => {+ const {command} = buildCommand('upload_file', commands['upload_file'].args);+ assert.strictEqual(command, 'upload_file <pageId> <uid> <filePaths..>');+ });++ it('renders required non-array args as plain positionals', () => {+ const {command} = buildCommand('click', commands['click'].args);+ assert.strictEqual(command, 'click <pageId> <uid>');+ });++ it('lists optional args in the usage line, not the command', () => {+ const {command, usage} = buildCommand(+ 'upload_file',+ commands['upload_file'].args,+ );+ assert.ok(!command.includes('--'));+ assert.ok(usage.startsWith(`$0 ${command} `));+ assert.ok(usage.includes('[--includeSnapshot]'));+ });++ it('keeps every generated command parsable by yargs', () => {+ for (const [name, {args}] of Object.entries(commands)) {+ const {command} = buildCommand(name, args);++ // A `[--flag]` token in the command string is parsed as a positional.+ assert.ok(+ !command.includes('--'),+ `${name}: optional args must not be in the command string`,+ );++ // yargs only allows a variadic positional as the last one.+ const variadic = command.indexOf('..>');+ assert.ok(+ variadic === -1 || variadic === command.length - 3,+ `${name}: a variadic positional must be last`,+ );++ // A required array arg the daemon receives as a string fails validation.+ for (const [argName, arg] of Object.entries(args)) {+ if (arg.required && arg.type === 'array') {+ assert.ok(+ command.includes(`<${argName}..>`),+ `${name}: required array arg ${argName} must be variadic`,+ );+ }+ }+ }+ });+});