Skip to content
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] Make UrlPattern as not nested #15434

Merged
merged 1 commit into from
Mar 17, 2025

Conversation

nvborisenko
Copy link
Member

@nvborisenko nvborisenko commented Mar 16, 2025

User description

Motivation and Context

Contributes to #15407

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement, Tests


Description

  • Refactored UrlPattern to use non-nested types for better extensibility.

  • Updated UrlPattern derived types to PatternUrlPattern and StringUrlPattern.

  • Adjusted test cases to use the new non-nested UrlPattern types.

  • Removed nested DTO type usage in BiDiJsonSerializerContext.


Changes walkthrough 📝

Relevant files
Enhancement
BiDiJsonSerializerContext.cs
Removed nested `UrlPattern.String` serialization                 

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

  • Removed JsonSerializable attribute for nested UrlPattern.String type.
  • Simplified serialization configuration by eliminating nested DTO
    reference.
  • +0/-1     
    UrlPattern.cs
    Refactored `UrlPattern` to non-nested derived types           

    dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs

  • Refactored UrlPattern to use non-nested derived types.
  • Renamed Pattern to PatternUrlPattern and String to StringUrlPattern.
  • Updated implicit operator to use StringUrlPattern.
  • +13/-16 
    Tests
    NetworkTest.cs
    Updated tests for non-nested `UrlPattern` types                   

    dotnet/test/common/BiDi/Network/NetworkTest.cs

  • Updated test cases to use PatternUrlPattern and StringUrlPattern.
  • Replaced references to nested UrlPattern types with new non-nested
    types.
  • +2/-2     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    15407 - PR Code Verified

    Compliant requirements:

    • Don't use nested DTO types in the .NET Selenium BiDi implementation
    • Replace nested types with standalone types to avoid name reservation issues

    Requires further human verification:

    • Verify if this change is part of a larger effort to convert all similar nested types
    • Confirm if this implementation follows the agreed pattern for all BiDi types
    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Property Removal

    The Pattern property was removed from the StringUrlPattern class. Verify this doesn't break any existing code that might be accessing this property.

    public record StringUrlPattern(string Pattern) : UrlPattern;

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add missing serialization attributes

    You've removed the serialization attribute for UrlPattern.String but need to add
    serialization attributes for the new non-nested types StringUrlPattern and
    PatternUrlPattern to ensure proper JSON serialization.

    dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs [124-125]

     [JsonSerializable(typeof(Modules.Network.BytesValue.String), TypeInfoPropertyName = "Network_BytesValue_String")]
    +[JsonSerializable(typeof(Modules.Network.StringUrlPattern), TypeInfoPropertyName = "Network_StringUrlPattern")]
    +[JsonSerializable(typeof(Modules.Network.PatternUrlPattern), TypeInfoPropertyName = "Network_PatternUrlPattern")]
     [JsonSerializable(typeof(Modules.Network.ContinueWithAuthParameters.Default), TypeInfoPropertyName = "Network_ContinueWithAuthParameters_Default")]
    • Apply this suggestion
    Suggestion importance[1-10]: 10

    __

    Why: This suggestion addresses a critical issue where serialization attributes for the new non-nested types are missing. Without these attributes, JSON serialization would fail for these types, breaking the BiDi communication functionality completely.

    High
    Add missing property accessor

    The StringUrlPattern record is missing a property accessor for the Pattern
    parameter. Without it, the Pattern value won't be properly serialized or
    accessible in the code.

    dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs [45]

    -public record StringUrlPattern(string Pattern) : UrlPattern;
    +public record StringUrlPattern(string Pattern) : UrlPattern
    +{
    +    public string Pattern { get; } = Pattern;
    +}
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: The suggestion correctly identifies a critical issue where the Pattern property accessor was removed during refactoring. Without this accessor, the pattern value won't be properly serialized or accessible, which would break functionality.

    High
    Learned
    best practice
    Add null handling in implicit conversion operators to prevent potential null reference issues

    The implicit operator doesn't validate if the input string is null before
    creating a new StringUrlPattern. This could lead to issues if null values are
    passed. Add a null check using the null-coalescing operator to provide a safe
    default value when the input is null.

    dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs [29]

    -public static implicit operator UrlPattern(string value) => new StringUrlPattern(value);
    +public static implicit operator UrlPattern(string value) => new StringUrlPattern(value ?? string.Empty);
    • Apply this suggestion
    Suggestion importance[1-10]: 6
    Low
    • More

    Copy link
    Contributor

    @RenderMichael RenderMichael left a comment

    Choose a reason for hiding this comment

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

    Looking nice.

    Small request, unrelated to changes.

    @nvborisenko nvborisenko merged commit 8d5a099 into SeleniumHQ:trunk Mar 17, 2025
    8 of 10 checks passed
    @nvborisenko nvborisenko deleted the bidi-urlpattern branch March 17, 2025 15:25
    sandeepsuryaprasad pushed a commit to sandeepsuryaprasad/selenium that referenced this pull request Mar 23, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants