Skip to content

[py] Use generated Bidi files instead of hand curated ones#17266

Merged
AutomatedTester merged 44 commits intotrunkfrom
cddl2py_bazel
Apr 20, 2026
Merged

[py] Use generated Bidi files instead of hand curated ones#17266
AutomatedTester merged 44 commits intotrunkfrom
cddl2py_bazel

Conversation

@AutomatedTester
Copy link
Copy Markdown
Member

🔗 Related Issues

💥 What does this PR do?

Deletes all the hand curated bidi code in the python tree and uses the generated code created in #16914 . Once that PR is approved we can merge this into there or do it into trunk as a 2nd PR. #16914 MUST BE FIRST INTO TRUNK

🔧 Implementation Notes

💡 Additional Considerations

🔄 Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)

Copilot AI review requested due to automatic review settings March 27, 2026 14:00
@selenium-ci selenium-ci added C-py Python Bindings C-dotnet .NET Bindings B-build Includes scripting, bazel and CI integrations B-devtools Includes everything BiDi or Chrome DevTools related labels Mar 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates Selenium’s Python WebDriver BiDi implementation from hand-curated source files to Bazel-generated modules produced from the BiDi CDDL specification (per #16914), and adjusts supporting build/test infrastructure accordingly.

Changes:

  • Remove the hand-maintained py/selenium/webdriver/common/bidi/* modules and wire Bazel to generate them from common/bidi/spec/*.cddl.
  • Update Python runtime plumbing to support generated BiDi dataclasses over WebSocket (custom JSON encoding + RemoteWebDriver.execute() accepting BiDi command generators).
  • Add/adjust supporting tooling and tests (local dev copy task, CLI alias, minor test robustness tweaks).

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/update_copyright.py Stop excluding a removed BiDi file from copyright updates.
rake_tasks/python.rake Copy generated BiDi files into the source tree for local dev workflows.
py/test/selenium/webdriver/common/bidi_browsing_context_tests.py Make viewport assertions tolerant to minor WM differences.
py/test/selenium/webdriver/common/bidi_browser_tests.py Update imports/constants + locator usage to match generated BiDi APIs.
py/selenium/webdriver/remote/websocket_connection.py Add BiDi-oriented JSON encoding for dataclass payloads when sending WS commands.
py/selenium/webdriver/remote/webdriver.py Allow execute() to accept BiDi command generators and route them via WebSocket.
py/selenium/webdriver/common/proxy.py Add __future__ annotations + formatting adjustments.
py/selenium/webdriver/common/by.py Add __future__ annotations + reformat ByType literal.
py/selenium/webdriver/common/bidi/webextension.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/storage.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/session.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/script.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/permissions.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/network.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/log.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/input.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/emulation.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/console.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/common.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/browsing_context.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/browser.py Remove hand-curated BiDi module (replaced by generated).
py/selenium/webdriver/common/bidi/init.py Remove hand-curated package init (replaced by generated).
py/selenium/common/exceptions.py Formatting-only changes to exception constructors.
py/private/generate_bidi.bzl Add Bazel rule to generate BiDi Python modules from CDDL.
py/private/cdp.py Tighten devtools version directory detection.
py/private/_event_manager.py Add shared event manager used by generated BiDi modules.
py/private/BUILD.bazel Export generator support files for Bazel consumption.
py/conftest.py Add --browser CLI alias for --driver.
py/BUILD.bazel Wire BiDi generation into the Python build graph.
py/AGENTS.md Update Python 3.10+ guidance for agents/contributors.
dotnet/src/webdriver/BiDi/EventDispatcher.cs Refactor event dispatcher internals (currently contains compile-breaking issues).
common/bidi/spec/remote.cddl Add BiDi CDDL “remote” spec inputs for generation.
common/bidi/spec/local.cddl Add BiDi CDDL “local” spec inputs for generation.
common/bidi/spec/BUILD.bazel Export CDDL specs for the Python generator rule.
Comments suppressed due to low confidence (2)

dotnet/src/webdriver/BiDi/EventDispatcher.cs:43

  • The channel is typed as Channel<EventItem>, but this file only defines PendingEvent and EnqueueEvent writes PendingEvent instances. This won’t compile unless EventItem exists and matches the written type; either switch the channel back to Channel<PendingEvent> or introduce a consistent EventItem type and use it everywhere.
    private readonly Channel<EventItem> _pendingEvents = Channel.CreateUnbounded<EventItem>(new()
    {
        SingleReader = true,
        SingleWriter = true
    });

dotnet/src/webdriver/BiDi/EventDispatcher.cs:99

  • Inside ProcessEventsAsync, the loop reads into evt, but the code still references result.Method / result.EventArgs. This won’t compile and will also read the wrong values. Use the variable you actually read from the channel consistently (and ensure its type matches the channel’s item type).
        while (await reader.WaitToReadAsync().ConfigureAwait(false))
        {
            while (reader.TryRead(out var evt))
            {
                if (_eventRegistrations.TryGetValue(result.Method, out var registration))
                {
                    foreach (var handler in registration.GetHandlers()) // copy-on-write array, safe to iterate
                    {
                        var runningHandlerTask = InvokeHandlerAsync(handler, result.EventArgs);
                        if (!runningHandlerTask.IsCompleted)
                        {

Comment thread dotnet/src/webdriver/BiDi/EventDispatcher.cs Outdated
Comment thread rake_tasks/python.rake
Comment thread rake_tasks/python.rake
Comment thread rake_tasks/python.rake Outdated
@cgoldberg
Copy link
Copy Markdown
Member

We need to add the directory to ruff config in pyproject.toml or else the linter will fail if you run it with the files in your local source tree.

You can add it to:

[tool.ruff]
extend-exclude = [
    "selenium/webdriver/common/devtools/",
    "selenium/webdriver/common/bidi/",
]

@cgoldberg
Copy link
Copy Markdown
Member

@AutomatedTester I pushed a fix to your branch that resolves all the comments I made and also adds the generated files to .gitignore.

Copilot AI review requested due to automatic review settings March 29, 2026 20:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@cgoldberg
Copy link
Copy Markdown
Member

there are still some linting/formatting errors in the new generation code

Copilot AI review requested due to automatic review settings March 29, 2026 21:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

Copy link
Copy Markdown
Member

@cgoldberg cgoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed python.rake previously, but you force pushed over my commit :/ I just added comments again.

We should add the generated files to .gitignore

Also, run the formatter so it passes the lint job in CI.

Comment thread py/generate_bidi.py Outdated
Comment thread rake_tasks/python.rake Outdated
Comment thread rake_tasks/python.rake
Copilot AI review requested due to automatic review settings March 31, 2026 18:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 240 out of 250 changed files in this pull request and generated 7 comments.

Comment thread dotnet/private/dotnet_nunit_test_suite.bzl
Comment thread README.md
Comment thread README.md
Comment thread README.md
Comment thread py/selenium/webdriver/common/selenium_manager.py
Comment thread dotnet/private/nuget_pack.bzl
Comment thread dotnet/test/webdriver/AssemblyFixture.cs
Copilot AI review requested due to automatic review settings April 15, 2026 06:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 39 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

scripts/update_copyright.py:108

  • PY_EXCLUSIONS no longer excludes any MIT/third-party sources. With the new py/private/cdp.py (MIT-licensed) in this PR, running this script would prepend the Selenium Apache-2.0 notice to that file, which would be an incorrect/unsafe license header modification. Please add py/private/cdp.py (and any other non-SFC third-party sources) to PY_EXCLUSIONS so the script does not rewrite their license text.

Comment thread py/selenium/webdriver/common/bidi/network.py Outdated
Copilot AI review requested due to automatic review settings April 16, 2026 10:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 21 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

scripts/update_copyright.py:108

  • py/private/cdp.py now contains MIT-licensed code (moved from the previously-excluded py/selenium/webdriver/common/bidi/cdp.py), but it is not in PY_EXCLUSIONS. Running this script will try to replace the MIT header with the standard SFC/Apache notice, which would be incorrect. Add py/private/cdp.py (and any other non-SFC-licensed vendored files under py/private/) to PY_EXCLUSIONS so the updater does not rewrite their license headers.
PY_EXCLUSIONS = [
    f"{ROOT}/py/generate.py",
    f"{ROOT}/py/selenium/webdriver/common/devtools/**/*",
    f"{ROOT}/py/venv/**/*",
]

