Overview
The file src/Adapter/MSTestAdapter.PlatformServices/Execution/TestDependencyGraph.cs has grown to 967 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/TestDependencyGraph.cs
- Size: 967 lines
- Language: C#
Structural Analysis
The file contains a single internal sealed class TestDependencyGraph that handles multiple distinct algorithmic responsibilities:
-
Edge resolution (ResolveEdges, ~lines 236–340): Resolves [DependsOn] attributes into a prerequisite index array, matching test names to indices and emitting warnings for unresolved dependencies.
-
Cycle detection (FindCycles, FindCyclePathWithin, ~lines 341–512): Tarjan/DFS-based strongly-connected-component analysis and per-test cycle message generation. ~170 lines of pure graph algorithms.
-
Sequential set computation (ComputeSequentialSet, PropagateSequential, ~lines 513–588): Marks which tests must be moved to the sequential phase and propagates that flag through the prerequisite graph.
-
Chunk building (BuildChunks, BuildChunkArrays, HasChunkCycle, FindChunksOnCycle, ~lines 589–881): Projects test-level edges onto scheduling chunks, builds chunk prerequisite arrays, detects and recovers from class-level projection cycles. ~290 lines of the heaviest logic.
-
Topological ordering & utilities (OrderTopologically, SelectIndices, ~lines 882–967): Kahn's algorithm topological sort and a small index-selection helper.
-
Data/model (BrokenTest nested class, properties, constructor, ~lines 28–133): The public surface — constructor, properties, and the BrokenTest nested record-like class.
Refactoring Strategy
Proposed File Splits
Based on the file's structure, split it into the following modules:
-
TestDependencyGraph.cs (data + entry point, ~120 lines)
- Contents: constructor, public properties,
BrokenTest nested class, Build factory method
- Responsibility: Public API surface and data holder; delegates all computation to the helpers below
-
TestDependencyGraph.EdgeResolution.cs (partial class, ~120 lines)
- Contents:
ResolveEdges
- Responsibility: Translates
[DependsOn] attribute strings into prerequisite index arrays
-
TestDependencyGraph.CycleDetection.cs (partial class, ~175 lines)
- Contents:
FindCycles, FindCyclePathWithin
- Responsibility: SCC/DFS cycle detection and per-test cycle message generation
-
TestDependencyGraph.SequentialSet.cs (partial class, ~80 lines)
- Contents:
ComputeSequentialSet, PropagateSequential
- Responsibility: Determines which tests must run in the sequential phase
-
TestDependencyGraph.ChunkBuilding.cs (partial class, ~300 lines)
- Contents:
BuildChunks, BuildChunkArrays, HasChunkCycle, FindChunksOnCycle
- Responsibility: Projects test-level edges onto scheduling chunks and recovers from chunk-level cycles
-
TestDependencyGraph.Ordering.cs (partial class, ~90 lines)
- Contents:
OrderTopologically, SelectIndices
- Responsibility: Kahn's topological sort and index-selection utilities
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 (all members are
internal, so partial class is the natural vehicle)
- Use
partial class: All split files should declare internal sealed partial class TestDependencyGraph in the same namespace — no new types needed
- Test After Each Split: Run the test suite after each incremental move (
./build.sh -test or the targeted unit-test project)
- One File at a Time: Move one logical group at a time to make review easier
Acceptance Criteria
Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier testing of individual algorithm phases, reduced merge conflicts when the dependency-graph feature evolves
🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · sonnet46 30.5 AIC · ⌖ 5.81 AIC · ⊞ 8K · [◷]( · ◷)
Overview
The file
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestDependencyGraph.cshas grown to 967 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.Current State
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestDependencyGraph.csStructural Analysis
The file contains a single
internal sealed class TestDependencyGraphthat handles multiple distinct algorithmic responsibilities:Edge resolution (
ResolveEdges, ~lines 236–340): Resolves[DependsOn]attributes into a prerequisite index array, matching test names to indices and emitting warnings for unresolved dependencies.Cycle detection (
FindCycles,FindCyclePathWithin, ~lines 341–512): Tarjan/DFS-based strongly-connected-component analysis and per-test cycle message generation. ~170 lines of pure graph algorithms.Sequential set computation (
ComputeSequentialSet,PropagateSequential, ~lines 513–588): Marks which tests must be moved to the sequential phase and propagates that flag through the prerequisite graph.Chunk building (
BuildChunks,BuildChunkArrays,HasChunkCycle,FindChunksOnCycle, ~lines 589–881): Projects test-level edges onto scheduling chunks, builds chunk prerequisite arrays, detects and recovers from class-level projection cycles. ~290 lines of the heaviest logic.Topological ordering & utilities (
OrderTopologically,SelectIndices, ~lines 882–967): Kahn's algorithm topological sort and a small index-selection helper.Data/model (
BrokenTestnested class, properties, constructor, ~lines 28–133): The public surface — constructor, properties, and theBrokenTestnested record-like class.Refactoring Strategy
Proposed File Splits
Based on the file's structure, split it into the following modules:
TestDependencyGraph.cs(data + entry point, ~120 lines)BrokenTestnested class,Buildfactory methodTestDependencyGraph.EdgeResolution.cs(partial class, ~120 lines)ResolveEdges[DependsOn]attribute strings into prerequisite index arraysTestDependencyGraph.CycleDetection.cs(partial class, ~175 lines)FindCycles,FindCyclePathWithinTestDependencyGraph.SequentialSet.cs(partial class, ~80 lines)ComputeSequentialSet,PropagateSequentialTestDependencyGraph.ChunkBuilding.cs(partial class, ~300 lines)BuildChunks,BuildChunkArrays,HasChunkCycle,FindChunksOnCycleTestDependencyGraph.Ordering.cs(partial class, ~90 lines)OrderTopologically,SelectIndicesImplementation Guidelines
internal, sopartial classis the natural vehicle)partial class: All split files should declareinternal sealed partial class TestDependencyGraphin the same namespace — no new types needed./build.sh -testor the targeted unit-test project)Acceptance Criteria
./build.sh -test)internalAPIpartialkeyword is added to the class declaration in every split filePriority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier testing of individual algorithm phases, reduced merge conflicts when the dependency-graph feature evolves