Refactor TerminalTestReporter into focused partial class files#8138
Refactor TerminalTestReporter into focused partial class files#8138Copilot wants to merge 4 commits into
Conversation
Agent-Logs-Url: https://github.com/microsoft/testfx/sessions/a79a70e0-6bc9-452a-81b0-a0de3a11da70 Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
There was a problem hiding this comment.
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
Evangelink
left a comment
There was a problem hiding this comment.
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 intact —
test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cscontinues 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 🧪
Evangelink
left a comment
There was a problem hiding this comment.
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
TerminalTestReportertype; no members are missing or duplicated. - Threading — The double-checked locking pattern on
_testProgressState(_lockisSystem.Threading.Lockon .NET 9,objecton 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_GREATERguards aroundSystem.Buffers.SearchValues<char>and.AsSpan().IndexOfAny(...)are preserved correctly inTerminalTestReporter.Formatting.ControlCharacters.cs. All partial files build cleanly acrossnet462,netstandard2.0,net8.0, andnet9.0. - API shape — No public members added, removed, or renamed. All previously
internalmembers remaininternal.[UnsupportedOSPlatform("browser")]is now repeated on each of the 7 partial-class declarations; sinceAllowMultiple = truefor this attribute type, this is valid—the compiled metadata is correct and Roslyn CA1416 analysis is unaffected. - Resources —
IDisposabledelegation via_terminalWithProgress.Dispose()remains in the primary file. No new disposable objects are introduced withoutusing. - Performance —
MakeControlCharactersVisiblehot-path pre-checks viaSearchValues<char>(NET8+) /IndexOfAny(char[])(older) before allocating aStringBuilder, all preserved. A pre-existing double-enumeration of_artifactsviaGroupBy().Any()+foreachinAppendTestRunSummaryis 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>
TerminalTestReporter.cshad grown to ~1K lines, making navigation and localized changes costly. This PR restructures the existinginternal sealed partial class TerminalTestReporterinto focused partial files without changing behavior or API shape.Core class reduced to state + lifecycle entrypoints
TerminalTestReporter.cs(Dispose,StartCancelling,ArtifactAdded,PrintOutOfProcessArtifacts).Lifecycle flow isolated
TerminalTestReporter.Lifecycle.cs:TestExecutionStartedAssemblyRunStartedGetOrAddAssemblyRunAssemblyRunCompletedTestExecutionCompletedTest result processing isolated
TerminalTestReporter.TestCompletion.cs:TestCompletedoverloadsGetShowPassedTestsRenderTestCompletedSummary/discovery rendering isolated
TerminalTestReporter.Summary.cs:AppendTestRunSummaryAppendTestDiscoverySummaryTestDiscoveredFormatting helpers isolated
TerminalTestReporter.Formatting.cs.TerminalTestReporter.Formatting.ControlCharacters.csto keep file sizes focused and under the requested threshold.Messaging/progress updates isolated
TerminalTestReporter.Messaging.cs:WriteMessage,WriteErrorMessage,WriteWarningMessageTestInProgress