Comment thread py/BUILD.bazel Outdated
Copilot AI review requested due to automatic review settings April 17, 2026 14:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 22 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

scripts/update_copyright.py:108

  • PY_EXCLUSIONS still excludes generated DevTools sources, but BiDi sources are now generated/ignored as well (see .gitignore and //py:create-bidi-src). Consider also excluding py/selenium/webdriver/common/bidi/**/* to avoid this script rewriting generated BiDi modules when they exist locally (similar to the DevTools exclusion).
PY_EXCLUSIONS = [
    f"{ROOT}/py/generate.py",
    f"{ROOT}/py/selenium/webdriver/common/devtools/**/*",
    f"{ROOT}/py/venv/**/*",
]

Comment thread py/generate_bidi.py
Copilot AI review requested due to automatic review settings April 18, 2026 12:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 24 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

scripts/update_copyright.py:108

  • Now that selenium/webdriver/common/bidi is treated as generated output (it’s gitignored and Bazel-generated like common/devtools), scripts/update_copyright.py should exclude the BiDi generated directory as well. Otherwise running this script after generating BiDi sources locally will rewrite generated files (e.g., prepend the SFC header), causing noisy diffs and potentially conflicting with the generator’s intended headers. Consider adding an exclusion like f"{ROOT}/py/selenium/webdriver/common/bidi/**/*" (mirroring the existing devtools exclusion).
PY_EXCLUSIONS = [
    f"{ROOT}/py/generate.py",
    f"{ROOT}/py/selenium/webdriver/common/devtools/**/*",
    f"{ROOT}/py/venv/**/*",
]

Copilot AI review requested due to automatic review settings April 19, 2026 15:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@AutomatedTester AutomatedTester merged commit a75eb73 into trunk Apr 20, 2026
38 checks passed
@AutomatedTester AutomatedTester deleted the cddl2py_bazel branch April 20, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-build Includes scripting, bazel and CI integrations B-devtools Includes everything BiDi or Chrome DevTools related C-dotnet .NET Bindings C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants