Repository navigation
Closed
Labels
type/automationCreated or maintained by an agentic workflow.type/tech-debtCode health, refactoring, simplification.
Description
🔍 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 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 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
ReportFileNameValidatorcalling convention or new validation logic inReportGeneratorCommandLineBasemust 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.csthat add no unique logic.
Refactoring Recommendations
- Extend
ReportGeneratorCommandLineBaseinTrxReportGeneratorCommandLine- Change
TrxReportGeneratorCommandLineto extendReportGeneratorCommandLineBaseinstead ofCommandLineOptionsProviderBase - Move the hardcoded strings (
.trx, resource keys) to constructor arguments - Remove the
ValidateOptionArgumentsAsyncandValidateCommandLineOptionsAsyncoverride 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
- Change
Implementation Checklist
- Review duplication findings
- Change
TrxReportGeneratorCommandLineto extendReportGeneratorCommandLineBase - Remove redundant
ValidateOptionArgumentsAsyncandValidateCommandLineOptionsAsyncoverrides - Verify existing TRX tests still pass
- Verify no functionality broken
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
- expires on Jun 18, 2026, 6:16 AM UTC
Reacted by Copilot
Metadata
Metadata
Assignees
Labels
type/automationCreated or maintained by an agentic workflow.type/tech-debtCode health, refactoring, simplification.
Activity
Copilot commentedon Jun 16, 2026
The agent encountered an error and was unable to start working on this issue: Please try again later, or contact support if the problem persists. (Request id: 1E40:359358:54B53:13D987:6A30EA59)