Skip to content

Refactor TerminalTestReporter into focused partial class files#8138

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/refactor-terminal-test-reporter
Open

Refactor TerminalTestReporter into focused partial class files#8138
Copilot wants to merge 4 commits into
mainfrom
copilot/refactor-terminal-test-reporter

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

TerminalTestReporter.cs had grown to ~1K lines, making navigation and localized changes costly. This PR restructures the existing internal sealed partial class TerminalTestReporter into focused partial files without changing behavior or API shape.

  • Core class reduced to state + lifecycle entrypoints

    • Kept fields, constructor, events, and lightweight public lifecycle/state methods in TerminalTestReporter.cs (Dispose, StartCancelling, ArtifactAdded, PrintOutOfProcessArtifacts).
  • Lifecycle flow isolated

    • Moved run/session orchestration into TerminalTestReporter.Lifecycle.cs:
      • TestExecutionStarted
      • AssemblyRunStarted
      • GetOrAddAssemblyRun
      • AssemblyRunCompleted
      • TestExecutionCompleted
  • Test result processing isolated

    • Moved completion pipeline into TerminalTestReporter.TestCompletion.cs:
      • TestCompleted overloads
      • GetShowPassedTests
      • RenderTestCompleted
  • Summary/discovery rendering isolated

    • Moved summary logic into TerminalTestReporter.Summary.cs:
      • AppendTestRunSummary
      • AppendTestDiscoverySummary
      • TestDiscovered
  • Formatting helpers isolated

    • Moved exception/output/stack formatting into TerminalTestReporter.Formatting.cs.
    • Moved control-character detection/normalization helpers into TerminalTestReporter.Formatting.ControlCharacters.cs to keep file sizes focused and under the requested threshold.
  • Messaging/progress updates isolated

    • Moved message and in-progress reporting into TerminalTestReporter.Messaging.cs:
      • WriteMessage, WriteErrorMessage, WriteWarningMessage
      • TestInProgress
// Example of the new focused partial organization:
internal sealed partial class TerminalTestReporter
{
    public void TestExecutionStarted(DateTimeOffset testStartTime, int workerCount, bool isDiscovery);
    internal void TestCompleted(...);
    private static void FormatStackTrace(ITerminal terminal, FlatException[] exceptions, int index);
    internal void WriteWarningMessage(string text, int? padding);
}

Copilot AI requested review from Copilot and removed request for Copilot May 11, 2026 22:31
Copilot AI requested review from Copilot and removed request for Copilot May 11, 2026 22:41
Copilot AI changed the title [WIP] Refactor split TerminalTestReporter.cs into focused partial class files Refactor TerminalTestReporter into focused partial class files May 11, 2026
Copilot AI requested a review from Evangelink May 11, 2026 22:42
Copilot AI review requested due to automatic review settings May 12, 2026 07:52
@Evangelink Evangelink marked this pull request as ready for review May 12, 2026 07:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors TerminalTestReporter by splitting the previously large implementation into multiple focused partial class files, improving navigability and making future localized edits easier while preserving existing behavior and API surface.

Changes:

  • Extracted lifecycle orchestration (run/session start/end) into TerminalTestReporter.Lifecycle.cs.
  • Isolated test completion rendering/pipeline into TerminalTestReporter.TestCompletion.cs.
  • Separated summary/discovery, messaging/progress updates, and formatting (including control-character handling) into dedicated partial files.
Show a summary per file
File Description
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs Reduced core file to shared state, ctor, and a small set of lifecycle/state entrypoints.
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.Lifecycle.cs Contains test execution/session lifecycle orchestration and progress start/stop integration.
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.TestCompletion.cs Contains test completion pipeline and per-test rendering logic.
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.Summary.cs Contains run/discovery summary rendering and discovery bookkeeping.
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.Messaging.cs Contains message printing helpers and in-progress test tracking updates.
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.Formatting.cs Contains stack/error/output formatting helpers used by reporting.
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.Formatting.ControlCharacters.cs Contains control-character detection/normalization used to keep terminal output robust.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 1

Copy link
Copy Markdown
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

Summary

Workflow: Test Expert Reviewer 🧪
Date: 2026-05-12
Repository: microsoft/testfx

Key Findings

  • No test file changes — all 7 changed files are production code under src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/. This is appropriate for a pure mechanical refactoring.
  • Existing test coverage intacttest/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs continues to cover the refactored code since no behavior or API was changed.
  • No new public API — partial class split preserves the same class surface; no new test-worthy branches or error paths were introduced.

Recommendations

No test changes required. The refactoring is purely structural (splitting one large file into focused partial class files), and the existing test suite exercises the same behaviors via the unchanged public/internal API.


Generated by Test Expert Reviewer

🧪 Test quality reviewed by Test Expert Reviewer 🧪

Copy link
Copy Markdown
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

Summary

Workflow: Expert Code Reviewer 🧠
Date: 2026-05-12
Repository: microsoft/testfx

Key Findings

No correctness, threading, performance, API, resource, or security issues were introduced by this PR. This is a faithful, line-for-line code move.

Verified:

  • Correctness — All moved methods are semantically identical to their originals. Partial class compilation correctly merges all declarations into one TerminalTestReporter type; no members are missing or duplicated.
  • Threading — The double-checked locking pattern on _testProgressState (_lock is System.Threading.Lock on .NET 9, object on older TFMs) is preserved unchanged. The protocol-ordered access semantics (write-before-parallel-reads, null-after-all-reads) are intact.
  • Cross-TFM#if NET8_0_OR_GREATER guards around System.Buffers.SearchValues<char> and .AsSpan().IndexOfAny(...) are preserved correctly in TerminalTestReporter.Formatting.ControlCharacters.cs. All partial files build cleanly across net462, netstandard2.0, net8.0, and net9.0.
  • API shape — No public members added, removed, or renamed. All previously internal members remain internal. [UnsupportedOSPlatform("browser")] is now repeated on each of the 7 partial-class declarations; since AllowMultiple = true for this attribute type, this is valid—the compiled metadata is correct and Roslyn CA1416 analysis is unaffected.
  • ResourcesIDisposable delegation via _terminalWithProgress.Dispose() remains in the primary file. No new disposable objects are introduced without using.
  • PerformanceMakeControlCharactersVisible hot-path pre-checks via SearchValues<char> (NET8+) / IndexOfAny(char[]) (older) before allocating a StringBuilder, all preserved. A pre-existing double-enumeration of _artifacts via GroupBy().Any() + foreach in AppendTestRunSummary is noted but was not introduced by this PR.

Recommendations

None required. The refactoring cleanly reduces a ~1K-line file into six focused files without altering behavior.


Generated by Expert Code Reviewer 🧠

🧠 Reviewed by Expert Code Reviewer 🧠

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 12, 2026 08:44
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.

Refactor: Split TerminalTestReporter.cs (990 lines) into focused partial class files

3 participants