From 8261b01e5e6ba52ec7f00767e03ba62e97b86ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 21:20:55 +0100 Subject: [PATCH 1/2] perf(ci): keep the dispatch reader's node types off the range gate The range gate classifies every function parameter's declared type before it analyzes the function, and this file took `oxc-parser`'s whole `Expression` union as its parameter type. That union is every AST kind, each a record of further such unions, so one file cost more analysis time than the rest of the repository combined: `pnpm exec fr` went 146s to 21s on the same machine when the reader declares the node fields it reads. The reader's verdict is unchanged, and the test now pins the literal set it collects: `src/cli.ts` yields 18 command literals, and a reader that stops collecting fails the deep-equal instead of passing over an empty loop. `scripts/lib/shipped-imports.ts` already records the same constraint. Co-Authored-By: Claude Opus 5.5 --- src/cli-command-dispatch.test.ts | 73 +++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/src/cli-command-dispatch.test.ts b/src/cli-command-dispatch.test.ts index d7209f1f14..c969225ad2 100644 --- a/src/cli-command-dispatch.test.ts +++ b/src/cli-command-dispatch.test.ts @@ -3,12 +3,32 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; import { fileURLToPath } from 'node:url'; import { parseSync } from 'oxc-parser'; -import type { BinaryExpression, Expression, PrivateIdentifier } from 'oxc-parser'; import { isKnownCliCommandName } from '@agent-device/command-registry/catalog'; test('cli.ts command dispatch checks are recognized by parser-level unknown-command handling', () => { const commands = collectCliDispatchCommandLiterals(); - assert.notEqual(commands.size, 0); + // The exact set, so a reader that collects nothing, or stops collecting, fails here instead + // of passing over an empty loop. + assert.deepEqual([...commands].sort(), [ + 'auth', + 'batch', + 'cdp', + 'close', + 'connect', + 'connection', + 'daemon', + 'device', + 'disconnect', + 'help', + 'mcp', + 'open', + 'plugins', + 'proxy', + 'react-devtools', + 'runtime', + 'test', + 'web', + ]); for (const command of commands) { assert.equal( isKnownCliCommandName(command), @@ -32,7 +52,24 @@ function collectCliDispatchCommandLiterals(): Set { return commands; } -type AstNode = { type: string }; +/** + * The node fields this reader walks, declared locally instead of taken from `oxc-parser`. The + * range gate classifies every parameter type it meets, and `oxc-parser`'s `Expression` union is + * every AST kind, each a record of further such unions. No function here takes that union. + */ +type AstNode = { + type: string; + name?: string; + operator?: string; + computed?: boolean; + value?: unknown; + left?: AstNode; + right?: AstNode; + expression?: AstNode; + expressions?: AstNode[]; + property?: AstNode; + quasis?: { value: { cooked?: string } }[]; +}; function isAstNode(value: unknown): value is AstNode { return ( @@ -58,49 +95,45 @@ function visitAstNodes(root: AstNode, visit: (node: AstNode) => void): void { function readBinaryComparisonCommandLiteral(node: AstNode): string | null { if (node.type !== 'BinaryExpression') return null; - const binary = node as unknown as BinaryExpression; - if (binary.operator !== '===' && binary.operator !== '!==') return null; + if (node.operator !== '===' && node.operator !== '!==') return null; + if (node.left == null || node.right == null) return null; return ( - readCommandComparisonLiteral(binary.left, binary.right) ?? - readCommandComparisonLiteral(binary.right, binary.left) + readCommandComparisonLiteral(node.left, node.right) ?? + readCommandComparisonLiteral(node.right, node.left) ); } -function readCommandComparisonLiteral( - commandSide: Expression | PrivateIdentifier, - literalSide: Expression | PrivateIdentifier, -): string | null { +function readCommandComparisonLiteral(commandSide: AstNode, literalSide: AstNode): string | null { if (!isCommandExpression(commandSide)) return null; return readStringLiteralText(unwrapParenthesizedExpression(literalSide)); } -function isCommandExpression(expression: Expression | PrivateIdentifier): boolean { +function isCommandExpression(expression: AstNode): boolean { const unwrapped = unwrapParenthesizedExpression(expression); if (unwrapped.type === 'Identifier') return unwrapped.name === 'command'; return ( unwrapped.type === 'MemberExpression' && !unwrapped.computed && - unwrapped.property.type === 'Identifier' && + unwrapped.property?.type === 'Identifier' && unwrapped.property.name === 'command' ); } // Mirrors ts.isStringLiteralLike: string literals plus substitution-free templates. -function readStringLiteralText(expression: Expression | PrivateIdentifier): string | null { +function readStringLiteralText(expression: AstNode): string | null { if (expression.type === 'Literal' && typeof expression.value === 'string') { return expression.value; } - if (expression.type === 'TemplateLiteral' && expression.expressions.length === 0) { - return expression.quasis[0]?.value.cooked ?? null; + if (expression.type === 'TemplateLiteral' && expression.expressions?.length === 0) { + const cooked = expression.quasis?.[0]?.value.cooked; + return typeof cooked === 'string' ? cooked : null; } return null; } -function unwrapParenthesizedExpression( - expression: Expression | PrivateIdentifier, -): Expression | PrivateIdentifier { +function unwrapParenthesizedExpression(expression: AstNode): AstNode { let current = expression; - while (current.type === 'ParenthesizedExpression') { + while (current.type === 'ParenthesizedExpression' && current.expression != null) { current = current.expression; } return current; From 90ba157e76821fb69c3b2a1e5af9ffd125870567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 22:14:48 +0100 Subject: [PATCH 2/2] ci: budget the numeric-range step on its own The audit's cost is per function parameter type, so a parameter typed as a parser's whole expression union makes one file cost minutes of analysis. The budget goes on the step rather than the job: a lockfile-changing PR pays a cold install in Setup toolchain, and that must not decide whether the gate runs. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 809d22b3ed..c585559881 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -284,7 +284,11 @@ jobs: - name: Setup toolchain uses: ./.github/actions/setup-node-pnpm + # The audit classifies every function parameter's declared type, so a parameter typed as a + # parser's whole expression union makes one file cost minutes of analysis. The budget is on + # the step, not the job, so a cold install cannot trip it. - name: Check numeric ranges + timeout-minutes: 3 uses: ./.github/actions/run-gate with: { gate: freerange }