🔍 Duplicate Code Detected: TRX Report Command Line Validation Pattern
Analysis of commit 6d6e32d
Assignee: @copilot
Summary
TrxReportGeneratorCommandLine manually implements two validation methods (ValidateOptionArgumentsAsync and ValidateCommandLineOptionsAsync) by directly calling ReportFileNameValidator helpers. The base class ReportGeneratorCommandLineBase was specifically designed to encapsulate this exact pattern, and three other report generators (CTRF, HTML, JUnit) already extend it — but TRX does not.
Duplication Details
Pattern: Report validation logic implemented inline instead of via base class
- Severity: Medium
- Occurrences: 4 implementations — 1 inline (TRX), 3 using base class (CTRF, HTML, JUnit)
- Locations:
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCommandLine.cs (lines 31–46) — inline duplicate
src/Platform/SharedExtensionHelpers/ReportGeneratorCommandLineBase.cs — base class with identical abstracted logic
src/Platform/Microsoft.Testing.Extensions.CtrfReport/CtrfReportGeneratorCommandLine.cs — correct pattern
src/Platform/Microsoft.Testing.Extensions.HtmlReport/HtmlReportGeneratorCommandLine.cs — correct pattern
src/Platform/Microsoft.Testing.Extensions.JUnitReport/JUnitReportGeneratorCommandLine.cs — correct pattern
- Code Sample (current TRX inline implementation):
// TrxCommandLine.cs - manual duplication
public override Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments)
=> commandOption.Name == TrxReportFileNameOptionName
? ReportFileNameValidator.ValidateReportFileNameArgumentAsync(
arguments,
".trx",
ExtensionResources.TrxReportFileNameMustNotBeEmpty,
ExtensionResources.TrxReportFileNameExtensionIsNotTrx,
ExtensionResources.TrxReportFileNameRelativePathMustStayUnderResultsDirectory)
: ValidationResult.ValidTask;
public override Task<ValidationResult> ValidateCommandLineOptionsAsync(ICommandLineOptions commandLineOptions)
=> ReportFileNameValidator.ValidateReportCommandLineOptionsAsync(
commandLineOptions,
TrxReportOptionName,
TrxReportFileNameOptionName,
ExtensionResources.TrxReportFileNameRequiresTrxReport,
ExtensionResources.TrxReportIsNotValidForDiscovery,
PlatformCommandLineProvider.DiscoverTestsOptionKey);
- Code Sample (correct CTRF pattern):
// CtrfReportGeneratorCommandLine.cs - extends base class
internal sealed class CtrfReportGeneratorCommandLine : ReportGeneratorCommandLineBase
{
public CtrfReportGeneratorCommandLine()
: base(
nameof(CtrfReportGeneratorCommandLine),
ExtensionResources.CtrfReportGeneratorDisplayName,
ExtensionResources.CtrfReportGeneratorDescription,
CtrfReportOptionName,
CtrfReportFileNameOptionName,
/* ... resource strings ... */
".json",
/* ... more resource strings ... */)
{ }
}
Impact Analysis
- Maintainability: Any future change to the shared
ReportFileNameValidator calling convention or new validation logic in ReportGeneratorCommandLineBase must be manually replicated in TRX as well. Other report generators benefit automatically.
- Bug Risk: A fix applied to validation logic via the base class silently misses TRX. This is especially risky for security- or correctness-related validation changes.
- Code Bloat: 17 extra lines in
TrxCommandLine.cs that add no unique logic.
Refactoring Recommendations
- Extend
ReportGeneratorCommandLineBase in TrxReportGeneratorCommandLine
- Change
TrxReportGeneratorCommandLine to extend ReportGeneratorCommandLineBase instead of CommandLineOptionsProviderBase
- Move the hardcoded strings (
.trx, resource keys) to constructor arguments
- Remove the
ValidateOptionArgumentsAsync and ValidateCommandLineOptionsAsync override methods entirely
- Target file:
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCommandLine.cs
- Estimated effort: < 1 hour
- Benefits: Consistent validation behavior with all other report generators; future validation improvements automatically apply to TRX
Implementation Checklist
Analysis Metadata
- Analyzed Files: 5
- Detection Method: Semantic code analysis — base class pattern mismatch
- Commit: 6d6e32d
- Analysis Date: 2026-06-16
🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Duplicate Code Detector workflow. · 951.6 AIC · ⌖ 25.8 AIC · [◷]( · ◷)
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: TRX Report Command Line Validation Pattern
Analysis of commit 6d6e32d
Assignee:
@copilotSummary
TrxReportGeneratorCommandLinemanually implements two validation methods (ValidateOptionArgumentsAsyncandValidateCommandLineOptionsAsync) by directly callingReportFileNameValidatorhelpers. The base classReportGeneratorCommandLineBasewas specifically designed to encapsulate this exact pattern, and three other report generators (CTRF, HTML, JUnit) already extend it — but TRX does not.Duplication Details
Pattern: Report validation logic implemented inline instead of via base class
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCommandLine.cs(lines 31–46) — inline duplicatesrc/Platform/SharedExtensionHelpers/ReportGeneratorCommandLineBase.cs— base class with identical abstracted logicsrc/Platform/Microsoft.Testing.Extensions.CtrfReport/CtrfReportGeneratorCommandLine.cs— correct patternsrc/Platform/Microsoft.Testing.Extensions.HtmlReport/HtmlReportGeneratorCommandLine.cs— correct patternsrc/Platform/Microsoft.Testing.Extensions.JUnitReport/JUnitReportGeneratorCommandLine.cs— correct patternImpact Analysis
ReportFileNameValidatorcalling convention or new validation logic inReportGeneratorCommandLineBasemust be manually replicated in TRX as well. Other report generators benefit automatically.TrxCommandLine.csthat add no unique logic.Refactoring Recommendations
ReportGeneratorCommandLineBaseinTrxReportGeneratorCommandLineTrxReportGeneratorCommandLineto extendReportGeneratorCommandLineBaseinstead ofCommandLineOptionsProviderBase.trx, resource keys) to constructor argumentsValidateOptionArgumentsAsyncandValidateCommandLineOptionsAsyncoverride methods entirelysrc/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCommandLine.csImplementation Checklist
TrxReportGeneratorCommandLineto extendReportGeneratorCommandLineBaseValidateOptionArgumentsAsyncandValidateCommandLineOptionsAsyncoverridesAnalysis Metadata
Add this agentic workflows to your repo
To install this agentic workflow, run