Skip to content

Refactor duplicated command-line provider boilerplate into shared base class#8546

Merged
Evangelink merged 5 commits into
mainfrom
copilot/duplicate-code-command-line-provider
May 25, 2026
Merged

Refactor duplicated command-line provider boilerplate into shared base class#8546
Evangelink merged 5 commits into
mainfrom
copilot/duplicate-code-command-line-provider

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 25, 2026

Duplicate-code analysis identified repeated ICommandLineOptionsProvider scaffolding across diagnostic/extension providers, with identical metadata, enablement, option-caching, and default validation structure. This change extracts that shared structure and keeps provider-specific validation logic local.

  • What changed

    • Added CommandLineOptionsProviderBase in Microsoft.Testing.Platform to centralize:
      • extension metadata (Uid, Version, DisplayName, Description)
      • IsEnabledAsync() default behavior
      • cached GetCommandLineOptions()
      • default no-op validation methods
  • Provider migrations (behavior preserved)

    • Refactored:
      • HangDumpCommandLineProvider
      • CrashDumpCommandLineProvider
      • MSBuildCommandLineProvider
    • Each provider now passes static option definitions + metadata via base constructor and overrides only provider-specific validation.
  • Coverage for new abstraction

    • Added focused unit tests for CommandLineOptionsProviderBase defaults and constructor-supplied options surface.
internal sealed class HangDumpCommandLineProvider : CommandLineOptionsProviderBase
{
    public HangDumpCommandLineProvider()
        : base(
            nameof(HangDumpCommandLineProvider),
            ExtensionVersion.DefaultSemVer,
            ExtensionResources.HangDumpExtensionDisplayName,
            ExtensionResources.HangDumpExtensionDescription,
            CachedCommandLineOptions)
    {
    }

    public override Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments)
    {
        // HangDump-specific checks only
    }
}

Copilot AI requested review from Copilot and removed request for Copilot May 25, 2026 05:53
Copilot AI linked an issue May 25, 2026 that may be closed by this pull request
10 tasks
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 25, 2026 06:04
Copilot AI changed the title [WIP] Refactor duplicate CommandLineProvider boilerplate structure Refactor duplicated command-line provider boilerplate into shared base class May 25, 2026
Copilot AI requested a review from Evangelink May 25, 2026 06:05
@Evangelink Evangelink marked this pull request as ready for review May 25, 2026 08:49
Copilot AI review requested due to automatic review settings May 25, 2026 08:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 repeated ICommandLineOptionsProvider boilerplate across multiple Platform extensions into a shared CommandLineOptionsProviderBase abstraction within Microsoft.Testing.Platform, and adds unit tests to validate the new base defaults.

Changes:

  • Introduce CommandLineOptionsProviderBase to centralize provider metadata, enablement default, option caching, and default validation behavior.
  • Migrate HangDump, CrashDump, and MSBuild command-line providers to inherit from the new base class.
  • Add unit tests covering default base behavior and constructor-supplied options exposure.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineOptionsProviderBaseTests.cs Adds unit tests validating the new base class defaults and option passthrough.
src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsProviderBase.cs Introduces the shared base class for command-line option providers.
src/Platform/Microsoft.Testing.Extensions.MSBuild/MSBuildCommandLineProvider.cs Refactors MSBuild provider to use the shared base + cached options.
src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpCommandLineProvider.cs Refactors HangDump provider to use the shared base and override validation.
src/Platform/Microsoft.Testing.Extensions.CrashDump/CrashDumpCommandLineProvider.cs Refactors CrashDump provider to use the shared base and override validation.

Copilot's findings

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

Copilot AI review requested due to automatic review settings May 25, 2026 11:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 18/18 changed files
  • Comments generated: 2

@Evangelink Evangelink merged commit 634e9bd into main May 25, 2026
25 checks passed
@Evangelink Evangelink deleted the copilot/duplicate-code-command-line-provider branch May 25, 2026 12:31
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.

[duplicate-code] Duplicate Code: CommandLineProvider Boilerplate Structure

4 participants