Skip to content

[code-simplifier] Deduplicate option-name collection in CommandLineOptionsValidator #10820

Description

@github-actions

This PR simplifies code recently added in PR #10798 ("Improve unknown command-line option guidance") to remove duplicated logic while preserving all functionality.

Files Simplified

  • src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs - Extracted duplicated logic into a shared helper

Improvements Made

  1. Reduced Duplication

    • ValidateNoUnknownOptions contained two nearly identical foreach loops — one iterating extensionOptionsByProvider and one iterating systemOptionsByProvider — both populating validOptionNames and visibleOptionNames in exactly the same way.
    • Extracted this shared logic into a new private static helper, CollectOptionNames(optionsByProvider, validOptionNames, visibleOptionNames), and call it twice instead of duplicating the loop body.
  2. Enhanced Clarity

    • ValidateNoUnknownOptions is now shorter and its intent (aggregate valid/visible option names from two provider sources) is clearer at a glance.

Changes Based On

Recent changes from:

Testing

  • ./build.sh -c Debug succeeded with 0 warnings / 0 errors
  • dotnet test test/UnitTests/Microsoft.Testing.Platform.UnitTests -f net8.0 --filter "FullyQualifiedName~CommandLineHandlerTests" — 69/69 passed
  • ✅ No functional changes — behavior is identical (pure extract-method refactor)

Review Focus

Please verify:

  • Functionality is preserved (pure mechanical extraction, no logic change)
  • The new helper name/signature fits existing conventions
  • No unintended side effects

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • southcentralus0.in.applicationinsights.azure.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "southcentralus0.in.applicationinsights.azure.com"

See Network Configuration for more information.

🤖 Automated content by GitHub Copilot. Generated by the Code Simplifier workflow. · auto · 99.4 AIC · ⌖ 3.97 AIC · ⊞ 14.1K · [◷]( · )

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/code-simplifier.md@main
  • expires on Aug 28, 2026, 5:00 PM UTC

Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch code-simplifier/dedup-collect-option-names-ee5b9e3c009573bf.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (81 of 81 lines)
From 55be8d1f46c44dd075e0c5a4eea324df3c20299b Mon Sep 17 00:00:00 2001
X-GH-AW-Base-Commit: 7361f3d0eceb63eef61cec52b090612080ce87c7
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Thu, 27 Aug 2026 16:58:30 +0000
Subject: [PATCH] Deduplicate option-name collection in
 CommandLineOptionsValidator

Extract the two identical foreach loops in ValidateNoUnknownOptions
(over extensionOptionsByProvider and systemOptionsByProvider) into a
shared CollectOptionNames helper to remove duplicated logic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 ...Validator.UnknownAndBootstrapValidation.cs | 43 +++++++++----------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs
index 51a6f9e..722482f 100644
--- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs
+++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs
@@ -122,29 +122,8 @@ private static ValidationResult ValidateNoUnknownOptions(
         var validOptionNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
         var visibleOptionNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
         bool includeKnownExtensionOptions = !parseResult.HasTool;
-        foreach (KeyValuePair<ICommandLineOptionsProvider, IReadOnlyCollection<CommandLineOption>> provider in extensionOptionsByProvider)
-        {
-            foreach (CommandLineOption option in provider.Value)
-            {
-                validOptionNames.Add(option.Name);
-                if (!option.IsHidden)
-                {
-                    visibleOptionNames.Add(option.Name);
-                }
-            }
-       
... (truncated)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions