[js] Add Javascript/Typescript CDDL code generator for WebDriver BiDi#17574
Conversation
Review Summary by QodoAdd JavaScript/TypeScript CDDL code generator for WebDriver BiDi with comprehensive test coverage
WalkthroughsDescription• Implements a comprehensive WebDriver BiDi code generator (generate_bidi.mjs) that transforms CDDL specifications into typed TypeScript domain classes • Two-pass generation approach: Pass 1 uses cddl2ts for type declarations with post-processing; Pass 2 walks raw CDDL AST to extract commands and events for implementation • Generates per-domain modules (Browser, BrowsingContext, Input, Log, Network, Script, Storage, Emulation) with typed command methods and event subscription helpers • Introduces enhancements manifest (bidi_enhancements_manifest.json) for injecting hand-written additions (deprecated compatibility shims, convenience wrappers) without modifying generated code • Integrates code generation into Bazel build pipeline via generate_bidi_library() macro that orchestrates CDDL merging, TypeScript generation, and compilation • Comprehensive integration test suite covering all generated BiDi domains with Chrome and Firefox browser validation • Adds cddl@^0.20.1 and cddl2ts@^0.9.1 dev dependencies and updates pnpm workspace configuration for dependency resolution • Expands visibility of CDDL merge tool to JavaScript build pipeline Diagramflowchart LR
CDDL["CDDL Specifications<br/>WebDriver BiDi, Permissions,<br/>Prefetch, UA Client Hints"]
Merge["Merge CDDL<br/>merge_cddl"]
Gen["Two-Pass Generator<br/>generate_bidi.mjs"]
Types["Type Declarations<br/>cddl2ts Pass 1"]
Impl["Implementation Classes<br/>Pass 2 AST Walk"]
Manifest["Enhancements Manifest<br/>bidi_enhancements_manifest.json"]
Output["Generated Domain Modules<br/>Browser, BrowsingContext,<br/>Input, Log, Network,<br/>Script, Storage, Emulation"]
Tests["Integration Tests<br/>All domains + browsers"]
Package["npm Package"]
CDDL --> Merge
Merge --> Gen
Gen --> Types
Gen --> Impl
Manifest --> Gen
Types --> Output
Impl --> Output
Output --> Tests
Output --> Package
Tests -.-> Package
File Changes1. javascript/selenium-webdriver/test/bidi/generated/browsing_context_test.js
|
Code Review by Qodo
1.
|
|
Code review by qodo was updated up to the latest commit 2dfef49 |
|
Code review by qodo was updated up to the latest commit 68d0f22 |
|
@pujagani This looks good, can we make sure the AI reviews are correct and resolve accordingly? |
|
Thank you for reviewing @AutomatedTester. Will do. |
|
Code review by qodo was updated up to the latest commit 5ec2e30 |
- back()/forward(): accept a context id instead of hard-coding an empty
string; delegate to traverseHistory({ context, delta: ±1 })
- continueWithAuth: replace username!/password! non-null assertions with
an explicit undefined guard that throws a descriptive error
- continueWithAuth: capture bidi.send() response and apply the same
response['type'] === 'error' check as generated methods, preventing
silent failures
|
Code review by qodo was updated up to the latest commit 25da91e |
|
Code review by qodo was updated up to the latest commit 4e9302d |
411f358 to
4e9302d
Compare
|
Code review by qodo was updated up to the latest commit 4e9302d |
|
Code review by qodo was updated up to the latest commit 527724a |
|
Code review by qodo was updated up to the latest commit 3c7f94f |
|
Code review by qodo was updated up to the latest commit 9af40fb |
🔗 Related Issues
Related to #17487
Part of the CDDL WebDriver BiDi API generator. Implemented as defined in the spec https://gist.github.com/AutomatedTester/148437f846a3759f7678c7ff6debb210
💥 What does this PR do?
Adds a code generator (
generate_bidi.mjs) that reads the merged WebDriver BiDi CDDLspecification and emits one typed TypeScript module per domain into
bidi/generated/.The generator is wired into the Bazel build so the output is compiled and included in
the npm package automatically.
Each generated domain class (
Browser,BrowsingContext,Input,Log,Network,Script,Storage, etc.) exposes typed command methods and event subscription helpersvia a
static async create(driver)factory. An enhancements manifest(
private/bidi_enhancements_manifest.json) allows hand-written additions (deprecatedcompatibility shims, convenience wrappers, and method overloads) to be injected at
build time without modifying generated files.
🔧 Implementation Notes
Why a two-pass generator?
cddl2tsonly produces type declarations; it has no concept of the BiDi command/eventdistinction. A second pass walks the raw CDDL AST to identify commands (groups with a
methodliteral andparams) and events (same structure plustype: "event") andemits the implementation class from that.
Why throw on error responses?
bidi/index.jsalways resolves, it never rejects on BiDi error responses. Both voidand non-void generated methods inspect the response payload and throw if
response.type === 'error', so unhandled server errors surface as test failures ratherthan being silently swallowed.
Why an enhancements manifest?
The existing hand-crafted modules use a builder pattern
(
getBrowserInstance(driver),AddInterceptParameters). The generated API uses typedparams objects. Replacing the old exports directly would be a breaking change. The
manifest lets deprecated compatibility wrappers live alongside generated code until a
major version bump removes them.
🤖 AI assistance
integration tests under
test/bidi/generated/💡 Additional Considerations
Breaking change: The generated API shape (
Domain.create(driver), typed paramsobjects) differs from the existing hand-crafted modules (positional args, builder
classes). Deprecated compatibility shims are in place for the most-used modules but a
full audit is needed before the old modules can be removed. See the Phase 7 audit in
the PR description or tracking issue for the complete list.
Follow-on work required:
captureBoxScreenshot,captureElementScreenshot,locateNode,locateElement,locateElements(BrowsingContext); filtered log level variants (Log).browsingContextInspector.jsandnetworkInspector.js— superseded byevent methods on the generated
BrowsingContextandNetworkclassesAddInterceptParameters,ContinueRequestParameters,CookieFilter, etc.).🔄 Types of changes