Deduplicate JUnit report filename validation#8949
Merged
Evangelink merged 2 commits intoJun 9, 2026
Merged
Conversation
7 tasks
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix duplicate code in JUnitReportGeneratorCommandLine
Deduplicate JUnit report filename validation
Jun 9, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns the JUnit report extension’s command-line filename/path validation with the shared ReportFileNameValidator helper (already used by HTML/TRX), reducing drift and ensuring future fixes—especially around path safety checks—apply consistently across report generators.
Changes:
- Refactored
JUnitReportGeneratorCommandLineto delegate filename and option cross-validation toMicrosoft.Testing.Extensions.ReportFileNameValidator. - Linked
SharedExtensionHelpers/ReportFileNameValidator.csinto the JUnit report extension project to reuse the shared implementation. - Added focused unit tests validating JUnit filename/path rules and option dependency/discovery-mode constraints.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj | Adds a project reference to the JUnit report extension so its command-line provider can be exercised by unit tests. |
| test/UnitTests/Microsoft.Testing.Extensions.UnitTests/JUnitReportGeneratorCommandLineTests.cs | New unit tests covering JUnit report filename validation and command-line option cross-validation behaviors. |
| src/Platform/Microsoft.Testing.Extensions.JUnitReport/Microsoft.Testing.Extensions.JUnitReport.csproj | Links the shared ReportFileNameValidator helper into the JUnit extension to match HTML/TRX structure. |
| src/Platform/Microsoft.Testing.Extensions.JUnitReport/JUnitReportGeneratorCommandLine.cs | Replaces local validation logic with calls into the shared ReportFileNameValidator. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The JUnit report command-line provider had drift-prone copies of the shared report filename/path validation logic, unlike the HTML and TRX providers which already delegate to
ReportFileNameValidator. This change aligns JUnit with the shared validation path so future fixes and security-sensitive path checks apply consistently across report generators.Refactor JUnit command-line validation
--report-junit-filenamevalidation withReportFileNameValidator.ValidateReportFileNameArgumentAsync(...)ReportFileNameValidator.ValidateReportCommandLineOptionsAsync(...)Remove duplicated path-validation logic
DirectorySeparatorsEscapesResultsDirectoryIsPathFullyQualifiedWire JUnit into shared helpers
src/Platform/SharedExtensionHelpers/ReportFileNameValidator.csintoMicrosoft.Testing.Extensions.JUnitReport.csprojAdd focused JUnit command-line coverage
JUnitReportGeneratorCommandLineTestsExample of the simplification: