Repository navigation
Description
🔍 Duplicate Code Detected: IsReparsePoint helper
Analysis of commit c2592c9 (recent history including #10542, #10543, #10548)
Assignee: @copilot
Summary
An identical private helper method IsReparsePoint(string path) is copy-pasted verbatim into four separate IArtifactPostProcessor implementations. Each copy has the same body: call File.GetAttributes, check the ReparsePoint flag, and return true on IOException/UnauthorizedAccessException.
Duplication Details
Pattern: Reparse-point detection helper
- Severity: Medium
- Occurrences: 4
- Locations:
src/Platform/Microsoft.Testing.Extensions.JUnitReport/JUnitArtifactPostProcessor.cs(lines 135-145)src/Platform/Microsoft.Testing.Extensions.CtrfReport/CtrfArtifactPostProcessor.cs(lines 84-94)src/Platform/Microsoft.Testing.Extensions.HtmlReport/HtmlArtifactPostProcessor.cs(lines 128-138)src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxArtifactPostProcessor.cs(lines 101-111)
- Code Sample:
private static bool IsReparsePoint(string path) { try { return (File.GetAttributes(path) & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint; } catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) { return true; } }
Related: the JUnit, Ctrf, Html, and Trx processors also duplicate near-identical OrderBy(input => Path.GetFullPath(input.Path), StringComparer.Ordinal) ordering logic for InputArtifact collections, reinforcing that these processors share common merge-preparation plumbing that isn't yet centralized.
Impact Analysis
- Maintainability: Any future fix (e.g., handling additional exception types, supporting symlinks vs. junctions differently, or adding logging) requires editing 4 files in lockstep. It's easy to update one and forget the others, which is exactly the failure mode copy-paste duplication causes.
- Bug Risk: Because the logic silently treats any IO error as "is a reparse point" (fail-safe to skip merging), a bug fix or behavior change applied to only one copy creates inconsistent behavior across report formats (JUnit, CTRF, HTML, TRX) for the same underlying scenario (merged output directory being a symlink/junction).
- Code Bloat: ~40 lines of identical code across the repo for a single-purpose utility.
Refactoring Recommendations
-
Extract to a shared internal utility
- Move
IsReparsePointinto a shared location consumable by all artifact post-processors, e.g. a new internal helper inMicrosoft.Testing.Extensions.Reporting(already referenced by AzureDevOpsReport/GitHubActionsReport) or a small linked shared.csfile included via project items in JUnit/Ctrf/Html/Trx projects (which don't currently referenceReporting). - Estimated effort: 1-2 hours
- Benefits: Single place to fix/extend reparse-point detection logic; removes ~40 duplicated lines; consistent behavior across all report formats.
- Move
-
Consider extracting the shared ordering expression too
- The
OrderBy(input => Path.GetFullPath(input.Path), StringComparer.Ordinal)(with further.ThenBychains for JUnit/HTML) is repeated across JUnit, Ctrf, Html, and Trx processors. A shared static helper (e.g.,OrderInputsByPath(IEnumerable<InputArtifact> inputs)) alongside the reparse-point helper would consolidate both patterns in one pass. - Estimated effort: 1 hour
- Benefits: Further reduces duplication and centralizes ordering semantics used for deterministic merge IDs.
- The
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan (shared helper location + project reference wiring)
- Implement changes
- Update tests (unit tests for JUnit/Ctrf/Html/Trx post-processors)
- Verify no functionality broken (run affected unit/integration test suites)
Analysis Metadata
- Analyzed Files: 7 (JUnit, Ctrf, AzureDevOps, GitHubActions, Html, Trx artifact post-processors, plus IArtifactPostProcessor interface)
- Detection Method: Semantic code analysis (grep + manual review) across recent commits
- Commit: c2592c9
- Analysis Date: 2026-08-17
🤖 Automated content by GitHub Copilot. Generated by the Duplicate Code Detector workflow. · auto · 47.5 AIC · ⌖ 2.2 AIC · ⊞ 12.9K · [◷]( · ◷)
Add this agentic workflow to your repo
To install this agentic workflow, run
gh aw add githubnext/agentics/workflows/duplicate-code-detector.md@main
- expires on Aug 19, 2026, 4:27 AM UTC
Activity