-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] [bidi] Fully immutable commands and events #17077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dotnet] [bidi] Fully immutable commands and events #17077
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||||||||||
PR Code Suggestions ✨No code suggestions found for the PR. |
There was a problem hiding this 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 refactors the .NET BiDi binding’s command option types (and many related value/event types) to be immutable-at-the-API-surface by converting classes to records and replacing property setters with init accessors.
Changes:
- Convert
CommandOptionsand most*Optionstypes from classes to records, switching{ get; set; }to{ get; init; }. - Update various BiDi value/event model types (cookies, script values, proxy config, locators, etc.) to use
init-only properties. - Adjust a few call sites to use object initializers (e.g.,
ContextTargetsandbox assignment) to comply withinitusage.
Reviewed changes
Copilot reviewed 85 out of 85 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/webdriver/BiDi/WebExtension/UninstallCommand.cs | Convert UninstallOptions to a record for immutability. |
| dotnet/src/webdriver/BiDi/WebExtension/InstallCommand.cs | Convert InstallOptions to a record for immutability. |
| dotnet/src/webdriver/BiDi/Subscription.cs | Convert subscription option types to records and make properties init-only. |
| dotnet/src/webdriver/BiDi/Storage/SetCookieCommand.cs | Make cookie/options properties init-only; convert option types to records. |
| dotnet/src/webdriver/BiDi/Storage/PartitionKey.cs | Make partition key properties init-only. |
| dotnet/src/webdriver/BiDi/Storage/GetCookiesCommand.cs | Convert options to records; make filter/partition properties init-only. |
| dotnet/src/webdriver/BiDi/Storage/DeleteCookiesCommand.cs | Convert options to records; make filter/partition properties init-only. |
| dotnet/src/webdriver/BiDi/Session/UserPromptHandler.cs | Make handler properties init-only. |
| dotnet/src/webdriver/BiDi/Session/UnsubscribeCommand.cs | Convert UnsubscribeByIdOptions to a record. |
| dotnet/src/webdriver/BiDi/Session/SubscribeCommand.cs | Convert SubscribeOptions to a record and make properties init-only. |
| dotnet/src/webdriver/BiDi/Session/StatusCommand.cs | Convert StatusOptions to a record. |
| dotnet/src/webdriver/BiDi/Session/ProxyConfiguration.cs | Make proxy configuration properties init-only; update interface accordingly. |
| dotnet/src/webdriver/BiDi/Session/NewCommand.cs | Convert NewOptions to a record; make capability properties init-only. |
| dotnet/src/webdriver/BiDi/Session/EndCommand.cs | Convert EndOptions to a record. |
| dotnet/src/webdriver/BiDi/Session/CapabilityRequest.cs | Make capability request properties init-only. |
| dotnet/src/webdriver/BiDi/Session/CapabilitiesRequest.cs | Make capabilities request properties init-only. |
| dotnet/src/webdriver/BiDi/Script/Target.cs | Make ContextTarget.Sandbox init-only. |
| dotnet/src/webdriver/BiDi/Script/Source.cs | Make Source.Context init-only. |
| dotnet/src/webdriver/BiDi/Script/SerializationOptions.cs | Convert to record; make serialization settings init-only. |
| dotnet/src/webdriver/BiDi/Script/RemovePreloadScriptCommand.cs | Convert RemovePreloadScriptOptions to a record. |
| dotnet/src/webdriver/BiDi/Script/RemoteValue.cs | Make remote value properties init-only across many variants. |
| dotnet/src/webdriver/BiDi/Script/RegExpValue.cs | Make Flags init-only. |
| dotnet/src/webdriver/BiDi/Script/RealmInfo.cs | Make Sandbox init-only. |
| dotnet/src/webdriver/BiDi/Script/LocalValue.cs | Make remote-reference local value properties init-only. |
| dotnet/src/webdriver/BiDi/Script/IRemoteReference.cs | Make reference interface properties init-only; align implementers. |
| dotnet/src/webdriver/BiDi/Script/GetRealmsCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Script/EvaluateCommand.cs | Convert EvaluateOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/Script/DisownCommand.cs | Convert DisownOptions to a record. |
| dotnet/src/webdriver/BiDi/Script/ChannelProperties.cs | Make channel properties init-only. |
| dotnet/src/webdriver/BiDi/Script/CallFunctionCommand.cs | Convert CallFunctionOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/Script/AddPreloadScriptCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Permissions/SetPermissionCommand.cs | Convert SetPermissionOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/Network/UrlPattern.cs | Make URL pattern properties init-only. |
| dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs | Convert SetExtraHeadersOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/Network/SetCookieHeader.cs | Make set-cookie header properties init-only. |
| dotnet/src/webdriver/BiDi/Network/SetCacheBehaviorCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Network/RemoveInterceptCommand.cs | Convert RemoveInterceptOptions to a record. |
| dotnet/src/webdriver/BiDi/Network/RemoveDataCollectorCommand.cs | Convert RemoveDataCollectorOptions to a record. |
| dotnet/src/webdriver/BiDi/Network/ProvideResponseCommand.cs | Convert ProvideResponseOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/Network/NetworkModule.HighLevel.cs | Convert interception option marker types to records. |
| dotnet/src/webdriver/BiDi/Network/Initiator.cs | Make initiator properties init-only. |
| dotnet/src/webdriver/BiDi/Network/GetDataCommand.cs | Convert GetDataOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/Network/FailRequestCommand.cs | Convert FailRequestOptions to a record. |
| dotnet/src/webdriver/BiDi/Network/ContinueWithAuthCommand.cs | Convert auth continuation option hierarchy to records. |
| dotnet/src/webdriver/BiDi/Network/ContinueResponseCommand.cs | Convert ContinueResponseOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/Network/ContinueRequestCommand.cs | Convert ContinueRequestOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/Network/AddInterceptCommand.cs | Convert intercept options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Network/AddDataCollectorCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Log/LogEntry.cs | Make StackTrace init-only. |
| dotnet/src/webdriver/BiDi/Input/SourceActions.cs | Make various input action properties init-only; adjust action container property to init-only. |
| dotnet/src/webdriver/BiDi/Input/SetFilesCommand.cs | Convert SetFilesOptions to a record. |
| dotnet/src/webdriver/BiDi/Input/ReleaseActionsCommand.cs | Convert ReleaseActionsOptions to a record. |
| dotnet/src/webdriver/BiDi/Input/PerformActionsCommand.cs | Convert PerformActionsOptions to a record. |
| dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverrideCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Emulation/SetTouchOverrideCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverrideCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabledCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverrideCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverrideCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Emulation/SetNetworkConditionsCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverrideCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverrideCommand.cs | Convert geolocation option hierarchy to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverrideCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/CommandOptions.cs | Convert base options type to abstract record; make Timeout init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistoryCommand.cs | Convert TraverseHistoryOptions to a record. |
| dotnet/src/webdriver/BiDi/BrowsingContext/SetViewportCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/ReloadCommand.cs | Convert ReloadOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs | Convert PrintOptions to a record; make print settings init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/NavigateCommand.cs | Convert NavigateOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/Locator.cs | Make locator/accessibility value properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodesCommand.cs | Convert LocateNodesOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPromptCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/CreateCommand.cs | Convert CreateOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/CloseCommand.cs | Convert CloseOptions to a record; make properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshotCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs | Update sandbox assignment to use object initializer (init-only compliance). |
| dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs | Convert interception option marker types to records. |
| dotnet/src/webdriver/BiDi/BrowsingContext/ActivateCommand.cs | Convert ActivateOptions to a record. |
| dotnet/src/webdriver/BiDi/Browser/SetDownloadBehaviorCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Browser/RemoveUserContextCommand.cs | Convert RemoveUserContextOptions to a record. |
| dotnet/src/webdriver/BiDi/Browser/GetUserContextsCommand.cs | Convert GetUserContextsOptions to a record. |
| dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs | Convert GetClientWindowsOptions to a record. |
| dotnet/src/webdriver/BiDi/Browser/CreateUserContextCommand.cs | Convert options to records; make properties init-only. |
| dotnet/src/webdriver/BiDi/Browser/CloseCommand.cs | Convert CloseOptions to a record. |
Comments suppressed due to low confidence (1)
dotnet/src/webdriver/BiDi/Input/SourceActions.cs:42
- This PR description states “everything in BiDi world now is immutable”, but SourceActions still exposes a mutable IList and an Add() method that mutates the instance after construction. If the intent is deep immutability, consider switching Actions to an immutable/read-only collection and making mutation APIs return a new instance (or adjust the PR description/scope to clarify that input actions remain mutable builders).
Now we are forcing user to construct command options object and never change it. So everything in Bidi world now is immutable!
🔗 Related Issues
Contributes to #16095
💥 What does this PR do?
This pull request makes broad improvements to the BiDi WebDriver codebase by refactoring option types from classes to records and switching property setters to initializers. These changes enhance immutability, simplify object construction, and align with modern C# practices. The refactor affects command option types across browser and browsing context modules, as well as related value types and utility structs.
These changes collectively modernize the codebase, making it safer and easier to work with, especially when constructing and passing command options.
🔄 Types of changes