[dotnet] [bidi] Remove IEnumerable of command results by nvborisenko · Pull Request #16219 · SeleniumHQ/selenium
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| High-level |
Ensure JSON deserialization worksYou removed custom JSON converters for enumerable results and changed result Examples:dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs [50]public sealed record GetTreeResult(IReadOnlyList<BrowsingContextInfo> Contexts) : EmptyResult; dotnet/src/webdriver/BiDi/Communication/Broker.cs [95-103]new Json.Converters.Polymorphic.EvaluateResultConverter(), new Json.Converters.Polymorphic.RemoteValueConverter(), new Json.Converters.Polymorphic.RealmInfoConverter(), new Json.Converters.Polymorphic.LogEntryConverter(), // // Enumerable new Json.Converters.Enumerable.InputSourceActionsConverter(), } Solution Walkthrough:Before:// In Broker.cs new JsonSerializerOptions { Converters = { // ... new Json.Converters.Enumerable.GetTreeResultConverter(), // ... } }; // In GetTreeCommand.cs public sealed record GetTreeResult : EmptyResult, IReadOnlyList<BrowsingContextInfo> { // ... manual implementation ... } After:// In Broker.cs new JsonSerializerOptions { Converters = { // GetTreeResultConverter is removed } }; // In GetTreeCommand.cs, to be robust against serializer settings: using System.Text.Json.Serialization; public sealed record GetTreeResult( [property: JsonPropertyName("contexts")] IReadOnlyList<BrowsingContextInfo> Contexts ) : EmptyResult; Suggestion importance[1-10]: 9__ Why: This suggestion correctly identifies a critical potential failure point in JSON deserialization after removing custom converters, which could break multiple BiDi commands at runtime if the implicit mapping fails. | High |
| Possible issue |
Null-safe realms accessGuard against a null dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs [44] -return (await scriptModule.GetRealmsAsync(options).ConfigureAwait(false)).Realms; +var result = await scriptModule.GetRealmsAsync(options).ConfigureAwait(false); +return result.Realms ?? Array.Empty<RealmInfo>();
Suggestion importance[1-10]: 6__ Why: The suggestion correctly identifies that | Low |
| General |
Null-safe empty assertionAccessing dotnet/src/webdriver/BiDi/Storage/StorageTest.cs [144] -Assert.That(cookiesResult.Cookies.Count, Is.EqualTo(0)); +Assert.That(cookiesResult.Cookies, Is.Empty);
Suggestion importance[1-10]: 5__ Why: The suggestion correctly points out a potential null reference and suggests a more robust and idiomatic assertion | Low |
| ||