Skip to content

Remove duplicate file-naming utilities from CtrfReportEngine in favor of SharedExtensionHelpers#9307

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/duplicate-code-fix-ctrfreportengine
Open

Remove duplicate file-naming utilities from CtrfReportEngine in favor of SharedExtensionHelpers#9307
Copilot wants to merge 2 commits into
mainfrom
copilot/duplicate-code-fix-ctrfreportengine

Conversation

Copilot AI commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

CtrfReportEngine.FileNaming.cs contained private reimplementations of three utilities already shared across JUnit/HTML/TRX report engines, including an acknowledgment comment that the duplication was a maintenance risk.

Changes

  • .csproj: Link ReportFileNameSanitizer.cs, ReportFileNameHelper.cs, and TargetFrameworkMonikerHelper.cs from SharedExtensionHelpers (mirrors what JUnitReport and HtmlReport already do)

  • CtrfReportEngine.FileNaming.cs:

    • GetTargetFrameworkMoniker()TargetFrameworkMonikerHelper.GetTargetFrameworkMoniker()
    • ResolveJsonFileName() body → ReportFileNameHelper.ResolveAndSanitize() (eliminates manual template-resolve + sanitize reimplementation)
    • ReplaceInvalidFileNameChars() + IsInvalidFileNameChar() + IsReservedFileName() (~50 lines) → single delegation to ReportFileNameSanitizer.ReplaceInvalidFileNameChars()
  • ReportFileNameSanitizationConsistencyTests.cs: Added TrxAndCtrfReportEngines_UseSameFileNameSanitizationRules to cover CTRF in the cross-engine sanitization parity checks

// Before: private reimplementations with a comment admitting alignment risk
private static string GetTargetFrameworkMoniker()
    => TargetFrameworkParser.GetShortTargetFrameworkIncludingPlatform(Assembly.GetEntryAssembly()) ?? "unknown";
// "Keep the explicit file-name sanitization aligned with TRX report naming"
private static bool IsInvalidFileNameChar(char c) => ...
private static bool IsReservedFileName(string fileName) { /* 15 lines */ }

// After: delegate to shared helpers
private string ResolveJsonFileName(string template)
    => ReportFileNameHelper.ResolveAndSanitize(template, processName, processId, _clock.UtcNow);

private static string ReplaceInvalidFileNameChars(string fileName)
    => ReportFileNameSanitizer.ReplaceInvalidFileNameChars(fileName);

Copilot AI requested review from Copilot and removed request for Copilot June 21, 2026 06:00
…haredExtensionHelpers

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 21, 2026 06:08
Copilot AI changed the title [WIP] Remove duplicate file-naming utilities from CtrfReportEngine Remove duplicate file-naming utilities from CtrfReportEngine in favor of SharedExtensionHelpers Jun 21, 2026
Copilot AI requested a review from Evangelink June 21, 2026 06:08
@Evangelink Evangelink marked this pull request as ready for review June 21, 2026 07:21
Copilot AI review requested due to automatic review settings June 21, 2026 07:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes duplicated CTRF report file-naming/sanitization logic by delegating to the existing SharedExtensionHelpers utilities already used by the JUnit/HTML/TRX report engines, and extends the cross-engine parity unit tests to include CTRF.

Changes:

  • Linked ReportFileNameHelper, ReportFileNameSanitizer, and TargetFrameworkMonikerHelper into the CTRF extension project.
  • Updated CtrfReportEngine.FileNaming.cs to delegate TFM resolution, template resolution + sanitization, and filename sanitization to the shared helpers.
  • Added a new unit test to ensure CTRF and TRX use identical filename sanitization rules.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/ReportFileNameSanitizationConsistencyTests.cs Adds CTRF to the existing TRX-vs-other-engine sanitization parity checks via reflection.
src/Platform/Microsoft.Testing.Extensions.CtrfReport/Microsoft.Testing.Extensions.CtrfReport.csproj Links shared file-naming/sanitization/TFM helper sources from SharedExtensionHelpers.
src/Platform/Microsoft.Testing.Extensions.CtrfReport/CtrfReportEngine.FileNaming.cs Replaces local implementations with calls to shared helper utilities for consistency and maintenance.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

@Evangelink Evangelink enabled auto-merge (squash) June 21, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants