Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[duplicate-code] Duplicate `HasDuplicateModuleIdentity` logic between AzureDevOps and GitHub Actions reporters

Chiusa
#12,000 0 commenti 1 reazione 2 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Evangelink ci sta già lavorando.

Dal 18/10/2026.

  • #12005 di @copilot-swe-agent — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

type/automation type/tech-debt

Summary

The exact same module-identity-collision check is duplicated byte-for-byte between the Azure DevOps and GitHub Actions CI summary reporters, each operating on the already-shared CiRunSummaryModule type (src/Platform/SharedExtensionHelpers/CiRunSummaryModels.cs). The repo already has a precedent for extracting this kind of cross-reporter logic into src/Platform/SharedExtensionHelpers — see CiRunSummaryExitCode (added in #11970) which consolidated near-identical exit-code logic from GitHubActionsExitCode for reuse by the Azure DevOps reporter.

Duplication Details

Pattern: Identical HasDuplicateModuleIdentity private method
  • Severity: Medium
  • Occurrences: 2 (each called from 2–3 call sites within its own file, so the logic effectively has multiple internal users per project)
  • Locations:
    • src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsSummaryReporter.Markdown.cs (lines 547-551), called from lines 466 and 528
    • src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/GitHubActionsSummaryReporter.Markdown.Aggregate.cs (lines 197-201), called from line 122
  • Code Sample:
    private static bool HasDuplicateModuleIdentity(IReadOnlyList<CiRunSummaryModule> modules, CiRunSummaryModule module)
        => modules.Count(candidate =>
            string.Equals(candidate.AssemblyName, module.AssemblyName, StringComparison.Ordinal)
            && string.Equals(candidate.TargetFramework, module.TargetFramework, StringComparison.Ordinal)
            && string.Equals(candidate.Architecture, module.Architecture, StringComparison.OrdinalIgnoreCase)) > 1;
    
    Both copies are identical character-for-character (verified with diff).

Impact Analysis

  • Maintainability: Any future change to how module identity collisions are detected (e.g. adding a new discriminator field, changing comparison semantics) must be made in two places; it is easy to update one and forget the other, causing the two CI report flavors to silently disagree on when module attempt/session discriminators are shown.
  • Bug Risk: Because both copies currently operate on the shared CiRunSummaryModule type with no reporter-specific variation, there is no reason for behavior to diverge — any divergence introduced later would be an unintentional bug rather than a deliberate design choice.
  • Code Bloat: Small (5 lines each), but it sets a precedent of re-deriving shared CI-summary logic per reporter instead of consolidating it, which compounds as more reporters (e.g. future CI providers) are added.

Refactoring Recommendations

  1. Move HasDuplicateModuleIdentity into src/Platform/SharedExtensionHelpers
    • Add it as a new internal static method (e.g. a ModuleIdentity or CiRunSummaryModuleIdentity helper class, or append to the existing CiRunSummaryAggregation.cs since it already operates on CiRunSummaryModule/CiRunSummaryAggregate).
    • Mirror the pattern used for CiRunSummaryExitCode (added in #11970): a single implementation guarded by #pragma warning disable RS0051 since the helper compiles into multiple extension assemblies.
    • Update both AzureDevOpsSummaryReporter.Markdown.cs and GitHubActionsSummaryReporter.Markdown.Aggregate.cs to call the shared helper instead of their private copies.
    • Estimated effort: low (under an hour); purely mechanical extraction with no behavior change.
    • Benefits: single source of truth for module-identity-collision detection; consistent with the existing CiRunSummaryExitCode precedent; removes duplicate code that must otherwise be kept in sync manually.

Implementation Checklist

  • Review duplication findings
  • Extract HasDuplicateModuleIdentity into src/Platform/SharedExtensionHelpers
  • Update both reporters to call the shared helper
  • Remove the two private copies
  • Verify existing AzureDevOps and GitHub Actions summary reporter unit tests still pass unchanged (behavior-preserving refactor)

Analysis Metadata

  • Analyzed Files: Recent commits touching src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/ and src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/ (commits around 88788a9eb, 95c503f07, 73a403f7f, e51893b06)
  • Detection Method: Semantic code analysis + exact diff comparison
  • Commit: e51893b06f6a5c6faa3a702a8e9d78cd93c35ce9

🤖 Automated content by GitHub Copilot. Generated by the Duplicate Code Detector workflow. · copilot · auto · 123.1 AIC · ⌖ 6.64 AIC · ⊞ 13.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 Oct 20, 2026, 4:31 AM UTC
Lingua principale
C#
Stelle
1.1k
Fork
312
Merge medio
8h 29m
PR unite (30g)
421

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/testfx

Tutte le issue di microsoft/testfx

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.