[js] Expose BiDi CDDL ast and model as shared artifacts#17657
Conversation
5ad5308 to
1d2c4a5
Compare
Code Review by Qodo
1. No tests for buildModel()
|
There was a problem hiding this comment.
Pull request overview
Refactors the JavaScript WebDriver BiDi generator so it can emit reusable, cross-binding build artifacts (a parsed CDDL AST JSON and a binding-neutral BiDi command/event model JSON), and wires those artifacts into Bazel as shared targets for other bindings to consume.
Changes:
- Split
generate_bidi.mjsinto a 3-stage CLI pipeline: CDDL → AST JSON, AST → model JSON, AST+model → generated TypeScript. - Add Bazel targets for
bidi-ast.jsonandbidi-model.jsonand rewire TS generation to consume them. - Open artifact visibility for
//java,//py, and//rbconsumers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| javascript/selenium-webdriver/generate_bidi.mjs | Adds staged pipeline and introduces binding-neutral model build/consumption paths. |
| javascript/selenium-webdriver/private/generate_bidi.bzl | Publishes AST/model artifacts as Bazel targets and updates the generator pipeline wiring. |
|
This looks good to me. Thank you, Titus! |
🔗 Related Issues
Addresses #17654. In draft until #17574 is merged, since it is based on that code.
💥 What does this PR do?
Parses the CDDL to expose two reusable artifacts, instead of being built in memory inside
create-bidi-src_tsand discarded. Other bindings (Java/Ruby/Python) can then consume one shared description of the BiDi command/event surface rather than each re-parsing the spec. The CDDL is parsed exactly once, and the shipped JS package is unchanged — the generated TypeScript is byte-identical to #17574.create-bidi-src_merged_cddlcreate-bidi-src_merged.cddlcreate-bidi-src_ts(old).tsmodule per BiDi domaincreate-bidi-src_astcreate-bidi-src_ast.json— full parsed ASTcreate-bidi-src_jsoncreate-bidi-src_ast.jsoncreate-bidi-src_model.json— binding-neutral command/event modelcreate-bidi-src_ts(new)create-bidi-src_ast.json+create-bidi-src_model.json.tsmodule per BiDi domaincreate-bidi-src.tsmodules.js+.d.ts(tsc)🔧 Implementation Notes
browser.CreateUserContextParameters), not cddl2ts's PascalCase, so each binding applies its own naming. Shape per domain:commands: [{method, name, params, result}],events: [{method, name, params}].params/resultarenullwhen a command takes no params / returns no value. Void is decided from the AST at model-build time (absent result type, or one aliased toEmptyResult) rather than in the JS emitter, so a consumer can trust the field without re-deriving it. Verified this matches the existing JS void detection across all 77 commands.create-bidi-src_astandcreate-bidi-src_jsonare visible to//java,//py,//rbso each binding depends on only the artifact it needs.🤖 AI assistance
generate_bidi.mjs, the binding-neutral model extractor, and the Bazel target wiring.💡 Additional Considerations
Deviations from #17654 (intentional refinements):
resultisnullwhen it returns nothing andparamsisnullwhen it takes no arguments, so a consumer can spot void/argument-less commands from the model alone (the issue listed those fields without the empty case). The model also adds anamefield — the bare operation name (createUserContext) next to the fullmethod(browser.createUserContext).Follow-ups / things noticed (left as-is here):
create-bidi-src_model.jsonin future PRs.CommandData/EventData(and extension) unions, so anything the spec defines but never wires into a union is silently absent. This is a limitation of the CDDL structure, not the extractor. Example:bluetooth.characteristicEventGeneratedandbluetooth.descriptorEventGeneratedare defined but added to noBluetoothEventunion, so they don't appear in the model (not needed for Selenium, so not chasing this one down right now).🔄 Types of changes