Skip to content

[duplicate-code] IsReparsePoint helper duplicated identically across 4 ArtifactPostProcessor classes #10580

Closed as not planned

Description

@github-actions

Assignee: @copilot

Summary

The private static helper IsReparsePoint(string path) is duplicated byte-for-byte across four IArtifactPostProcessor implementations. Each copy is ~11 lines with identical logic, catch clauses, and return values.

Duplication Details

Pattern: Reparse-point detection helper

  • Severity: Medium
  • Occurrences: 4 (introduced/touched most recently by commit a760075, "Consolidate reports across retry attempts (Consolidate reports across retry attempts #10542)")
  • Locations:
    • src/Platform/Microsoft.Testing.Extensions.CtrfReport/CtrfArtifactPostProcessor.cs (lines 84-95)
    • src/Platform/Microsoft.Testing.Extensions.HtmlReport/HtmlArtifactPostProcessor.cs (lines 128-139, approx.)
    • src/Platform/Microsoft.Testing.Extensions.JUnitReport/JUnitArtifactPostProcessor.cs (lines 135-145)
    • src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxArtifactPostProcessor.cs (lines 101-111, approx.)
  • 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;
        }
    }

Note: TrxReportEngine.Merge.PathHelpers.cs has a related, but not identical, single-expression variant (IsReparsePoint without try/catch) used for a different ancestor-walking check — that one is a separate, lower-priority overlap and is out of scope for this issue.

Impact Analysis

  • Maintainability: Any future change to reparse-point handling (e.g., additional exception types, logging, or Windows/Unix-specific tweaks) must be applied in 4 places; it's easy to update 3 and miss one.
  • Bug Risk: Because the logic conservatively treats I/O errors as "is a reparse point" (fail-safe), a fix to that safety behavior in one copy could silently diverge from the others if not mirrored everywhere.
  • Code Bloat: ~40 duplicated lines across the report-extension projects for a single-purpose utility.

Refactoring Recommendations

  1. Extract to a shared internal helper
    • Since Microsoft.Testing.Platform.Extensions.ArtifactPostProcessing (in src/Platform/Microsoft.Testing.Platform) already defines the shared IArtifactPostProcessor/ArtifactPostProcessingContext abstractions consumed by all four processors, add a shared internal static helper there (e.g., ArtifactPostProcessingPathHelper.IsReparsePoint(string path)) and have each processor call it instead of maintaining its own private copy.
    • Estimated effort: ~1 hour (small, low-risk refactor + rebuild/test).
    • Benefits: single source of truth for reparse-point detection semantics; removes ~30 duplicated lines; consistent behavior guaranteed by construction.

Implementation Checklist

  • Review duplication findings
  • Add shared internal helper in Microsoft.Testing.Platform (or another already-shared internals-visible-to project)
  • Replace the 4 private IsReparsePoint copies with calls to the shared helper
  • Update InternalAPI.Unshipped.txt if the shared surface changes any public/internal API tracked there
  • Verify no functional behavior changes (existing unit/acceptance tests for the four post-processors should still pass unmodified)

Analysis Metadata

  • Analyzed Files: JUnitArtifactPostProcessor.cs, CtrfArtifactPostProcessor.cs, HtmlArtifactPostProcessor.cs, TrxArtifactPostProcessor.cs, JUnitReportMerger.cs, CtrfReportMerger.RetryCollapsing.cs, TrxReportEngine.Merge.PathHelpers.cs
  • Detection Method: Semantic code analysis of files touched by recent commits, cross-referenced against sibling extension projects
  • Commit: c2592c9 (HEAD); duplication originates from a760075

🤖 Automated content by GitHub Copilot. Generated by the Duplicate Code Detector workflow. · auto · 45.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 15, 2026, 4:47 AM UTC

Activity

  1. github-actions commented on Aug 15, 2026

    @github-actions
    ContributorAuthor

    This issue was automatically closed because it expired on 2026-08-15T04:47:16.122Z.

    Closed by Workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/automationCreated or maintained by an agentic workflow.type/tech-debtCode health, refactoring, simplification.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions