Skip to content

[dotnet] [bidi] Make script Target as not nested #15436

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 nested Target types into standalone types for better usability.

  • Updated references to Target.Context and Target.Realm to ContextTarget and RealmTarget.

  • Adjusted serialization attributes to reflect the new standalone types.

  • Updated and validated test cases to use the new standalone types.


Changes walkthrough 📝

Relevant files
Enhancement
BiDiJsonSerializerContext.cs
Adjust serialization for standalone `Target` types             

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

  • Removed serialization attributes for nested Target types.
  • Adjusted serialization to align with standalone types.
  • +0/-3     
    BrowsingContextScriptModule.cs
    Replace nested `Target.Context` with `ContextTarget`         

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs

  • Replaced Target.Context with ContextTarget in method calls.
  • Updated logic to use standalone ContextTarget.
  • +2/-2     
    Target.cs
    Refactor `Target` into standalone types                                   

    dotnet/src/webdriver/BiDi/Modules/Script/Target.cs

  • Refactored Target into standalone RealmTarget and ContextTarget.
  • Updated properties and structure for new types.
  • +8/-9     
    Tests
    CallFunctionParameterTest.cs
    Update tests to use `RealmTarget`                                               

    dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs

  • Updated test cases to use RealmTarget instead of Target.Realm.
  • Validated functionality with new standalone types.
  • +4/-4     
    EvaluateParametersTest.cs
    Update tests to use `RealmTarget`                                               

    dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs

  • Updated test cases to use RealmTarget instead of Target.Realm.
  • Validated functionality with new standalone types.
  • +4/-4     

    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 BiDi implementation
    • Replace nested types with standalone types

    Requires further human verification:

    • Verify if all nested types across the codebase have been addressed, not just the Target class

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Missing JsonSerializable Attributes

    The PR removed JsonSerializable attributes for the nested Target types but didn't add corresponding attributes for the new standalone types in BiDiJsonSerializerContext.cs. This might cause serialization issues.

    [JsonDerivedType(typeof(RealmTarget))]
    [JsonDerivedType(typeof(ContextTarget))]
    public abstract record Target;
    Missing Initialization

    The PR adds a new ContextTarget initialization but there's a line with no code before the if statement that might indicate incomplete refactoring.

    var contextTarget = new ContextTarget(context);
    
    if (targetOptions is not null)

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 16, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add polymorphic serialization attribute

    Add JsonPolymorphic attribute to the Target class to ensure proper polymorphic
    serialization/deserialization. Without this attribute, the JsonDerivedType
    attributes may not work correctly for polymorphic serialization in .NET.

    dotnet/src/webdriver/BiDi/Modules/Script/Target.cs [24-26]

    +[JsonPolymorphic]
     [JsonDerivedType(typeof(RealmTarget))]
     [JsonDerivedType(typeof(ContextTarget))]
     public abstract record Target;
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: The suggestion correctly identifies a critical issue with JSON polymorphic serialization. Without the [JsonPolymorphic] attribute, the JsonDerivedType attributes won't properly enable type discrimination during serialization/deserialization, which could lead to runtime errors or incorrect behavior in the BiDi communication.

    High
    • Update

    @nvborisenko nvborisenko merged commit 01c0ef4 into SeleniumHQ:trunk Mar 17, 2025
    3 of 4 checks passed
    @nvborisenko nvborisenko deleted the bidi-target branch March 17, 2025 15:36
    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