[file-diet] Refactor MtpServerClient.cs (581 lines) into focused partial files
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Overview
The file src/Platform/Microsoft.Testing.Platform.ServerMode.Client.Sources/Client/MtpServerClient.cs has grown to 581 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.
Current State
- File:
src/Platform/Microsoft.Testing.Platform.ServerMode.Client.Sources/Client/MtpServerClient.cs - Size: 581 lines
- Language: C#
Structural Analysis
MtpServerClient is the internal sealed class implementation of IMtpServerClient, a client over MtpJsonRpcConnection used to talk to an MTP server. Based on a bounded sample (first 100 lines plus a member-signature scan), it contains three distinguishable groups of responsibility:
- Construction / lifecycle: constructors,
Launch,LaunchAsync,LaunchInProcessAsync,InitializeAsync,Dispose,DetachHandlers,EnsureStarted— connecting to and tearing down the underlying transport/process. - Test execution:
DiscoverCoreAsync,RunCoreAsync,OnServerRequestAsync— sending discovery/run requests and handling server-initiated requests. - Event/notification plumbing:
OnNotificationReceived,RaiseTestNodesUpdated,RaiseLog,RaiseTelemetry,RaiseAttachments— translating raw JSON-RPC notifications into the publicTestNodesUpdated,LogReceived,TelemetryReceived,AttachmentsReceivedevents.
This file is internal sealed, which makes a partial class split across files a natural, low-risk option for a single-project source-included package (.Sources suffix suggests it is distributed as source, so public/internal surface for consumers outside this project must stay unchanged).
Refactoring Strategy
Proposed File Splits
Based on the bounded structural sample, investigate these proposed splits. Confirm their safety during implementation preflight before moving code — treat these as provisional until verified against the full file body, its callers, and existing tests:
-
MtpServerClient.cs(retained)- Contents: Class declaration, fields, constructors, public events, properties (
ServerRequestHandler,ProcessId,ServerExitCode,Capabilities),Launch/LaunchAsync/LaunchInProcessAsync/InitializeAsync,Dispose,DetachHandlers,EnsureStarted. - Responsibility: Client identity, connection lifecycle, and startup/teardown.
- Contents: Class declaration, fields, constructors, public events, properties (
-
MtpServerClient.Execution.cs(new partial)- Contents:
DiscoverCoreAsync,RunCoreAsync,OnServerRequestAsync. - Responsibility: Sending discovery/run requests to the server and responding to server-initiated requests.
- Contents:
-
MtpServerClient.Notifications.cs(new partial)- Contents:
OnNotificationReceived,RaiseTestNodesUpdated,RaiseLog,RaiseTelemetry,RaiseAttachments. - Responsibility: Deserializing JSON-RPC notification payloads and raising the corresponding public events.
- Contents:
Implementation Guidelines
- Establish Equivalence: Follow
.github/skills/behavior-preserving-refactor/SKILL.md. Before editing, read the complete affected bodies, inventory baseline behavior and relevant tests, and identify distinguishing cases. - Preserve Selection and Evaluation: Keep iteration order, short-circuit evaluation, exact type selection, first/last-match semantics, defaults, exceptions, and side effects. Cover reachable duplicate and malformed inputs; similar-looking helpers are not automatically interchangeable.
- Trace All Consumers: Check partial declarations, source-linked consumers, owning/consuming project includes, target-framework guards, and tracked public/internal API surfaces. Keep names, accessibility, attributes, and native interop contracts unchanged. Because this file lives under a
.Sourcesproject, verify how it is included (source link vs. compile item) by every consuming project and ensure all new partial files are included identically. - Move Before Modernizing: Move bodies unchanged first, one coherent responsibility at a time. Preserve allocation and performance behavior on hot paths; do not mix adjacent modernization or bug fixes into the split.
- Use Focused Checks: Run the smallest affected project/TFM builds and relevant tests before and after each coherent split. Add distinguishing equivalence cases where coverage is missing; a pure file move does not require the full solution. Report exact checks and outcomes, including unavailable checks.
- Surface Constraints: Measure resulting line counts. If a safe structural split cannot meet the size goal without changing semantics, report the remaining size and blocker rather than forcing behavior changes.
Acceptance Criteria
- Original file is split into focused modules
- Each new file is under 300 lines, or a concrete behavior-preservation blocker and remaining size are reported
- Baseline semantics, including reachable duplicate/malformed cases and evaluation order, are preserved by focused equivalence checks
- Relevant builds and tests pass for affected consumers/TFMs; exact checks and any validation gaps are reported
- Public and tracked internal API contracts, attributes, and conditional compilation are preserved
- Project includes, source links, and package layout still include the moved code for every affected consumer
Priority: Medium
Effort: Small
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts
🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · copilot · auto · 39.6 AIC · ⌖ 5.19 AIC · ⊞ 13K · [◷]( · ◷)
- expires on Oct 15, 2026, 7:01 PM UTC
- Lingua principale
- C#
- Stelle
- 1k
- Fork
- 314
- Merge medio
- 9h 30m
- PR unite (30g)
- 424
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/testfx
-
type/automation type/tech-debt
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
type/automation type/tech-debt
Difficoltà 5/5 Più di una settimana Idoneità per principianti 5/100
I maintainer di solito rispondono entro 1 giorno
-
[msbuild-quality] Test TitleForse già presa @YuliiaKovalova l’ha presa 1 giorno fa. Apertaarea/mtp-msbuild type/automation type/tech-debt
microsoft/testfx#11937 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[quality-improver] Browser/WASM Blocking-Wait Contract Compliance: FileLoggerProvider.Dispose() IsBrowser() branch still blocksForse già presa @Evangelink l’ha presa 1 giorno fa. Apertatype/automation type/tech-debt
Difficoltà 3/5 Mezza giornata Idoneità per principianti 45/100
microsoft/testfx#11934 · 1 reazione · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
-
[file-diet] Refactor oversized NamedPipeServer.cs (565 lines) into focused filesForse già presa @Evangelink l’ha presa 1 giorno fa. Apertatype/automation type/tech-debt
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
microsoft/testfx#11933 · 1 reazione · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/testfx
Issue simili
-
S: Untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Trauma-Station/Trauma-Station#5058 ·
I maintainer di solito rispondono entro 1 giorno
-
:books: documentation untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue hacktoberfest
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
good first issue help wanted ready-for-human
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno