Skip to content

[file-diet] Refactor VsTestConsoleRequestSender.cs (1,157 lines) into focused modules #16441

Description

@github-actions

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:

  1. VsTestConsoleRequestSender.cs (retained, trimmed)

    • Contents: fields, constructors, InitializeCommunicationAsync, InitializeExtensions, HandShakeWithVsTestConsoleAsync, OnProcessExited, Close, EndSession, Dispose
    • Responsibility: communication lifecycle and object construction/teardown
  2. VsTestConsoleRequestSender.Discovery.cs

    • Contents: DiscoverTests, DiscoverTestsAsync, CancelDiscovery, SendMessageAndListenAndReportTestCases, SendMessageAndListenAndReportTestCasesAsync
    • Responsibility: test discovery request/response handling
  3. VsTestConsoleRequestSender.Execution.cs

    • Contents: all StartTestRun/StartTestRunAsync/StartTestRunWithCustomHost(Async) overloads, CancelTestRun, AbortTestRun, SendMessageAndListenAndReportTestResults, SendMessageAndListenAndReportTestResultsAsync
    • Responsibility: test execution request/response handling
  4. VsTestConsoleRequestSender.Attachments.cs

    • Contents: ProcessTestRunAttachmentsAsync, SendMessageAndListenAndReportAttachmentsProcessingResultAsync
    • Responsibility: attachments post-processing protocol handling
  5. 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

  1. Preserve Behavior: All existing functionality must work identically after the split
  2. Maintain Public API: Keep exported/public symbols accessible with the same names (the class stays VsTestConsoleRequestSender, split via partial class)
  3. Update Imports: Fix all import paths throughout the codebase
  4. Test After Each Split: Run the test suite after each incremental change
  5. One File at a Time: Split one module at a time to make review easier

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

Generated by Daily File Diet · copilot · auto · 30.9 AIC · ⌖ 9.14 AIC · ⊞ 13K ·

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions