Skip to content

[dotnet] [bidi] Make BytesValue not nested #15433

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

Merged
merged 2 commits 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 BytesValue to use non-nested types for better extensibility.

  • Updated references to BytesValue.String and BytesValue.Base64 to StringBytesValue and Base64BytesValue.

  • Adjusted test cases to align with the new BytesValue structure.

  • Removed unnecessary nested type serialization in BiDiJsonSerializerContext.


Changes walkthrough 📝

Relevant files
Enhancement
BiDiJsonSerializerContext.cs
Removed nested type serialization for `BytesValue`             

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

  • Removed nested type BytesValue.String from JSON serialization.
  • Simplified serialization by removing unnecessary nested type
    reference.
  • +0/-1     
    BytesValue.cs
    Refactored `BytesValue` to non-nested types                           

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

  • Refactored BytesValue.String to StringBytesValue.
  • Refactored BytesValue.Base64 to Base64BytesValue.
  • Updated implicit operator to use StringBytesValue.
  • +6/-6     
    Tests
    NetworkEventsTest.cs
    Updated network event tests for `BytesValue` changes         

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

  • Updated test assertions to use StringBytesValue instead of
    BytesValue.String.
  • Ensured compatibility with refactored BytesValue structure.
  • +1/-1     
    StorageTest.cs
    Updated storage tests for `BytesValue` changes                     

    dotnet/test/common/BiDi/Storage/StorageTest.cs

  • Updated test assertions to use StringBytesValue instead of
    BytesValue.String.
  • Ensured compatibility with refactored BytesValue structure.
  • +1/-1     

    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:

    • Replaced nested BytesValue.String and BytesValue.Base64 with standalone StringBytesValue and Base64BytesValue types

    Requires further human verification:

    • Verify if there are other nested DTO types that should be refactored similarly
    • Confirm that all references to the refactored types have been updated throughout the codebase
    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Serialization Attributes

    Verify that the JSON serialization attributes are correctly applied to the new non-nested types and that they will serialize/deserialize properly with the BiDi protocol.

    [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
    [JsonDerivedType(typeof(StringBytesValue), "string")]
    [JsonDerivedType(typeof(Base64BytesValue), "base64")]

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 16, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Register new serializable types

    Add the missing [JsonSerializable] attribute for the new StringBytesValue and
    Base64BytesValue types in the BiDiJsonSerializerContext.cs file. The old nested
    type was removed from serialization context, but the new standalone types need
    to be registered.

    dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs [24-34]

    +[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
    +[JsonDerivedType(typeof(StringBytesValue), "string")]
    +[JsonDerivedType(typeof(Base64BytesValue), "base64")]
    +public abstract record BytesValue
    +{
    +    public static implicit operator BytesValue(string value) => new StringBytesValue(value);
    +}
     
    +public record StringBytesValue(string Value) : BytesValue;
     
    +public record Base64BytesValue(string Value) : BytesValue;
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: The PR refactored nested types to standalone types (StringBytesValue and Base64BytesValue), but failed to register these new types in the BiDiJsonSerializerContext. This is a critical issue as it would cause serialization failures at runtime when these types are used.

    High
    Learned
    best practice
    Add null validation for string parameters in record constructors to prevent potential null reference exceptions

    The new StringBytesValue and Base64BytesValue records accept a string parameter
    but don't validate that it's not null. Since these values are likely required
    for proper functionality, add null validation in the constructor or use a
    non-nullable property with validation.

    dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs [32-34]

    -public record StringBytesValue(string Value) : BytesValue;
    +public record StringBytesValue : BytesValue
    +{
    +    public string Value { get; }
    +    
    +    public StringBytesValue(string value)
    +    {
    +        ArgumentNullException.ThrowIfNull(value, nameof(value));
    +        Value = value;
    +    }
    +}
     
    -public record Base64BytesValue(string Value) : BytesValue;
    +public record Base64BytesValue : BytesValue
    +{
    +    public string Value { get; }
    +    
    +    public Base64BytesValue(string value)
    +    {
    +        ArgumentNullException.ThrowIfNull(value, nameof(value));
    +        Value = value;
    +    }
    +}
    • Apply this suggestion
    Suggestion importance[1-10]: 6
    Low
    • Update

    @nvborisenko nvborisenko merged commit 6d26762 into SeleniumHQ:trunk Mar 17, 2025
    9 of 10 checks passed
    @nvborisenko nvborisenko deleted the bidi-bytesvalue branch March 17, 2025 16:03
    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