From f2324914f6069714956588d6da04d4463fc347e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 27 Aug 2026 13:00:38 +0200 Subject: [PATCH 1/9] Improve unknown command-line option guidance Suggest uniquely matching registered or known extension options and identify the package that auto-registers missing extension options. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f53849d1-b75f-4292-8452-9279531cc9ca --- ...Validator.UnknownAndBootstrapValidation.cs | 239 +++++++++++++++++- .../Resources/PlatformResources.resx | 8 + .../Resources/xlf/PlatformResources.cs.xlf | 10 + .../Resources/xlf/PlatformResources.de.xlf | 10 + .../Resources/xlf/PlatformResources.es.xlf | 10 + .../Resources/xlf/PlatformResources.fr.xlf | 10 + .../Resources/xlf/PlatformResources.it.xlf | 10 + .../Resources/xlf/PlatformResources.ja.xlf | 10 + .../Resources/xlf/PlatformResources.ko.xlf | 10 + .../Resources/xlf/PlatformResources.pl.xlf | 10 + .../Resources/xlf/PlatformResources.pt-BR.xlf | 10 + .../Resources/xlf/PlatformResources.ru.xlf | 10 + .../Resources/xlf/PlatformResources.tr.xlf | 10 + .../xlf/PlatformResources.zh-Hans.xlf | 10 + .../xlf/PlatformResources.zh-Hant.xlf | 10 + .../CommandLine/CommandLineHandlerTests.cs | 112 ++++++++ 16 files changed, 487 insertions(+), 2 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs index e1c88961765..70f49980c8f 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs @@ -10,6 +10,105 @@ namespace Microsoft.Testing.Platform.CommandLine; internal static partial class CommandLineOptionsValidator { + // Keep in sync with public command-line providers that are automatically registered by the listed packages. + // Packages without public options, options requiring explicit framework registration, and hidden internal options + // are intentionally omitted. + private static readonly Dictionary KnownExtensionOptionsByPackage = new(StringComparer.OrdinalIgnoreCase) + { + ["Microsoft.Testing.Extensions.AzureDevOpsReport"] = + [ + "publish-azdo-run-name", + "publish-azdo-test-results", + "report-azdo", + "report-azdo-annotations", + "report-azdo-demote-known-flaky", + "report-azdo-flaky-history", + "report-azdo-groups", + "report-azdo-quarantine-file", + "report-azdo-severity", + "report-azdo-slow-test-history", + "report-azdo-slow-test-history-min-sample", + "report-azdo-slow-test-history-multiplier", + "report-azdo-stackframe-filter", + "report-azdo-summary", + "report-azdo-upload-artifact-exclude", + "report-azdo-upload-artifact-include", + "report-azdo-upload-artifact-name", + "report-azdo-upload-artifacts", + ], + ["Microsoft.Testing.Extensions.CodeCoverage"] = + [ + "coverage", + "coverage-output", + "coverage-output-format", + "coverage-settings", + ], + ["Microsoft.Testing.Extensions.CrashDump"] = + [ + "crash-report", + "crash-report-if-supported", + "crash-sequence", + "crashdump", + "crashdump-filename", + "crashdump-type", + ], + ["Microsoft.Testing.Extensions.CtrfReport"] = + [ + "report-ctrf", + "report-ctrf-filename", + ], + ["Microsoft.Testing.Extensions.GitHubActionsReport"] = + [ + "report-gh", + "report-gh-annotations", + "report-gh-failure-details", + "report-gh-groups", + "report-gh-slow-test-notices", + "report-gh-slow-test-threshold", + "report-gh-step-summary", + "report-gh-step-summary-sections", + ], + ["Microsoft.Testing.Extensions.HangDump"] = + [ + "hangdump", + "hangdump-filename", + "hangdump-timeout", + "hangdump-type", + "hangdump-type-if-supported", + ], + ["Microsoft.Testing.Extensions.HtmlReport"] = + [ + "report-html", + "report-html-filename", + ], + ["Microsoft.Testing.Extensions.JUnitReport"] = + [ + "report-junit", + "report-junit-filename", + ], + ["Microsoft.Testing.Extensions.Retry"] = + [ + "retry-failed-tests", + "retry-failed-tests-delay", + "retry-failed-tests-max-percentage", + "retry-failed-tests-max-tests", + ], + ["Microsoft.Testing.Extensions.TrxReport"] = + [ + "report-trx", + "report-trx-filename", + ], + ["Microsoft.Testing.Extensions.VideoRecorder"] = + [ + "capture-video", + "capture-video-args", + "capture-video-chapters", + "capture-video-granularity", + "capture-video-max-duration", + "capture-video-source", + ], + }; + private static ValidationResult ValidateNoUnknownOptions( CommandLineParseResult parseResult, IReadOnlyList? jsonCommandLineOptions, @@ -21,11 +120,16 @@ private static ValidationResult ValidateNoUnknownOptions( // parsing is already case-sensitive but a case-insensitive lookup is a strict superset and // does not change CLI behavior. var validOptionNames = new HashSet(StringComparer.OrdinalIgnoreCase); + var visibleOptionNames = new HashSet(StringComparer.OrdinalIgnoreCase); foreach (KeyValuePair> provider in extensionOptionsByProvider) { foreach (CommandLineOption option in provider.Value) { validOptionNames.Add(option.Name); + if (!option.IsHidden) + { + visibleOptionNames.Add(option.Name); + } } } @@ -34,6 +138,10 @@ private static ValidationResult ValidateNoUnknownOptions( foreach (CommandLineOption option in provider.Value) { validOptionNames.Add(option.Name); + if (!option.IsHidden) + { + visibleOptionNames.Add(option.Name); + } } } @@ -43,7 +151,7 @@ private static ValidationResult ValidateNoUnknownOptions( if (!validOptionNames.Contains(optionRecord.Name)) { stringBuilder ??= new(); - stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineUnknownOption, optionRecord.Name)); + AppendUnknownOptionError(stringBuilder, optionRecord.Name, validOptionNames, visibleOptionNames); } } @@ -58,7 +166,9 @@ private static ValidationResult ValidateNoUnknownOptions( if (!validOptionNames.Contains(entry.OptionName)) { stringBuilder ??= new(); - string innerError = string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineUnknownOption, entry.OptionName); + StringBuilder innerErrorBuilder = new(); + AppendUnknownOptionError(innerErrorBuilder, entry.OptionName, validOptionNames, visibleOptionNames); + string innerError = innerErrorBuilder.ToTrimmedString(); stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.JsonCommandLineOptionsValidationErrorPrefix, innerError)); } } @@ -69,6 +179,131 @@ private static ValidationResult ValidateNoUnknownOptions( : ValidationResult.Valid(); } + private static void AppendUnknownOptionError( + StringBuilder stringBuilder, + string unknownOptionName, + HashSet validOptionNames, + HashSet visibleOptionNames) + { + stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineUnknownOption, unknownOptionName)); + + string? packageName = GetKnownExtensionPackage(unknownOptionName); + if (packageName is not null) + { + AppendMissingExtensionSuggestion(stringBuilder, unknownOptionName, packageName); + return; + } + + string? suggestedOptionName = FindSuggestedOption( + unknownOptionName, + visibleOptionNames.Concat(KnownExtensionOptionsByPackage.Values.SelectMany(static optionNames => optionNames))); + if (suggestedOptionName is null) + { + return; + } + + stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineOptionSuggestion, suggestedOptionName)); + + packageName = GetKnownExtensionPackage(suggestedOptionName); + if (packageName is not null && !validOptionNames.Contains(suggestedOptionName)) + { + AppendMissingExtensionSuggestion(stringBuilder, suggestedOptionName, packageName); + } + } + + private static void AppendMissingExtensionSuggestion(StringBuilder stringBuilder, string optionName, string packageName) + => stringBuilder.AppendLine(string.Format( + CultureInfo.InvariantCulture, + PlatformResources.CommandLineOptionRequiresExtension, + optionName, + packageName)); + + private static string? GetKnownExtensionPackage(string optionName) + { + foreach (KeyValuePair extensionOptions in KnownExtensionOptionsByPackage) + { + if (extensionOptions.Value.Contains(optionName, StringComparer.OrdinalIgnoreCase)) + { + return extensionOptions.Key; + } + } + + return null; + } + + private static string? FindSuggestedOption(string unknownOptionName, IEnumerable candidateOptionNames) + { + int maximumDistance = unknownOptionName.Length switch + { + <= 4 => 1, + <= 12 => 2, + _ => 3, + }; + + string? bestCandidate = null; + int bestDistance = maximumDistance + 1; + bool hasAmbiguousBestCandidate = false; + + foreach (string candidateOptionName in candidateOptionNames.Distinct(StringComparer.OrdinalIgnoreCase)) + { + if (Math.Abs(candidateOptionName.Length - unknownOptionName.Length) > maximumDistance) + { + continue; + } + + int distance = CalculateEditDistance(unknownOptionName, candidateOptionName); + if (distance < bestDistance) + { + bestCandidate = candidateOptionName; + bestDistance = distance; + hasAmbiguousBestCandidate = false; + } + else if (distance == bestDistance) + { + hasAmbiguousBestCandidate = true; + } + } + + return bestDistance <= maximumDistance && !hasAmbiguousBestCandidate + ? bestCandidate + : null; + } + + private static int CalculateEditDistance(string source, string target) + { + int[,] distances = new int[source.Length + 1, target.Length + 1]; + for (int i = 0; i <= source.Length; i++) + { + distances[i, 0] = i; + } + + for (int j = 0; j <= target.Length; j++) + { + distances[0, j] = j; + } + + for (int i = 1; i <= source.Length; i++) + { + for (int j = 1; j <= target.Length; j++) + { + int substitutionCost = char.ToUpperInvariant(source[i - 1]) == char.ToUpperInvariant(target[j - 1]) ? 0 : 1; + distances[i, j] = Math.Min( + Math.Min(distances[i - 1, j] + 1, distances[i, j - 1] + 1), + distances[i - 1, j - 1] + substitutionCost); + + if (i > 1 + && j > 1 + && char.ToUpperInvariant(source[i - 1]) == char.ToUpperInvariant(target[j - 2]) + && char.ToUpperInvariant(source[i - 2]) == char.ToUpperInvariant(target[j - 1])) + { + distances[i, j] = Math.Min(distances[i, j], distances[i - 2, j - 2] + 1); + } + } + } + + return distances[source.Length, target.Length]; + } + private static ValidationResult ValidateNoBootstrapOnlyOptionsInJson( IReadOnlyList? jsonCommandLineOptions) { diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index 07ae9a40f06..5bf31741fd6 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -467,6 +467,14 @@ Unknown option '--{0}' {0} is the unknown option name without the leading dashes. + + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Invalid command line arguments: diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf index 6636449f9b1..f626c6ae823 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -197,6 +197,16 @@ Možnost --{0} od zprostředkovatele {1} (UID: {2}) používá vyhrazenou předponu --internal. {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. Rozhraní ICommandLineOptions ještě není sestavené. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf index e8be502a3ce..24b5843dc2c 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -197,6 +197,16 @@ Die Option "--{0}" vom Anbieter "{1}" (UID: {2}) verwendet das reservierte Präfix "--internal". {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. ICommandLineOptions wurde noch nicht erstellt. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf index 3971a91d0f8..b91d266293c 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -197,6 +197,16 @@ La opción “--{0}” del proveedor “{1}” (UID: {2}) usa el prefijo reservado “--internal” {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. ICommandLineOptions aún no se ha compilado. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf index ac7c028a608..aa22f707864 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -197,6 +197,16 @@ L’option « --{0} » du fournisseur « {1} » (UID : {2}) utilise le préfixe réservé « --internal » {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. ICommandLineOptions n’a pas encore été généré. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf index a23af453c2d..b6d20eb572d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -197,6 +197,16 @@ L'opzione '--{0}' del provider '{1}' (UID: {2}) usa il prefisso riservato '--internal' {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. ICommandLineOptions non è stato ancora compilato. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf index 1320536e21d..e093e617028 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -197,6 +197,16 @@ プロバイダー '{1}' のオプション '--{0}' (UID:{2}) は予約済みプレフィックス '--internal' を 使用しています {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. ICommandLineOptions はまだ構築されていません。 diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf index 7f408e5631d..41751018e3d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -197,6 +197,16 @@ 공급자 '{1}'(UID: {2})의 옵션 '-- {0}'이 예약된 접두사 '--internal'을 사용하고 있습니다. {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. ICommandLineOptions가 아직 빌드되지 않았습니다. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf index 27e29bac8a0..5d0e274bc49 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -197,6 +197,16 @@ Opcja „--{0}” od dostawcy „{1}” (UID: {2}) używa zastrzeżonego prefiksu „--internal” {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. Obiekt ICommandLineOptions nie został jeszcze skompilowany. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf index 09a4849fcc8..33f17046106 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf @@ -197,6 +197,16 @@ A opção '--{0}' do provedor '{1}' (UID: {2}) está usando o prefixo reservado '--internal' {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. O ICommandLineOptions ainda não foi criado. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf index d7ccdc4db9d..ee4b91d7471 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -197,6 +197,16 @@ Параметр "--{0}" от поставщика "{1}" (UID: {2}) использует зарезервированный префикс "--internal" {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. Параметр ICommandLineOptions еще не создан. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf index 4ddfc53677b..b02858cffa0 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -197,6 +197,16 @@ '{1}' sağlayıcısındaki (UID: {2}) `--{0}` seçeneği ayrılmış '--internal' önekini kullanıyor {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. ICommandLineOptions henüz derlenmedi. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf index c7139927cbd..de76cfe16ae 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf @@ -197,6 +197,16 @@ 来自提供程序“{1}” (UID: {2}) 的选项“--{0}”正在使用保留前缀“--internal” {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. ICommandLineOptions 尚未生成。 diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf index c112d6f1437..a96d2bd9feb 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf @@ -197,6 +197,16 @@ 提供者 '{1}' (UID: {2}) 中的選項 '--{0}' 使用保留的前置詞 '--internal' {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + + + Did you mean '--{0}'? + Did you mean '--{0}'? + {0} is the suggested option name without the leading dashes. + The ICommandLineOptions has not been built yet. 尚未建置 ICommandLineOptions。 diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index bc5928d7050..cabc5412977 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -534,6 +534,118 @@ Unknown option '--x' """, result.ErrorMessage); } + [TestMethod] + public async Task ParseAndValidateAsync_UnknownOptionWithCloseRegisteredOption_SuggestsOption() + { + CommandLineParseResult parseResult = CommandLineParser.Parse(["--halp"], new SystemEnvironment()); + + ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( + parseResult, + _systemCommandLineOptionsProviders, + _extensionCommandLineOptionsProviders, + Mock.Of()); + + Assert.IsFalse(result.IsValid); + Assert.AreEqual( + """ + Unknown option '--halp' + Did you mean '--help'? + Command line: --halp + """, + result.ErrorMessage); + } + + [TestMethod] + public async Task ParseAndValidateAsync_UnknownOptionWithAmbiguousMatches_DoesNotSuggestOption() + { + CommandLineParseResult parseResult = CommandLineParser.Parse(["--ad"], new SystemEnvironment()); + ICommandLineOptionsProvider[] extensionCommandLineOptionsProviders = + [ + new ExtensionCommandLineProviderMockValidConfiguration("ab"), + new ExtensionCommandLineProviderMockValidConfiguration("ac"), + ]; + + ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( + parseResult, + _systemCommandLineOptionsProviders, + extensionCommandLineOptionsProviders, + Mock.Of()); + + Assert.IsFalse(result.IsValid); + Assert.Contains("Unknown option '--ad'", result.ErrorMessage); + Assert.DoesNotContain("Did you mean", result.ErrorMessage); + } + + [TestMethod] + [DataRow("--report-azdo", "Microsoft.Testing.Extensions.AzureDevOpsReport")] + [DataRow("--coverage-output-format", "Microsoft.Testing.Extensions.CodeCoverage")] + [DataRow("--crashdump-type", "Microsoft.Testing.Extensions.CrashDump")] + [DataRow("--report-ctrf", "Microsoft.Testing.Extensions.CtrfReport")] + [DataRow("--report-gh", "Microsoft.Testing.Extensions.GitHubActionsReport")] + [DataRow("--hangdump-timeout", "Microsoft.Testing.Extensions.HangDump")] + [DataRow("--report-html", "Microsoft.Testing.Extensions.HtmlReport")] + [DataRow("--report-junit", "Microsoft.Testing.Extensions.JUnitReport")] + [DataRow("--retry-failed-tests", "Microsoft.Testing.Extensions.Retry")] + [DataRow("--report-trx", "Microsoft.Testing.Extensions.TrxReport")] + [DataRow("--capture-video", "Microsoft.Testing.Extensions.VideoRecorder")] + public async Task ParseAndValidateAsync_KnownExtensionOptionWithoutExtension_SuggestsPackage(string option, string packageName) + { + CommandLineParseResult parseResult = CommandLineParser.Parse([option], new SystemEnvironment()); + + ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( + parseResult, + _systemCommandLineOptionsProviders, + _extensionCommandLineOptionsProviders, + Mock.Of()); + + Assert.IsFalse(result.IsValid); + Assert.Contains($"Unknown option '{option}'", result.ErrorMessage); + Assert.Contains($"Option '{option}' is provided by the '{packageName}' extension. Add a package reference to use it.", result.ErrorMessage); + } + + [TestMethod] + [DataRow("--report-adzo", "--report-azdo", "Microsoft.Testing.Extensions.AzureDevOpsReport")] + [DataRow("--coverge", "--coverage", "Microsoft.Testing.Extensions.CodeCoverage")] + [DataRow("--report-htlm", "--report-html", "Microsoft.Testing.Extensions.HtmlReport")] + public async Task ParseAndValidateAsync_MisspelledKnownExtensionOption_SuggestsOptionAndPackage( + string option, + string suggestedOption, + string packageName) + { + CommandLineParseResult parseResult = CommandLineParser.Parse([option], new SystemEnvironment()); + + ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( + parseResult, + _systemCommandLineOptionsProviders, + _extensionCommandLineOptionsProviders, + Mock.Of()); + + Assert.IsFalse(result.IsValid); + Assert.Contains($"Unknown option '{option}'", result.ErrorMessage); + Assert.Contains($"Did you mean '{suggestedOption}'?", result.ErrorMessage); + Assert.Contains($"Option '{suggestedOption}' is provided by the '{packageName}' extension. Add a package reference to use it.", result.ErrorMessage); + } + + [TestMethod] + public async Task ParseAndValidateAsync_MisspelledRegisteredExtensionOption_DoesNotSuggestPackage() + { + CommandLineParseResult parseResult = CommandLineParser.Parse(["--report-adzo"], new SystemEnvironment()); + ICommandLineOptionsProvider[] extensionCommandLineOptionsProviders = + [ + new ExtensionCommandLineProviderMockValidConfiguration("report-azdo"), + ]; + + ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( + parseResult, + _systemCommandLineOptionsProviders, + extensionCommandLineOptionsProviders, + Mock.Of()); + + Assert.IsFalse(result.IsValid); + Assert.Contains("Did you mean '--report-azdo'?", result.ErrorMessage); + Assert.DoesNotContain("Add a package reference", result.ErrorMessage); + } + [TestMethod] public async Task ParseAndValidateAsync_MultipleUnknownOptions_ReportsAll() { From 7d26d2a642caeb1ec2f33e873635e472a73af0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 27 Aug 2026 14:50:13 +0200 Subject: [PATCH 2/9] Test hidden CLI option suggestions Cover the user-visible rule that hidden registered options are excluded from typo suggestions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f53849d1-b75f-4292-8452-9279531cc9ca --- .../CommandLine/CommandLineHandlerTests.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index cabc5412977..2ff8ce37f95 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -576,6 +576,26 @@ public async Task ParseAndValidateAsync_UnknownOptionWithAmbiguousMatches_DoesNo Assert.DoesNotContain("Did you mean", result.ErrorMessage); } + [TestMethod] + public async Task ParseAndValidateAsync_UnknownOptionWithCloseHiddenOption_DoesNotSuggestOption() + { + CommandLineParseResult parseResult = CommandLineParser.Parse(["--hiddden"], new SystemEnvironment()); + ICommandLineOptionsProvider[] extensionCommandLineOptionsProviders = + [ + new ExtensionCommandLineProviderMockValidConfiguration("hidden", isHidden: true), + ]; + + ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( + parseResult, + _systemCommandLineOptionsProviders, + extensionCommandLineOptionsProviders, + Mock.Of()); + + Assert.IsFalse(result.IsValid); + Assert.Contains("Unknown option '--hiddden'", result.ErrorMessage); + Assert.DoesNotContain("Did you mean", result.ErrorMessage); + } + [TestMethod] [DataRow("--report-azdo", "Microsoft.Testing.Extensions.AzureDevOpsReport")] [DataRow("--coverage-output-format", "Microsoft.Testing.Extensions.CodeCoverage")] @@ -954,7 +974,7 @@ public Task ValidateCommandLineOptionsAsync(ICommandLineOption } #pragma warning restore TPEXP - private sealed class ExtensionCommandLineProviderMockValidConfiguration(string optionName) : ICommandLineOptionsProvider + private sealed class ExtensionCommandLineProviderMockValidConfiguration(string optionName, bool isHidden = false) : ICommandLineOptionsProvider { public string Uid => nameof(ExtensionCommandLineProviderMockValidConfiguration); @@ -967,7 +987,7 @@ private sealed class ExtensionCommandLineProviderMockValidConfiguration(string o public Task IsEnabledAsync() => Task.FromResult(true); public IReadOnlyCollection GetCommandLineOptions() - => [new(optionName, optionName, ArgumentArity.ExactlyOne, isHidden: false)]; + => [new(optionName, optionName, ArgumentArity.ExactlyOne, isHidden)]; public Task ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments) => ValidationResult.ValidTask; From ec16ef034a7fdcccc8416dc18bb651acaf7c7e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 27 Aug 2026 15:01:53 +0200 Subject: [PATCH 3/9] Limit unknown option suggestions to registered options Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- ...Validator.UnknownAndBootstrapValidation.cs | 146 +----------------- .../Resources/PlatformResources.resx | 4 - .../Resources/xlf/PlatformResources.cs.xlf | 5 - .../Resources/xlf/PlatformResources.de.xlf | 5 - .../Resources/xlf/PlatformResources.es.xlf | 5 - .../Resources/xlf/PlatformResources.fr.xlf | 5 - .../Resources/xlf/PlatformResources.it.xlf | 5 - .../Resources/xlf/PlatformResources.ja.xlf | 5 - .../Resources/xlf/PlatformResources.ko.xlf | 5 - .../Resources/xlf/PlatformResources.pl.xlf | 5 - .../Resources/xlf/PlatformResources.pt-BR.xlf | 5 - .../Resources/xlf/PlatformResources.ru.xlf | 5 - .../Resources/xlf/PlatformResources.tr.xlf | 5 - .../xlf/PlatformResources.zh-Hans.xlf | 5 - .../xlf/PlatformResources.zh-Hant.xlf | 5 - .../CommandLine/CommandLineHandlerTests.cs | 60 +++---- 16 files changed, 28 insertions(+), 247 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs index 70f49980c8f..c7e94efe733 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs @@ -10,105 +10,6 @@ namespace Microsoft.Testing.Platform.CommandLine; internal static partial class CommandLineOptionsValidator { - // Keep in sync with public command-line providers that are automatically registered by the listed packages. - // Packages without public options, options requiring explicit framework registration, and hidden internal options - // are intentionally omitted. - private static readonly Dictionary KnownExtensionOptionsByPackage = new(StringComparer.OrdinalIgnoreCase) - { - ["Microsoft.Testing.Extensions.AzureDevOpsReport"] = - [ - "publish-azdo-run-name", - "publish-azdo-test-results", - "report-azdo", - "report-azdo-annotations", - "report-azdo-demote-known-flaky", - "report-azdo-flaky-history", - "report-azdo-groups", - "report-azdo-quarantine-file", - "report-azdo-severity", - "report-azdo-slow-test-history", - "report-azdo-slow-test-history-min-sample", - "report-azdo-slow-test-history-multiplier", - "report-azdo-stackframe-filter", - "report-azdo-summary", - "report-azdo-upload-artifact-exclude", - "report-azdo-upload-artifact-include", - "report-azdo-upload-artifact-name", - "report-azdo-upload-artifacts", - ], - ["Microsoft.Testing.Extensions.CodeCoverage"] = - [ - "coverage", - "coverage-output", - "coverage-output-format", - "coverage-settings", - ], - ["Microsoft.Testing.Extensions.CrashDump"] = - [ - "crash-report", - "crash-report-if-supported", - "crash-sequence", - "crashdump", - "crashdump-filename", - "crashdump-type", - ], - ["Microsoft.Testing.Extensions.CtrfReport"] = - [ - "report-ctrf", - "report-ctrf-filename", - ], - ["Microsoft.Testing.Extensions.GitHubActionsReport"] = - [ - "report-gh", - "report-gh-annotations", - "report-gh-failure-details", - "report-gh-groups", - "report-gh-slow-test-notices", - "report-gh-slow-test-threshold", - "report-gh-step-summary", - "report-gh-step-summary-sections", - ], - ["Microsoft.Testing.Extensions.HangDump"] = - [ - "hangdump", - "hangdump-filename", - "hangdump-timeout", - "hangdump-type", - "hangdump-type-if-supported", - ], - ["Microsoft.Testing.Extensions.HtmlReport"] = - [ - "report-html", - "report-html-filename", - ], - ["Microsoft.Testing.Extensions.JUnitReport"] = - [ - "report-junit", - "report-junit-filename", - ], - ["Microsoft.Testing.Extensions.Retry"] = - [ - "retry-failed-tests", - "retry-failed-tests-delay", - "retry-failed-tests-max-percentage", - "retry-failed-tests-max-tests", - ], - ["Microsoft.Testing.Extensions.TrxReport"] = - [ - "report-trx", - "report-trx-filename", - ], - ["Microsoft.Testing.Extensions.VideoRecorder"] = - [ - "capture-video", - "capture-video-args", - "capture-video-chapters", - "capture-video-granularity", - "capture-video-max-duration", - "capture-video-source", - ], - }; - private static ValidationResult ValidateNoUnknownOptions( CommandLineParseResult parseResult, IReadOnlyList? jsonCommandLineOptions, @@ -151,7 +52,7 @@ private static ValidationResult ValidateNoUnknownOptions( if (!validOptionNames.Contains(optionRecord.Name)) { stringBuilder ??= new(); - AppendUnknownOptionError(stringBuilder, optionRecord.Name, validOptionNames, visibleOptionNames); + AppendUnknownOptionError(stringBuilder, optionRecord.Name, visibleOptionNames); } } @@ -167,7 +68,7 @@ private static ValidationResult ValidateNoUnknownOptions( { stringBuilder ??= new(); StringBuilder innerErrorBuilder = new(); - AppendUnknownOptionError(innerErrorBuilder, entry.OptionName, validOptionNames, visibleOptionNames); + AppendUnknownOptionError(innerErrorBuilder, entry.OptionName, visibleOptionNames); string innerError = innerErrorBuilder.ToTrimmedString(); stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.JsonCommandLineOptionsValidationErrorPrefix, innerError)); } @@ -182,56 +83,19 @@ private static ValidationResult ValidateNoUnknownOptions( private static void AppendUnknownOptionError( StringBuilder stringBuilder, string unknownOptionName, - HashSet validOptionNames, HashSet visibleOptionNames) { stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineUnknownOption, unknownOptionName)); - string? packageName = GetKnownExtensionPackage(unknownOptionName); - if (packageName is not null) - { - AppendMissingExtensionSuggestion(stringBuilder, unknownOptionName, packageName); - return; - } - - string? suggestedOptionName = FindSuggestedOption( - unknownOptionName, - visibleOptionNames.Concat(KnownExtensionOptionsByPackage.Values.SelectMany(static optionNames => optionNames))); - if (suggestedOptionName is null) + if (FindSuggestedOption(unknownOptionName, visibleOptionNames) is not { } suggestedOptionName) { return; } stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineOptionSuggestion, suggestedOptionName)); - - packageName = GetKnownExtensionPackage(suggestedOptionName); - if (packageName is not null && !validOptionNames.Contains(suggestedOptionName)) - { - AppendMissingExtensionSuggestion(stringBuilder, suggestedOptionName, packageName); - } - } - - private static void AppendMissingExtensionSuggestion(StringBuilder stringBuilder, string optionName, string packageName) - => stringBuilder.AppendLine(string.Format( - CultureInfo.InvariantCulture, - PlatformResources.CommandLineOptionRequiresExtension, - optionName, - packageName)); - - private static string? GetKnownExtensionPackage(string optionName) - { - foreach (KeyValuePair extensionOptions in KnownExtensionOptionsByPackage) - { - if (extensionOptions.Value.Contains(optionName, StringComparer.OrdinalIgnoreCase)) - { - return extensionOptions.Key; - } - } - - return null; } - private static string? FindSuggestedOption(string unknownOptionName, IEnumerable candidateOptionNames) + private static string? FindSuggestedOption(string unknownOptionName, HashSet candidateOptionNames) { int maximumDistance = unknownOptionName.Length switch { @@ -244,7 +108,7 @@ private static void AppendMissingExtensionSuggestion(StringBuilder stringBuilder int bestDistance = maximumDistance + 1; bool hasAmbiguousBestCandidate = false; - foreach (string candidateOptionName in candidateOptionNames.Distinct(StringComparer.OrdinalIgnoreCase)) + foreach (string candidateOptionName in candidateOptionNames) { if (Math.Abs(candidateOptionName.Length - unknownOptionName.Length) > maximumDistance) { diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index 5bf31741fd6..a9b59278f6f 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -471,10 +471,6 @@ Did you mean '--{0}'? {0} is the suggested option name without the leading dashes. - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Invalid command line arguments: diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf index f626c6ae823..b0ba580ba0f 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -197,11 +197,6 @@ Možnost --{0} od zprostředkovatele {1} (UID: {2}) používá vyhrazenou předponu --internal. {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf index 24b5843dc2c..3db62dac3c8 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -197,11 +197,6 @@ Die Option "--{0}" vom Anbieter "{1}" (UID: {2}) verwendet das reservierte Präfix "--internal". {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf index b91d266293c..a76de32c86b 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -197,11 +197,6 @@ La opción “--{0}” del proveedor “{1}” (UID: {2}) usa el prefijo reservado “--internal” {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf index aa22f707864..509237ffc15 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -197,11 +197,6 @@ L’option « --{0} » du fournisseur « {1} » (UID : {2}) utilise le préfixe réservé « --internal » {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf index b6d20eb572d..9862565a8bc 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -197,11 +197,6 @@ L'opzione '--{0}' del provider '{1}' (UID: {2}) usa il prefisso riservato '--internal' {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf index e093e617028..937d6eac7ad 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -197,11 +197,6 @@ プロバイダー '{1}' のオプション '--{0}' (UID:{2}) は予約済みプレフィックス '--internal' を 使用しています {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf index 41751018e3d..f77e3d8350f 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -197,11 +197,6 @@ 공급자 '{1}'(UID: {2})의 옵션 '-- {0}'이 예약된 접두사 '--internal'을 사용하고 있습니다. {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf index 5d0e274bc49..2fe4283a271 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -197,11 +197,6 @@ Opcja „--{0}” od dostawcy „{1}” (UID: {2}) używa zastrzeżonego prefiksu „--internal” {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf index 33f17046106..971293067f4 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf @@ -197,11 +197,6 @@ A opção '--{0}' do provedor '{1}' (UID: {2}) está usando o prefixo reservado '--internal' {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf index ee4b91d7471..237fb1bb243 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -197,11 +197,6 @@ Параметр "--{0}" от поставщика "{1}" (UID: {2}) использует зарезервированный префикс "--internal" {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf index b02858cffa0..8db36e8fbaa 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -197,11 +197,6 @@ '{1}' sağlayıcısındaki (UID: {2}) `--{0}` seçeneği ayrılmış '--internal' önekini kullanıyor {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf index de76cfe16ae..0895ee11ba4 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf @@ -197,11 +197,6 @@ 来自提供程序“{1}” (UID: {2}) 的选项“--{0}”正在使用保留前缀“--internal” {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf index a96d2bd9feb..388dcddab83 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf @@ -197,11 +197,6 @@ 提供者 '{1}' (UID: {2}) 中的選項 '--{0}' 使用保留的前置詞 '--internal' {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} - - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. - {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. - Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index 2ff8ce37f95..aef2e7813de 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -597,20 +597,9 @@ public async Task ParseAndValidateAsync_UnknownOptionWithCloseHiddenOption_DoesN } [TestMethod] - [DataRow("--report-azdo", "Microsoft.Testing.Extensions.AzureDevOpsReport")] - [DataRow("--coverage-output-format", "Microsoft.Testing.Extensions.CodeCoverage")] - [DataRow("--crashdump-type", "Microsoft.Testing.Extensions.CrashDump")] - [DataRow("--report-ctrf", "Microsoft.Testing.Extensions.CtrfReport")] - [DataRow("--report-gh", "Microsoft.Testing.Extensions.GitHubActionsReport")] - [DataRow("--hangdump-timeout", "Microsoft.Testing.Extensions.HangDump")] - [DataRow("--report-html", "Microsoft.Testing.Extensions.HtmlReport")] - [DataRow("--report-junit", "Microsoft.Testing.Extensions.JUnitReport")] - [DataRow("--retry-failed-tests", "Microsoft.Testing.Extensions.Retry")] - [DataRow("--report-trx", "Microsoft.Testing.Extensions.TrxReport")] - [DataRow("--capture-video", "Microsoft.Testing.Extensions.VideoRecorder")] - public async Task ParseAndValidateAsync_KnownExtensionOptionWithoutExtension_SuggestsPackage(string option, string packageName) + public async Task ParseAndValidateAsync_MisspelledUnregisteredExtensionOption_DoesNotSuggestOption() { - CommandLineParseResult parseResult = CommandLineParser.Parse([option], new SystemEnvironment()); + CommandLineParseResult parseResult = CommandLineParser.Parse(["--report-adzo"], new SystemEnvironment()); ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( parseResult, @@ -619,51 +608,48 @@ public async Task ParseAndValidateAsync_KnownExtensionOptionWithoutExtension_Sug Mock.Of()); Assert.IsFalse(result.IsValid); - Assert.Contains($"Unknown option '{option}'", result.ErrorMessage); - Assert.Contains($"Option '{option}' is provided by the '{packageName}' extension. Add a package reference to use it.", result.ErrorMessage); + Assert.Contains("Unknown option '--report-adzo'", result.ErrorMessage); + Assert.DoesNotContain("Did you mean", result.ErrorMessage); } [TestMethod] - [DataRow("--report-adzo", "--report-azdo", "Microsoft.Testing.Extensions.AzureDevOpsReport")] - [DataRow("--coverge", "--coverage", "Microsoft.Testing.Extensions.CodeCoverage")] - [DataRow("--report-htlm", "--report-html", "Microsoft.Testing.Extensions.HtmlReport")] - public async Task ParseAndValidateAsync_MisspelledKnownExtensionOption_SuggestsOptionAndPackage( - string option, - string suggestedOption, - string packageName) + public async Task ParseAndValidateAsync_MisspelledRegisteredExtensionOption_SuggestsOption() { - CommandLineParseResult parseResult = CommandLineParser.Parse([option], new SystemEnvironment()); + CommandLineParseResult parseResult = CommandLineParser.Parse(["--report-adzo"], new SystemEnvironment()); + ICommandLineOptionsProvider[] extensionCommandLineOptionsProviders = + [ + new ExtensionCommandLineProviderMockValidConfiguration("report-azdo"), + ]; ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( parseResult, _systemCommandLineOptionsProviders, - _extensionCommandLineOptionsProviders, + extensionCommandLineOptionsProviders, Mock.Of()); Assert.IsFalse(result.IsValid); - Assert.Contains($"Unknown option '{option}'", result.ErrorMessage); - Assert.Contains($"Did you mean '{suggestedOption}'?", result.ErrorMessage); - Assert.Contains($"Option '{suggestedOption}' is provided by the '{packageName}' extension. Add a package reference to use it.", result.ErrorMessage); + Assert.Contains("Did you mean '--report-azdo'?", result.ErrorMessage); } [TestMethod] - public async Task ParseAndValidateAsync_MisspelledRegisteredExtensionOption_DoesNotSuggestPackage() + public async Task ParseAndValidateAsync_MisspelledJsonOption_SuggestsRegisteredOption() { - CommandLineParseResult parseResult = CommandLineParser.Parse(["--report-adzo"], new SystemEnvironment()); - ICommandLineOptionsProvider[] extensionCommandLineOptionsProviders = - [ - new ExtensionCommandLineProviderMockValidConfiguration("report-azdo"), - ]; + CommandLineParseResult parseResult = CommandLineParser.Parse([], new SystemEnvironment()); ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( parseResult, _systemCommandLineOptionsProviders, - extensionCommandLineOptionsProviders, - Mock.Of()); + _extensionCommandLineOptionsProviders, + Mock.Of(), + [new JsonCommandLineOptionEntry("halp", [], isDisabled: false)]); Assert.IsFalse(result.IsValid); - Assert.Contains("Did you mean '--report-azdo'?", result.ErrorMessage); - Assert.DoesNotContain("Add a package reference", result.ErrorMessage); + Assert.Contains( + """ + In testconfig.json under 'commandLineOptions': Unknown option '--halp' + Did you mean '--help'? + """, + result.ErrorMessage); } [TestMethod] From 7b1ee238446596b6eb7139fd0921d939f711473a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 27 Aug 2026 15:15:18 +0200 Subject: [PATCH 4/9] Strengthen registered option suggestion test Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../CommandLine/CommandLineHandlerTests.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index aef2e7813de..68e6a978049 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -628,7 +628,13 @@ public async Task ParseAndValidateAsync_MisspelledRegisteredExtensionOption_Sugg Mock.Of()); Assert.IsFalse(result.IsValid); - Assert.Contains("Did you mean '--report-azdo'?", result.ErrorMessage); + Assert.AreEqual( + """ + Unknown option '--report-adzo' + Did you mean '--report-azdo'? + Command line: --report-adzo + """, + result.ErrorMessage); } [TestMethod] From 1873ff97b9bab0342196fe88efac411ad614f16b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 27 Aug 2026 15:22:54 +0200 Subject: [PATCH 5/9] Restore extension package guidance Restore known option-to-package metadata and diagnostics for automatically registered first-party extensions, including Microsoft code coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f53849d1-b75f-4292-8452-9279531cc9ca --- ...Validator.UnknownAndBootstrapValidation.cs | 146 +++++++++++++++++- .../Resources/PlatformResources.resx | 4 + .../Resources/xlf/PlatformResources.cs.xlf | 5 + .../Resources/xlf/PlatformResources.de.xlf | 5 + .../Resources/xlf/PlatformResources.es.xlf | 5 + .../Resources/xlf/PlatformResources.fr.xlf | 5 + .../Resources/xlf/PlatformResources.it.xlf | 5 + .../Resources/xlf/PlatformResources.ja.xlf | 5 + .../Resources/xlf/PlatformResources.ko.xlf | 5 + .../Resources/xlf/PlatformResources.pl.xlf | 5 + .../Resources/xlf/PlatformResources.pt-BR.xlf | 5 + .../Resources/xlf/PlatformResources.ru.xlf | 5 + .../Resources/xlf/PlatformResources.tr.xlf | 5 + .../xlf/PlatformResources.zh-Hans.xlf | 5 + .../xlf/PlatformResources.zh-Hant.xlf | 5 + .../CommandLine/CommandLineHandlerTests.cs | 44 +++++- 16 files changed, 249 insertions(+), 10 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs index c7e94efe733..70f49980c8f 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs @@ -10,6 +10,105 @@ namespace Microsoft.Testing.Platform.CommandLine; internal static partial class CommandLineOptionsValidator { + // Keep in sync with public command-line providers that are automatically registered by the listed packages. + // Packages without public options, options requiring explicit framework registration, and hidden internal options + // are intentionally omitted. + private static readonly Dictionary KnownExtensionOptionsByPackage = new(StringComparer.OrdinalIgnoreCase) + { + ["Microsoft.Testing.Extensions.AzureDevOpsReport"] = + [ + "publish-azdo-run-name", + "publish-azdo-test-results", + "report-azdo", + "report-azdo-annotations", + "report-azdo-demote-known-flaky", + "report-azdo-flaky-history", + "report-azdo-groups", + "report-azdo-quarantine-file", + "report-azdo-severity", + "report-azdo-slow-test-history", + "report-azdo-slow-test-history-min-sample", + "report-azdo-slow-test-history-multiplier", + "report-azdo-stackframe-filter", + "report-azdo-summary", + "report-azdo-upload-artifact-exclude", + "report-azdo-upload-artifact-include", + "report-azdo-upload-artifact-name", + "report-azdo-upload-artifacts", + ], + ["Microsoft.Testing.Extensions.CodeCoverage"] = + [ + "coverage", + "coverage-output", + "coverage-output-format", + "coverage-settings", + ], + ["Microsoft.Testing.Extensions.CrashDump"] = + [ + "crash-report", + "crash-report-if-supported", + "crash-sequence", + "crashdump", + "crashdump-filename", + "crashdump-type", + ], + ["Microsoft.Testing.Extensions.CtrfReport"] = + [ + "report-ctrf", + "report-ctrf-filename", + ], + ["Microsoft.Testing.Extensions.GitHubActionsReport"] = + [ + "report-gh", + "report-gh-annotations", + "report-gh-failure-details", + "report-gh-groups", + "report-gh-slow-test-notices", + "report-gh-slow-test-threshold", + "report-gh-step-summary", + "report-gh-step-summary-sections", + ], + ["Microsoft.Testing.Extensions.HangDump"] = + [ + "hangdump", + "hangdump-filename", + "hangdump-timeout", + "hangdump-type", + "hangdump-type-if-supported", + ], + ["Microsoft.Testing.Extensions.HtmlReport"] = + [ + "report-html", + "report-html-filename", + ], + ["Microsoft.Testing.Extensions.JUnitReport"] = + [ + "report-junit", + "report-junit-filename", + ], + ["Microsoft.Testing.Extensions.Retry"] = + [ + "retry-failed-tests", + "retry-failed-tests-delay", + "retry-failed-tests-max-percentage", + "retry-failed-tests-max-tests", + ], + ["Microsoft.Testing.Extensions.TrxReport"] = + [ + "report-trx", + "report-trx-filename", + ], + ["Microsoft.Testing.Extensions.VideoRecorder"] = + [ + "capture-video", + "capture-video-args", + "capture-video-chapters", + "capture-video-granularity", + "capture-video-max-duration", + "capture-video-source", + ], + }; + private static ValidationResult ValidateNoUnknownOptions( CommandLineParseResult parseResult, IReadOnlyList? jsonCommandLineOptions, @@ -52,7 +151,7 @@ private static ValidationResult ValidateNoUnknownOptions( if (!validOptionNames.Contains(optionRecord.Name)) { stringBuilder ??= new(); - AppendUnknownOptionError(stringBuilder, optionRecord.Name, visibleOptionNames); + AppendUnknownOptionError(stringBuilder, optionRecord.Name, validOptionNames, visibleOptionNames); } } @@ -68,7 +167,7 @@ private static ValidationResult ValidateNoUnknownOptions( { stringBuilder ??= new(); StringBuilder innerErrorBuilder = new(); - AppendUnknownOptionError(innerErrorBuilder, entry.OptionName, visibleOptionNames); + AppendUnknownOptionError(innerErrorBuilder, entry.OptionName, validOptionNames, visibleOptionNames); string innerError = innerErrorBuilder.ToTrimmedString(); stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.JsonCommandLineOptionsValidationErrorPrefix, innerError)); } @@ -83,19 +182,56 @@ private static ValidationResult ValidateNoUnknownOptions( private static void AppendUnknownOptionError( StringBuilder stringBuilder, string unknownOptionName, + HashSet validOptionNames, HashSet visibleOptionNames) { stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineUnknownOption, unknownOptionName)); - if (FindSuggestedOption(unknownOptionName, visibleOptionNames) is not { } suggestedOptionName) + string? packageName = GetKnownExtensionPackage(unknownOptionName); + if (packageName is not null) + { + AppendMissingExtensionSuggestion(stringBuilder, unknownOptionName, packageName); + return; + } + + string? suggestedOptionName = FindSuggestedOption( + unknownOptionName, + visibleOptionNames.Concat(KnownExtensionOptionsByPackage.Values.SelectMany(static optionNames => optionNames))); + if (suggestedOptionName is null) { return; } stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineOptionSuggestion, suggestedOptionName)); + + packageName = GetKnownExtensionPackage(suggestedOptionName); + if (packageName is not null && !validOptionNames.Contains(suggestedOptionName)) + { + AppendMissingExtensionSuggestion(stringBuilder, suggestedOptionName, packageName); + } + } + + private static void AppendMissingExtensionSuggestion(StringBuilder stringBuilder, string optionName, string packageName) + => stringBuilder.AppendLine(string.Format( + CultureInfo.InvariantCulture, + PlatformResources.CommandLineOptionRequiresExtension, + optionName, + packageName)); + + private static string? GetKnownExtensionPackage(string optionName) + { + foreach (KeyValuePair extensionOptions in KnownExtensionOptionsByPackage) + { + if (extensionOptions.Value.Contains(optionName, StringComparer.OrdinalIgnoreCase)) + { + return extensionOptions.Key; + } + } + + return null; } - private static string? FindSuggestedOption(string unknownOptionName, HashSet candidateOptionNames) + private static string? FindSuggestedOption(string unknownOptionName, IEnumerable candidateOptionNames) { int maximumDistance = unknownOptionName.Length switch { @@ -108,7 +244,7 @@ private static void AppendUnknownOptionError( int bestDistance = maximumDistance + 1; bool hasAmbiguousBestCandidate = false; - foreach (string candidateOptionName in candidateOptionNames) + foreach (string candidateOptionName in candidateOptionNames.Distinct(StringComparer.OrdinalIgnoreCase)) { if (Math.Abs(candidateOptionName.Length - unknownOptionName.Length) > maximumDistance) { diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index a9b59278f6f..5bf31741fd6 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -471,6 +471,10 @@ Did you mean '--{0}'? {0} is the suggested option name without the leading dashes. + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Invalid command line arguments: diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf index b0ba580ba0f..f626c6ae823 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -197,6 +197,11 @@ Možnost --{0} od zprostředkovatele {1} (UID: {2}) používá vyhrazenou předponu --internal. {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf index 3db62dac3c8..24b5843dc2c 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -197,6 +197,11 @@ Die Option "--{0}" vom Anbieter "{1}" (UID: {2}) verwendet das reservierte Präfix "--internal". {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf index a76de32c86b..b91d266293c 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -197,6 +197,11 @@ La opción “--{0}” del proveedor “{1}” (UID: {2}) usa el prefijo reservado “--internal” {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf index 509237ffc15..aa22f707864 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -197,6 +197,11 @@ L’option « --{0} » du fournisseur « {1} » (UID : {2}) utilise le préfixe réservé « --internal » {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf index 9862565a8bc..b6d20eb572d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -197,6 +197,11 @@ L'opzione '--{0}' del provider '{1}' (UID: {2}) usa il prefisso riservato '--internal' {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf index 937d6eac7ad..e093e617028 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -197,6 +197,11 @@ プロバイダー '{1}' のオプション '--{0}' (UID:{2}) は予約済みプレフィックス '--internal' を 使用しています {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf index f77e3d8350f..41751018e3d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -197,6 +197,11 @@ 공급자 '{1}'(UID: {2})의 옵션 '-- {0}'이 예약된 접두사 '--internal'을 사용하고 있습니다. {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf index 2fe4283a271..5d0e274bc49 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -197,6 +197,11 @@ Opcja „--{0}” od dostawcy „{1}” (UID: {2}) używa zastrzeżonego prefiksu „--internal” {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf index 971293067f4..33f17046106 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf @@ -197,6 +197,11 @@ A opção '--{0}' do provedor '{1}' (UID: {2}) está usando o prefixo reservado '--internal' {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf index 237fb1bb243..ee4b91d7471 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -197,6 +197,11 @@ Параметр "--{0}" от поставщика "{1}" (UID: {2}) использует зарезервированный префикс "--internal" {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf index 8db36e8fbaa..b02858cffa0 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -197,6 +197,11 @@ '{1}' sağlayıcısındaki (UID: {2}) `--{0}` seçeneği ayrılmış '--internal' önekini kullanıyor {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf index 0895ee11ba4..de76cfe16ae 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf @@ -197,6 +197,11 @@ 来自提供程序“{1}” (UID: {2}) 的选项“--{0}”正在使用保留前缀“--internal” {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf index 388dcddab83..a96d2bd9feb 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf @@ -197,6 +197,11 @@ 提供者 '{1}' (UID: {2}) 中的選項 '--{0}' 使用保留的前置詞 '--internal' {0} is the option name without the leading dashes. {1} is the provider display name. {2} is the provider UID. {Locked="--internal"} + + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. + {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. + Did you mean '--{0}'? Did you mean '--{0}'? diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index 68e6a978049..3b33da1700b 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -597,9 +597,20 @@ public async Task ParseAndValidateAsync_UnknownOptionWithCloseHiddenOption_DoesN } [TestMethod] - public async Task ParseAndValidateAsync_MisspelledUnregisteredExtensionOption_DoesNotSuggestOption() + [DataRow("--report-azdo", "Microsoft.Testing.Extensions.AzureDevOpsReport")] + [DataRow("--coverage-output-format", "Microsoft.Testing.Extensions.CodeCoverage")] + [DataRow("--crashdump-type", "Microsoft.Testing.Extensions.CrashDump")] + [DataRow("--report-ctrf", "Microsoft.Testing.Extensions.CtrfReport")] + [DataRow("--report-gh", "Microsoft.Testing.Extensions.GitHubActionsReport")] + [DataRow("--hangdump-timeout", "Microsoft.Testing.Extensions.HangDump")] + [DataRow("--report-html", "Microsoft.Testing.Extensions.HtmlReport")] + [DataRow("--report-junit", "Microsoft.Testing.Extensions.JUnitReport")] + [DataRow("--retry-failed-tests", "Microsoft.Testing.Extensions.Retry")] + [DataRow("--report-trx", "Microsoft.Testing.Extensions.TrxReport")] + [DataRow("--capture-video", "Microsoft.Testing.Extensions.VideoRecorder")] + public async Task ParseAndValidateAsync_KnownExtensionOptionWithoutExtension_SuggestsPackage(string option, string packageName) { - CommandLineParseResult parseResult = CommandLineParser.Parse(["--report-adzo"], new SystemEnvironment()); + CommandLineParseResult parseResult = CommandLineParser.Parse([option], new SystemEnvironment()); ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( parseResult, @@ -608,12 +619,35 @@ public async Task ParseAndValidateAsync_MisspelledUnregisteredExtensionOption_Do Mock.Of()); Assert.IsFalse(result.IsValid); - Assert.Contains("Unknown option '--report-adzo'", result.ErrorMessage); - Assert.DoesNotContain("Did you mean", result.ErrorMessage); + Assert.Contains($"Unknown option '{option}'", result.ErrorMessage); + Assert.Contains($"Option '{option}' is provided by the '{packageName}' extension. Add a package reference to use it.", result.ErrorMessage); + } + + [TestMethod] + [DataRow("--report-adzo", "--report-azdo", "Microsoft.Testing.Extensions.AzureDevOpsReport")] + [DataRow("--coverge", "--coverage", "Microsoft.Testing.Extensions.CodeCoverage")] + [DataRow("--report-htlm", "--report-html", "Microsoft.Testing.Extensions.HtmlReport")] + public async Task ParseAndValidateAsync_MisspelledKnownExtensionOption_SuggestsOptionAndPackage( + string option, + string suggestedOption, + string packageName) + { + CommandLineParseResult parseResult = CommandLineParser.Parse([option], new SystemEnvironment()); + + ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( + parseResult, + _systemCommandLineOptionsProviders, + _extensionCommandLineOptionsProviders, + Mock.Of()); + + Assert.IsFalse(result.IsValid); + Assert.Contains($"Unknown option '{option}'", result.ErrorMessage); + Assert.Contains($"Did you mean '{suggestedOption}'?", result.ErrorMessage); + Assert.Contains($"Option '{suggestedOption}' is provided by the '{packageName}' extension. Add a package reference to use it.", result.ErrorMessage); } [TestMethod] - public async Task ParseAndValidateAsync_MisspelledRegisteredExtensionOption_SuggestsOption() + public async Task ParseAndValidateAsync_MisspelledRegisteredExtensionOption_DoesNotSuggestPackage() { CommandLineParseResult parseResult = CommandLineParser.Parse(["--report-adzo"], new SystemEnvironment()); ICommandLineOptionsProvider[] extensionCommandLineOptionsProviders = From 878289c6fd83ef4dda20a1e1be1d73b4ccda61b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 27 Aug 2026 15:30:06 +0200 Subject: [PATCH 6/9] Fix command-line resources after base merge Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../Microsoft.Testing.Platform/Resources/PlatformResources.resx | 1 + .../CommandLine/CommandLineHandlerTests.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index fe3e2cb2634..763190aa099 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -470,6 +470,7 @@ Did you mean '--{0}'? {0} is the suggested option name without the leading dashes. + Run '--help' to see the options registered by this test application. If the option belongs to an extension, ensure its package is referenced and the extension is registered. {Locked="'--help'"} diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index 5ea6dbb5d98..323fb54f8bd 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -551,6 +551,7 @@ public async Task ParseAndValidateAsync_UnknownOptionWithCloseRegisteredOption_S """ Unknown option '--halp' Did you mean '--help'? + Run '--help' to see the options registered by this test application. If the option belongs to an extension, ensure its package is referenced and the extension is registered. Command line: --halp """, result.ErrorMessage); @@ -633,6 +634,7 @@ public async Task ParseAndValidateAsync_MisspelledRegisteredExtensionOption_Sugg """ Unknown option '--report-adzo' Did you mean '--report-azdo'? + Run '--help' to see the options registered by this test application. If the option belongs to an extension, ensure its package is referenced and the extension is registered. Command line: --report-adzo """, result.ErrorMessage); From c5d8343f99e62fdf34485f246c99ad20a6f1ed2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 27 Aug 2026 15:33:08 +0200 Subject: [PATCH 7/9] Fix merged unknown-option resource XML Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../Microsoft.Testing.Platform/Resources/PlatformResources.resx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index 4c958bceabb..e11c16163e8 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -474,6 +474,7 @@ Run '--help' to see the options registered by this test application. If the option belongs to an extension, ensure its package is referenced and the extension is registered. {Locked="'--help'"} + Option '--{0}' is provided by the '{1}' extension. Add a package reference to use it. {0} is the option name without the leading dashes. {1} is the extension's NuGet package name. From dbbeea5c4d6dc7db7344d7000094b1103f014710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 27 Aug 2026 15:38:03 +0200 Subject: [PATCH 8/9] Test option suggestion distance thresholds Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../CommandLine/CommandLineHandlerTests.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index e87af1d64a5..1e3b9aa92ba 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -557,6 +557,40 @@ Did you mean '--help'? result.ErrorMessage); } + [TestMethod] + [DataRow("abcdefgh", "abczefgx", true)] + [DataRow("abcdefgh", "abczefxy", false)] + [DataRow("abcdefghijklmn", "abczefghijklxy", true)] + [DataRow("abcdefghijklmn", "abczefghijkwxy", false)] + public async Task ParseAndValidateAsync_UnknownOption_RespectsSuggestionDistanceThresholds( + string registeredOptionName, + string unknownOptionName, + bool shouldSuggest) + { + CommandLineParseResult parseResult = CommandLineParser.Parse([$"--{unknownOptionName}"], new SystemEnvironment()); + ICommandLineOptionsProvider[] extensionCommandLineOptionsProviders = + [ + new ExtensionCommandLineProviderMockValidConfiguration(registeredOptionName), + ]; + + ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( + parseResult, + _systemCommandLineOptionsProviders, + extensionCommandLineOptionsProviders, + Mock.Of()); + + Assert.IsFalse(result.IsValid); + Assert.Contains($"Unknown option '--{unknownOptionName}'", result.ErrorMessage); + if (shouldSuggest) + { + Assert.Contains($"Did you mean '--{registeredOptionName}'?", result.ErrorMessage); + } + else + { + Assert.DoesNotContain("Did you mean", result.ErrorMessage); + } + } + [TestMethod] public async Task ParseAndValidateAsync_UnknownOptionWithAmbiguousMatches_DoesNotSuggestOption() { From 3560ad6f4a010fd29d59cf543cde3866861cda2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 27 Aug 2026 15:44:53 +0200 Subject: [PATCH 9/9] Suppress extension catalog suggestions for tools Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- ...Validator.UnknownAndBootstrapValidation.cs | 24 ++++++++++++------- .../CommandLine/CommandLineHandlerTests.cs | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs index 38d9bebec72..51a6f9e4603 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.UnknownAndBootstrapValidation.cs @@ -121,6 +121,7 @@ private static ValidationResult ValidateNoUnknownOptions( // does not change CLI behavior. var validOptionNames = new HashSet(StringComparer.OrdinalIgnoreCase); var visibleOptionNames = new HashSet(StringComparer.OrdinalIgnoreCase); + bool includeKnownExtensionOptions = !parseResult.HasTool; foreach (KeyValuePair> provider in extensionOptionsByProvider) { foreach (CommandLineOption option in provider.Value) @@ -151,7 +152,7 @@ private static ValidationResult ValidateNoUnknownOptions( if (!validOptionNames.Contains(optionRecord.Name)) { stringBuilder ??= new(); - AppendUnknownOptionError(stringBuilder, optionRecord.Name, validOptionNames, visibleOptionNames); + AppendUnknownOptionError(stringBuilder, optionRecord.Name, validOptionNames, visibleOptionNames, includeKnownExtensionOptions); } } @@ -167,7 +168,7 @@ private static ValidationResult ValidateNoUnknownOptions( { stringBuilder ??= new(); StringBuilder innerErrorBuilder = new(); - AppendUnknownOptionError(innerErrorBuilder, entry.OptionName, validOptionNames, visibleOptionNames); + AppendUnknownOptionError(innerErrorBuilder, entry.OptionName, validOptionNames, visibleOptionNames, includeKnownExtensionOptions); string innerError = innerErrorBuilder.ToTrimmedString(); stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.JsonCommandLineOptionsValidationErrorPrefix, innerError)); } @@ -188,20 +189,24 @@ private static void AppendUnknownOptionError( StringBuilder stringBuilder, string unknownOptionName, HashSet validOptionNames, - HashSet visibleOptionNames) + HashSet visibleOptionNames, + bool includeKnownExtensionOptions) { stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineUnknownOption, unknownOptionName)); - string? packageName = GetKnownExtensionPackage(unknownOptionName); - if (packageName is not null) + if (includeKnownExtensionOptions + && GetKnownExtensionPackage(unknownOptionName) is { } packageName) { AppendMissingExtensionSuggestion(stringBuilder, unknownOptionName, packageName); return; } + IEnumerable candidateOptionNames = includeKnownExtensionOptions + ? visibleOptionNames.Concat(KnownExtensionOptionsByPackage.Values.SelectMany(static optionNames => optionNames)) + : visibleOptionNames; string? suggestedOptionName = FindSuggestedOption( unknownOptionName, - visibleOptionNames.Concat(KnownExtensionOptionsByPackage.Values.SelectMany(static optionNames => optionNames))); + candidateOptionNames); if (suggestedOptionName is null) { return; @@ -209,10 +214,11 @@ private static void AppendUnknownOptionError( stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineOptionSuggestion, suggestedOptionName)); - packageName = GetKnownExtensionPackage(suggestedOptionName); - if (packageName is not null && !validOptionNames.Contains(suggestedOptionName)) + if (includeKnownExtensionOptions + && GetKnownExtensionPackage(suggestedOptionName) is { } suggestedPackageName + && !validOptionNames.Contains(suggestedOptionName)) { - AppendMissingExtensionSuggestion(stringBuilder, suggestedOptionName, packageName); + AppendMissingExtensionSuggestion(stringBuilder, suggestedOptionName, suggestedPackageName); } } diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index 1e3b9aa92ba..0030e94dfbc 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -357,6 +357,30 @@ public async Task ParseAndValidateAsync_ToolOptionDoesNotConflictWithNormalExten Assert.IsTrue(result.IsValid); } + [TestMethod] + [DataRow("--report-trx")] + [DataRow("--report-txr")] + public async Task ParseAndValidateAsync_KnownExtensionOptionInToolMode_DoesNotSuggestPackageOrOption(string option) + { + CommandLineParseResult parseResult = CommandLineParser.Parse(["tool", option], new SystemEnvironment()); + ICommandLineOptionsProvider[] providers = + [ + new ExtensionCommandLineProviderMockValidConfiguration("report-trx"), + new ToolCommandLineProviderMock("input"), + ]; + + ValidationResult result = await CommandLineOptionsValidator.ValidateAsync( + parseResult, + _systemCommandLineOptionsProviders, + providers, + Mock.Of()); + + Assert.IsFalse(result.IsValid); + Assert.Contains($"Unknown option '{option}'", result.ErrorMessage); + Assert.DoesNotContain("Did you mean", result.ErrorMessage); + Assert.DoesNotContain("Microsoft.Testing.Extensions.TrxReport", result.ErrorMessage); + } + [TestMethod] public async Task ParseAndValidateAsync_UnknownJsonOptionForSelectedTool_ReturnsInvalid() {