Skip to content

[file-diet] Refactor CiRunSummaryAggregation.cs (834 lines) into focused modules #10708

Description

@github-actions

Overview

The file src/Platform/SharedExtensionHelpers/CiRunSummaryAggregation.cs has grown to 834 lines, mixing several distinct concerns: data models, coverage summary computation/rendering, aggregation logic, and fragment file I/O. This makes it harder to navigate and maintain.

(Note: the repository's single largest source file, src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/XxHashShared.cs at 925 lines, is explicitly a verbatim port of dotnet/runtime's XxHashShared.cs and should not be restructured, since that would break the ability to diff/sync against upstream. This issue targets the next-largest file that is a genuine internal implementation.)

Current State

  • File: src/Platform/SharedExtensionHelpers/CiRunSummaryAggregation.cs
  • Size: 834 lines
  • Language: C#
Structural Analysis

The file currently contains:

  • Plain DTO/model classes: CiRunSummaryModule, CiRunSummaryTest, CiRunSummaryFailingClass, CiCoverageSummaryData, CiCoverageMetric, CiCoverageThreshold, CiRunSummaryAggregate, CiRunSummaryFragment.
  • CiCoverageSummary (static class, ~130 lines) — coverage aggregation and Markdown rendering (AppendMarkdown).
  • CiRunSummaryAggregation (static partial class, ~390 lines) — the core logic: CreateModule, WriteFragmentAsync, ValidateModule, private helpers WriteTextAsync/WriteAtomicAsync for atomic fragment file writes, plus the nested CiRunSummaryJsonContext JSON source-generation context.

Refactoring Strategy

Proposed File Splits

  1. CiRunSummaryModels.cs

    • Contents: CiRunSummaryModule, CiRunSummaryTest, CiRunSummaryFailingClass, CiCoverageSummaryData, CiCoverageMetric, CiCoverageThreshold, CiRunSummaryAggregate, CiRunSummaryFragment
    • Responsibility: Pure data-transfer objects with no behavior, used across the aggregation pipeline.
  2. CiCoverageSummary.cs

    • Contents: CiCoverageSummary static class (Aggregate, AppendMarkdown, and related private helpers)
    • Responsibility: Coverage-specific aggregation and Markdown report rendering, isolated from run/test summary logic.
  3. CiRunSummaryAggregation.cs (trimmed)

    • Contents: CiRunSummaryAggregation partial class — CreateModule, WriteFragmentAsync, ValidateModule
    • Responsibility: Core orchestration of building and validating a module summary from test records.
  4. CiRunSummaryFragmentIo.cs

    • Contents: WriteTextAsync, WriteAtomicAsync (as another partial of CiRunSummaryAggregation, or a small internal helper class), plus CiRunSummaryJsonContext
    • Responsibility: Atomic file I/O for writing fragment JSON to disk, decoupled from aggregation logic.

Implementation Guidelines

  1. Preserve Behavior: All existing functionality must work identically after the split.
  2. Maintain Public API: Keep exported/public and internal symbols accessible with the same names and namespace (Microsoft.Testing.Extensions).
  3. Update Imports: Fix all import paths/usages throughout the codebase that reference these types.
  4. Test After Each Split: Run the relevant unit/integration test suite after each incremental change.
  5. One File at a Time: Split one module at a time to make review easier — start with the DTOs (lowest risk), then coverage summary, then fragment I/O.

Acceptance Criteria

  • Original file is split into focused modules
  • Each new file is under 300 lines
  • All tests pass after refactoring
  • No breaking changes to public API
  • All import paths updated correctly

Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts

🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · auto · 32.6 AIC · ⌖ 2.86 AIC · ⊞ 11.4K · [◷]( · )

  • expires on Aug 26, 2026, 7:07 PM UTC

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