Skip to content

[file-diet] Refactor TestRequestManager.cs (1569 lines) into smaller focused files #16339

Description

@github-actions

Overview

The file src/vstest.console/TestPlatformHelpers/TestRequestManager.cs has grown to 1569 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.

Note: The two larger files in the repo (Jsonite.cs at 1726 lines and SimpleJSON.cs at 1391 lines) are vendored third-party libraries and are excluded from this analysis.

Current State

  • File: src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
  • Size: 1569 lines
  • Language: C#
Structural Analysis

The file contains a single internal class TestRequestManager plus a small internal static class KnownPlatformSourceFilter at the bottom. The class handles:

  1. Public request lifecycleInitializeExtensions, ResetOptions, DiscoverTests, RunTests, ProcessTestRunAttachments, plus cancellation/abort/dispose methods (lines ~167–560).
  2. RunSettings mutationUpdateRunSettingsIfRequired and ~15 private helpers that each patch a specific XML node: UpdateTargetDevice, UpdateDesignMode, UpdatePlatform, UpdateFrameworkInRunSettingsIfRequired, AddOrUpdateBatchSize, UpdateCollectSourceInformation, AddFakesConfigurationToRunsettings, UpdateCollectCoverageSettings, etc. (lines ~563–1143).
  3. Logger managementAddOrUpdateBuiltInLoggers, AddConsoleLogger, UpdateConsoleLoggerIfExists, UpdateMSBuildLoggerIfExists (lines ~808–1144).
  4. Telemetry & diagnosticsCollectMetrics, LogTelemetryForLegacySettings, LogCommandsTelemetryPoints, IsTelemetryOptedIn (lines ~486–507, ~1275–1461).
  5. Source-compatibility checksCheckSourcesForCompatibility, WriteWarningForNetFramework35IsUnsupported, KnownPlatformSourceFilter (lines ~921–1569).

Refactoring Strategy

Proposed File Splits

  1. TestRequestManager.cs (core — kept, trimmed)

    • Contents: constructor, InitializeExtensions, ResetOptions, DiscoverTests, RunTests, ProcessTestRunAttachments, cancellation helpers, Dispose
    • Responsibility: Orchestrates test discovery, execution, and attachments processing
  2. TestRequestManager.RunSettings.cs (partial class)

    • Contents: UpdateRunSettingsIfRequired and all private XML-patch helpers (UpdateTargetDevice, UpdateDesignMode, UpdatePlatform, UpdateFrameworkInRunSettingsIfRequired, AddOrUpdateBatchSize, UpdateCollectSourceInformation, UpdateIsTargetPlatformInferred, AddFakesConfigurationToRunsettings, UpdateCollectCoverageSettings)
    • Responsibility: Mutates run-settings XML before dispatching a request
  3. TestRequestManager.Loggers.cs (partial class)

    • Contents: AddOrUpdateBuiltInLoggers, AddConsoleLogger, UpdateConsoleLoggerIfExists, UpdateMSBuildLoggerIfExists
    • Responsibility: Injects and updates built-in loggers in run-settings
  4. TestRequestManager.Telemetry.cs (partial class)

    • Contents: CollectMetrics, LogTelemetryForLegacySettings, LogCommandsTelemetryPoints, IsTelemetryOptedIn
    • Responsibility: Collects and emits telemetry/diagnostics data
  5. KnownPlatformSourceFilter.cs (separate file)

    • Contents: internal static class KnownPlatformSourceFilter with KnownPlatformSources set and FilterKnownPlatformSources
    • Responsibility: Filters well-known platform assemblies from test source lists

Implementation Guidelines

  1. Preserve Behavior: All existing functionality must work identically after the split
  2. Maintain Public API: TestRequestManager is internal — use partial class so callers are unaffected
  3. Update Imports: Each new partial-class file needs its own using directives
  4. Test After Each Split: Run ./test.cmd after each incremental change
  5. One File at a Time: Split one partial at a time to make review easier

Acceptance Criteria

  • TestRequestManager.cs is split into partial-class files as described above
  • KnownPlatformSourceFilter lives in its own file
  • Each new file is under 400 lines
  • All tests pass after refactoring (./test.cmd)
  • No breaking changes to public API
  • All using directives are correctly distributed across the new files

Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier isolated testing of RunSettings logic, reduced merge conflicts in the orchestration core

Generated by Daily File Diet · 24 AIC · ⌖ 6.26 AIC · ⊞ 6.1K ·

  • expires on Aug 5, 2026, 11:46 PM UTC

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