Overview
The file src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs has grown to 1,157 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.
Current State
- File:
src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs
- Size: 1,157 lines
- Language: C#
Structural Analysis
VsTestConsoleRequestSender is a single internal class implementing ITranslationLayerRequestSender, responsible for the entire client-side protocol handshake and request/response cycle with vstest.console.exe. It mixes several distinct concerns:
- Communication lifecycle:
InitializeCommunicationAsync, InitializeExtensions, HandShakeWithVsTestConsoleAsync, OnProcessExited, Close, EndSession, Dispose.
- Discovery API surface: sync/async overloads of
DiscoverTests/DiscoverTestsAsync.
- Execution API surface: multiple sync/async overloads of
StartTestRun, StartTestRunAsync, StartTestRunWithCustomHost, StartTestRunWithCustomHostAsync, plus CancelTestRun, AbortTestRun, CancelDiscovery.
- Attachments processing API:
ProcessTestRunAttachmentsAsync.
- Message loop / event-report plumbing (largest and most repetitive part):
SendMessageAndListenAndReportTestCases(Async), SendMessageAndListenAndReportTestResults(Async), SendMessageAndListenAndReportAttachmentsProcessingResultAsync, TryReceiveMessageAsync.
- Debugger/custom host + telemetry helpers:
HandleCustomHostLaunch, AttachDebuggerToProcess, HandleTelemetryEvent.
These groups are logically separable and largely operate on the shared _communicationManager/_dataSerializer fields via the same class, which is a good candidate for partial class decomposition without changing the public API.
Refactoring Strategy
Proposed File Splits
Use partial class VsTestConsoleRequestSender across files to preserve the single public type while splitting responsibilities:
-
VsTestConsoleRequestSender.cs (retained, trimmed)
- Contents: fields, constructors,
InitializeCommunicationAsync, InitializeExtensions, HandShakeWithVsTestConsoleAsync, OnProcessExited, Close, EndSession, Dispose
- Responsibility: communication lifecycle and object construction/teardown
-
VsTestConsoleRequestSender.Discovery.cs
- Contents:
DiscoverTests, DiscoverTestsAsync, CancelDiscovery, SendMessageAndListenAndReportTestCases, SendMessageAndListenAndReportTestCasesAsync
- Responsibility: test discovery request/response handling
-
VsTestConsoleRequestSender.Execution.cs
- Contents: all
StartTestRun/StartTestRunAsync/StartTestRunWithCustomHost(Async) overloads, CancelTestRun, AbortTestRun, SendMessageAndListenAndReportTestResults, SendMessageAndListenAndReportTestResultsAsync
- Responsibility: test execution request/response handling
-
VsTestConsoleRequestSender.Attachments.cs
- Contents:
ProcessTestRunAttachmentsAsync, SendMessageAndListenAndReportAttachmentsProcessingResultAsync
- Responsibility: attachments post-processing protocol handling
-
VsTestConsoleRequestSender.CustomHost.cs
- Contents:
HandleCustomHostLaunch, AttachDebuggerToProcess, HandleTelemetryEvent, TryReceiveMessageAsync
- Responsibility: custom test host launch/debugger attach and telemetry event handling shared by discovery/execution paths
Implementation Guidelines
- Preserve Behavior: All existing functionality must work identically after the split
- Maintain Public API: Keep exported/public symbols accessible with the same names (the class stays
VsTestConsoleRequestSender, split via partial class)
- Update Imports: Fix all import paths throughout the codebase
- Test After Each Split: Run the test suite after each incremental change
- One File at a Time: Split one module at a time to make review easier
Acceptance Criteria
Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts
Generated by Daily File Diet · copilot · auto · 30.9 AIC · ⌖ 9.14 AIC · ⊞ 13K · ◷
Overview
The file
src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cshas grown to 1,157 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.Current State
src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.csStructural Analysis
VsTestConsoleRequestSenderis a singleinternalclass implementingITranslationLayerRequestSender, responsible for the entire client-side protocol handshake and request/response cycle withvstest.console.exe. It mixes several distinct concerns:InitializeCommunicationAsync,InitializeExtensions,HandShakeWithVsTestConsoleAsync,OnProcessExited,Close,EndSession,Dispose.DiscoverTests/DiscoverTestsAsync.StartTestRun,StartTestRunAsync,StartTestRunWithCustomHost,StartTestRunWithCustomHostAsync, plusCancelTestRun,AbortTestRun,CancelDiscovery.ProcessTestRunAttachmentsAsync.SendMessageAndListenAndReportTestCases(Async),SendMessageAndListenAndReportTestResults(Async),SendMessageAndListenAndReportAttachmentsProcessingResultAsync,TryReceiveMessageAsync.HandleCustomHostLaunch,AttachDebuggerToProcess,HandleTelemetryEvent.These groups are logically separable and largely operate on the shared
_communicationManager/_dataSerializerfields via the same class, which is a good candidate forpartial classdecomposition without changing the public API.Refactoring Strategy
Proposed File Splits
Use
partial class VsTestConsoleRequestSenderacross files to preserve the single public type while splitting responsibilities:VsTestConsoleRequestSender.cs(retained, trimmed)InitializeCommunicationAsync,InitializeExtensions,HandShakeWithVsTestConsoleAsync,OnProcessExited,Close,EndSession,DisposeVsTestConsoleRequestSender.Discovery.csDiscoverTests,DiscoverTestsAsync,CancelDiscovery,SendMessageAndListenAndReportTestCases,SendMessageAndListenAndReportTestCasesAsyncVsTestConsoleRequestSender.Execution.csStartTestRun/StartTestRunAsync/StartTestRunWithCustomHost(Async)overloads,CancelTestRun,AbortTestRun,SendMessageAndListenAndReportTestResults,SendMessageAndListenAndReportTestResultsAsyncVsTestConsoleRequestSender.Attachments.csProcessTestRunAttachmentsAsync,SendMessageAndListenAndReportAttachmentsProcessingResultAsyncVsTestConsoleRequestSender.CustomHost.csHandleCustomHostLaunch,AttachDebuggerToProcess,HandleTelemetryEvent,TryReceiveMessageAsyncImplementation Guidelines
VsTestConsoleRequestSender, split viapartial class)Acceptance Criteria
Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts