fix(python): preserve query parameters in CDP discovery URLs

Draft
KA
4d ago
+54-2

An HTTP CDP endpoint such as https://proxy.test/browser/?token=demo is currently probed as https://proxy.test/browser/?token=demo/json/version. The discovery suffix becomes part of the query value, so the resolver polls the wrong URL. A fragment can similarly swallow the suffix.

Build the discovery URL from parsed URL components: append /json/version to the path, preserve the original query (including percent encoding), and omit the fragment. Direct ws:// and wss:// endpoints continue to pass through unchanged.

Added eight regression/control cases. Four query/fragment cases fail before the fix; four plain-HTTP/WebSocket controls already pass. All 62 CDP client tests pass with the fix. Python Ruff lint/format, ty, and git diff --check pass. Tests use a mocked discovery reader and fake sockets; no browser or external service was used. A Python-only patch changeset is included; no protocol/generated code changes.

Developed with AI assistance; reproduced the malformed discovery URLs locally and reviewed the patch and tests. The TypeScript resolver has similar string concatenation; this PR is scoped to the Python SDK.

Full Python suite: 794 passed, 1 skipped, 1 failed because the checkout lacks the built extension manifest. The same test fails on the unmodified base; it is unrelated to this patch. Cross-language just check/just test were not run.


Summary by cubic

Fixes CDP discovery URL construction when the HTTP endpoint has a query string or fragment. Such endpoints were probed with the discovery suffix appended to the query value (e.g. .../browser/?token=demo became .../browser/?token=demo/json/version), so the resolver polled the wrong URL.

  • Builds the discovery URL from parsed URL components, appending /json/version to the path, preserving the query (including percent encoding), and dropping the fragment.
  • ws:// and wss:// endpoints pass through unchanged.
  • Adds regression tests for query/fragment cases and WebSocket passthrough.