🔍 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
// 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
-
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
-
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
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
🔍 Duplicate Code Detected: ClientInfo/ServerInfo Record Pattern
Analysis of commit 78e6371
Assignee:
@copilotSummary
Identical
ClientInfoandServerInforecord 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:
Impact Analysis
Refactoring Recommendations
Create Shared Contract Assembly
src/Platform/Microsoft.Testing.Platform.Contracts/ServerMode/InfoRecords.csAlternative: Use Internal Visible To
RpcMessages.csas internal[assembly: InternalsVisibleTo("samples.Playground")]to expose to samplesImplementation Checklist
Analysis Metadata
Add this agentic workflows to your repo
To install this agentic workflow, run