Skip to content

[duplicate-code] Duplicate Code: ClientInfo/ServerInfo Record Pattern #8530

@Evangelink

Description

@Evangelink

🔍 Duplicate Code Detected: ClientInfo/ServerInfo Record Pattern

Analysis of commit 78e6371

Assignee: @copilot

Summary

Identical ClientInfo and ServerInfo record definitions are duplicated across the production code and sample/test integration code. These records share the exact same structure (Name and Version properties) but are defined in different namespaces, leading to maintenance burden and potential inconsistencies.

Duplication Details

Pattern: ClientInfo/ServerInfo Records

  • Severity: Medium

  • Occurrences: 4 distinct definitions (2 pairs)

  • Locations:

    • src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/RpcMessages.cs (lines 62, 66)
      • internal sealed record ClientInfo(string Name, string Version);
      • internal sealed record ServerInfo(string Name, string Version);
    • samples/Playground/ServerMode/v1.0.0/ClientInfo.cs (lines 8-13)
      • public sealed record ClientInfo([property:JsonProperty("name")] string Name, [property:JsonProperty("version")] string Version = "1.0.0");
    • samples/Playground/ServerMode/v1.0.0/ServerInfo.cs (lines 8-13)
      • public sealed record ServerInfo([property:JsonProperty("name")] string Name, [property:JsonProperty("version")] string Version = "1.0.0");
  • Code Sample:

// Production version (RpcMessages.cs)
internal sealed record ClientInfo(string Name, string Version);
internal sealed record ServerInfo(string Name, string Version);

// Sample/Test version (separate files)
public sealed record ClientInfo(
    [property:JsonProperty("name")]
    string Name,
    [property:JsonProperty("version")]
    string Version = "1.0.0");

Impact Analysis

  • Maintainability: Changes to the info record structure require updates in multiple locations across production and test code
  • Bug Risk: The sample/test versions have default values and JSON property attributes that the production versions lack, creating potential behavioral differences
  • Code Bloat: ~40 lines of duplicated record definitions that could be consolidated
  • Type Safety: Different namespaces prevent compile-time detection of structural mismatches between production and test code

Refactoring Recommendations

  1. Create Shared Contract Assembly

    • Extract to: src/Platform/Microsoft.Testing.Platform.Contracts/ServerMode/InfoRecords.cs
    • Make records public and add appropriate JSON serialization attributes
    • Reference from both production code and samples
    • Estimated effort: 2-3 hours
    • Benefits: Single source of truth, consistent serialization behavior, reduced duplication
  2. Alternative: Use Internal Visible To

    • Keep records in RpcMessages.cs as internal
    • Add [assembly: InternalsVisibleTo("samples.Playground")] to expose to samples
    • Update sample code to reference the production types
    • Estimated effort: 1 hour
    • Benefits: No new assembly, immediate consolidation
    • Drawbacks: Tighter coupling between production and samples

Implementation Checklist

  • Review duplication findings
  • Decide between shared contract assembly vs InternalsVisibleTo approach
  • Create refactoring plan
  • Consolidate ClientInfo and ServerInfo records
  • Update all references in samples and tests
  • Verify JSON serialization works consistently
  • Ensure no functionality broken
  • Update related Capabilities records if following same pattern

Analysis Metadata

  • Analyzed Files: 6 source files across src/Platform and samples/
  • Detection Method: Semantic code analysis with grep pattern matching
  • Commit: 78e6371
  • Analysis Date: 2026-05-24T05:30:57Z

Generated by Duplicate Code Detector · ● 1.4M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/duplicate-code-detector.md@main
  • expires on May 26, 2026, 5:36 AM UTC

Metadata

Metadata

Labels

type/automationCreated or maintained by an agentic workflow.type/tech-debtCode health, refactoring, simplification.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions