Skip to content

Refactor ServerTestHost into focused partial-class files#8865

Merged
Evangelink merged 6 commits into
mainfrom
copilot/file-diet-refactor-server-test-host
Jun 7, 2026
Merged

Refactor ServerTestHost into focused partial-class files#8865
Evangelink merged 6 commits into
mainfrom
copilot/file-diet-refactor-server-test-host

Conversation

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

ServerTestHost.cs had grown into a large mixed-responsibility file, making the server host flow harder to navigate. This change splits the existing partial type by concern so lifecycle, inbound RPC handling, request execution, and outbound messaging each live in a dedicated file.

  • What changed

    • Kept ServerTestHost.cs focused on host lifecycle and core state:
      • fields
      • constructor
      • identity properties
      • initialization guard
      • InternalRunAsync
      • Dispose
      • unhandled exception hooks
    • Extracted inbound RPC processing to ServerTestHost.MessageLoop.cs:
      • HandleMessagesAsync
      • HandleNotificationAsync
      • HandleRequestAsync
      • CompleteRequest
      • RpcInvocationState
    • Extracted request execution and telemetry shaping to ServerTestHost.RequestExecution.cs:
      • HandleRequestCoreAsync
      • per-request execution pipeline
      • discovery/run metric builders
    • Extracted outbound RPC/message helpers to ServerTestHost.Messaging.cs:
      • responses/errors
      • test updates
      • telemetry updates
      • pushed server log messages
  • Behavioral note

    • Preserves the existing ServerTestHost surface area and call paths while reducing file size and isolating responsibilities.
    • Corrects the cancellation warning path so warnings are emitted only when request cancellation itself throws.
  • Example split

    // ServerTestHost.MessageLoop.cs
    private async Task HandleMessagesAsync(CancellationToken cancellationToken) { ... }
    
    // ServerTestHost.RequestExecution.cs
    private async Task<object> HandleRequestCoreAsync(RequestMessage message, RpcInvocationState rpcInvocationState, CancellationToken cancellationToken) { ... }
    
    // ServerTestHost.Messaging.cs
    private async Task SendMessageAsync(string method, object? @params, CancellationToken cancellationToken, bool checkServerExit = false, bool rethrowException = true) { ... }

Copilot AI requested review from Copilot and removed request for Copilot June 5, 2026 19:31
Copilot AI linked an issue Jun 5, 2026 that may be closed by this pull request
6 tasks
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 5, 2026 19:43
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 5, 2026 19:43
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 5, 2026 19:47
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 5, 2026 19:56
Copilot AI changed the title [WIP] Refactor ServerTestHost.cs into focused partial-class files Refactor ServerTestHost into focused partial-class files Jun 5, 2026
Copilot AI requested a review from Evangelink June 5, 2026 19:57
@Evangelink Evangelink marked this pull request as ready for review June 6, 2026 14:17
Copilot AI review requested due to automatic review settings June 6, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 ServerTestHost (Microsoft.Testing.Platform server-mode host) by splitting the existing partial type into multiple concern-focused files, keeping the lifecycle/core state in ServerTestHost.cs while moving message-loop/RPC handling, request execution, and outbound messaging into dedicated partial-class files. It also fixes the cancellation-warning logic so warnings are emitted only when request-cancellation itself throws.

Changes:

  • Split inbound JSON-RPC reading/dispatch and request tracking into ServerTestHost.MessageLoop.cs.
  • Split request execution + telemetry metric shaping into ServerTestHost.RequestExecution.cs.
  • Split outbound JSON-RPC response/notification helpers into ServerTestHost.Messaging.cs, keeping ServerTestHost.cs focused on lifecycle and core state.
Show a summary per file
File Description
src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs Removes message-loop, request execution, and messaging helpers to keep the main file focused on lifecycle/core state.
src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.MessageLoop.cs New partial file containing the main message loop, inbound notification/request handling, and per-request cancellation state.
src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.RequestExecution.cs New partial file containing request execution pipeline and telemetry metric builders for discovery/run.
src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.Messaging.cs New partial file containing outbound responses/errors and pushed notifications (test updates, telemetry, logs).

Copilot's findings

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink Evangelink merged commit afe6647 into main Jun 7, 2026
33 checks passed
@Evangelink Evangelink deleted the copilot/file-diet-refactor-server-test-host branch June 7, 2026 11:06
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.

[file-diet] Refactor ServerTestHost.cs into focused partial-class files (795 lines)

3 participants