chrome-devtools-mcp icon indicating copy to clipboard operation
chrome-devtools-mcp copied to clipboard

fix(telemetry): resolve enum values through nested schema wrappers

Open Liohtml opened this issue 4 months ago • 3 comments

What

generateToolMetrics reads an enum parameter's values by unwrapping at most one optional wrapper:

if (schema._def.values?.length > 0) {
  values = schema._def.values;
} else {
  values = schema._def.innerType._def.values; // only one level
}

An enum parameter wrapped in .default().optional() (or any nested optional/default/nullable combination) therefore falls through to schema._def.innerType._def.values === undefined, and npm run update-metrics (run as part of npm run gen) crashes:

TypeError: Cannot read properties of undefined (reading '0')
    at validateEnumHomogeneity (build/src/telemetry/metricsRegistry.js:12)
    at generateToolMetrics (build/src/telemetry/metricsRegistry.js:59)

Why it matters

npm run gen is required whenever a tool is added or changed (per CONTRIBUTING.md). Declaring an enum parameter with a default — a natural, documented zod pattern — silently breaks docs/metrics generation.

Fix

Add getEnumValues() in transformation.ts that recursively unwraps optional / default / nullable / effects wrappers, mirroring the existing getZodType(), and use it in generateToolMetrics. Behavior is unchanged for the existing bare-enum and single-optional cases.

Tests

  • getEnumValues unit tests: bare enum, optional, default, both orders of default+optional, and throws for a non-enum type.
  • generateToolMetrics regression test with zod.enum(...).default(...).optional().
  • npm run typecheck, the telemetry tests, and npm run check-format pass.

First-time contributor here — happy to sign the CLA.

Liohtml avatar Jul 07 '26 13:07 Liohtml

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Jul 07 '26 13:07 google-cla[bot]

LGTM, but @yulunz can you please check it as well?

nattallius avatar Jul 08 '26 14:07 nattallius

Thanks for taking a look, @nattallius! Happy to address anything @yulunz flags — the change is small and isolated (a recursive enum-value unwrap in the telemetry helper) with unit + regression tests.

Liohtml avatar Jul 08 '26 14:07 Liohtml