[file-diet] Refactor TestMethodInfo.Execution.cs (574 lines) into focused files
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start with src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.Execution.cs and read the complete method bodies, then inspect the neighboring TestMethodInfo.*.cs partials and .github/skills/behavior-preserving-refactor/SKILL.md. Trace consumers, project includes, source links, and the NETFRAMEWORK conditional before moving code. Done means focused files stay under 300 lines where safe, behavior and API contracts are preserved, and affected builds and tests pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Overview
The file src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.Execution.cs has grown to 574 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.
Current State
- File:
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.Execution.cs - Size: 574 lines
- Language: C#
Structural Analysis
This file is already one of six partial class TestMethodInfo files in the Execution folder (alongside .ArgumentResolution.cs, .ExceptionHandling.cs, .Lifecycle.cs, .TestContext.cs, and .cs), so the project already follows a per-concern partial-class convention — this file itself has simply outgrown that convention and can be split further along the same lines.
From the bounded sample (first 100 lines + a member-signature grep), the file contains:
GetTestTimeout()— resolves the effectiveTimeoutAttribute/default timeout for a test method.ThrowMultipleAttributesException/ThrowMultipleClassAttributesException— small[DoesNotReturn]helpers that raiseTypeInspectionExceptionfor duplicate attribute usage.ExecuteInternalAsync(...)(lines ~77–336) — the large core method that orchestrates global/local test initialization, test invocation, and global/local cleanup.DefaultTestClassInstanceLease(lines ~336–363) — a private nestedsealed classimplementingITestClassInstanceLease.ExecuteInternalWithTimeoutAsync(...)(lines ~363–526) — the timeout-wrapping variant of execution.TestInvocationState(lines ~526–570) — a private nested class tracking activation/cleanup state (PublishActivation,CompleteTestContextSetup).TestInvocationCleanupSnapshot(line ~570+) — a private nestedreadonly record structcapturing cleanup snapshot data.
Refactoring Strategy
Proposed File Splits
Based on the bounded structural sample, investigate these proposed splits as provisional — the sample used for this issue did not read the full method bodies or verify consumer/test coupling, so their safety must be confirmed during implementation preflight before moving any code:
-
TestMethodInfo.Execution.cs(retained, trimmed)- Contents:
GetTestTimeout(),ThrowMultipleAttributesException,ThrowMultipleClassAttributesException, and the primaryExecuteInternalAsync(...)entry point. - Responsibility: Core non-timeout test execution orchestration and small attribute-validation helpers.
- Contents:
-
TestMethodInfo.Execution.Timeout.cs- Contents:
ExecuteInternalWithTimeoutAsync(...)and theTestInvocationStatenested class it uses to track invocation/cleanup state. - Responsibility: Timeout-bounded test execution path, isolated from the non-timeout path.
- Contents:
-
TestMethodInfo.Execution.Types.cs(if needed)- Contents:
DefaultTestClassInstanceLeaseandTestInvocationCleanupSnapshotnested types. - Responsibility: Small supporting types (lease/snapshot) shared by both execution paths, separated from the executable logic.
- 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 (e.g. the
#if NETFRAMEWORKblock at the top of the file), and tracked public/internal API surfaces. Keep names, accessibility, attributes, and native interop contracts unchanged. - 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 (following the existing
TestMethodInfo.*.cspartial-class convention) - 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 (including the
NETFRAMEWORK-conditional code path); 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: Medium
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts
🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · copilot · auto · 41 AIC · ⌖ 10.4 AIC · ⊞ 12.9K · [◷]( · ◷)
- expires on Oct 21, 2026, 7:02 PM UTC
- Lingua principale
- C#
- Stelle
- 1.1k
- Fork
- 312
- Merge medio
- 8h 25m
- PR unite (30g)
- 443
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à 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
type/automation type/tech-debt
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
type/automation type/tech-debt
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
area/dump needs/triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
microsoft/testfx#11981 · 2 commenti ·
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
Tutte le issue di microsoft/testfx
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
KnifeLemon/Filee#363 ·
I maintainer di solito rispondono entro 1 giorno
-
[CI] .trgen-ignore required for several grammars.Forse già presa @kaby76 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
antlr/grammars-v4#5073 ·
I maintainer di solito rispondono entro 1 giorno
-
/api/oauth/introspect emits clientId and tokenType instead of RFC 7662's client_id and token_typeApertabug P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nightscout/nocturne#2317 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG]: Position intent set on a simple order is dropped when it becomes a bracket, OCO or OTO orderForse già presa @RaphaelFakhri l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
alpacahq/alpaca-trade-api-csharp#903 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
joinrpg/joinrpg-net#5752 ·
I maintainer di solito rispondono entro 1 giorno