Block --help and --list-tests for MTP test apps when passed via non-CLI channels#54487
Open
Evangelink wants to merge 4 commits into
Open
Block --help and --list-tests for MTP test apps when passed via non-CLI channels#54487Evangelink wants to merge 4 commits into
Evangelink wants to merge 4 commits into
Conversation
Fixes dotnet#50654. When users pass --help, -?, or --list-tests to a Microsoft Testing Platform (MTP) test app through channels the .NET CLI doesn't observe (TestingPlatformCommandLineArguments MSBuild property, RunArguments, or launchSettings.json's commandLineArgs), the SDK previously either crashed via FailFast or silently reported zero tests run. This change adds a pre-launch validation step in TestApplication.RunAsync that tokenizes args from all three sources and throws a GracefulException with a clear, actionable message identifying the offending option and the channel it came through. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents MTP test apps from receiving --help, -?, or --list-tests through argument channels that bypass normal dotnet test parsing, replacing crash/zero-test behavior with a clear user-facing failure.
Changes:
- Adds pre-launch validation for forbidden test-app arguments from CLI passthrough, MSBuild
RunArguments, and launch profile args. - Handles
GracefulExceptioncleanly in the MTP test application queue. - Adds localized resource strings and regression tests for key argument sources.
Show a summary per file
| File | Description |
|---|---|
src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs |
Adds forbidden-option validation and tokenization before launching test apps. |
src/Cli/dotnet/Commands/Test/MTP/TestApplicationActionQueue.cs |
Prints GracefulException messages without wrapping/stack traces. |
src/Cli/dotnet/Commands/CliCommandStrings.resx |
Adds user-facing error/source strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf |
Adds localization units for the new strings. |
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf |
Adds localization units for the new strings. |
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsHelp.cs |
Adds regression tests for forbidden options via MSBuild property and CLI passthrough. |
Copilot's findings
- Files reviewed: 17/17 changed files
- Comments generated: 2
…ests - Sanitize forbiddenOption before using it in CopyTestAsset identifier: '-?' was producing a test-asset directory containing '?', invalid on Windows file systems. - Add PassingHelpOrListTestsViaLaunchSettings_ShouldFailWithClearError to cover the launchSettings.json commandLineArgs validation path. - Add PassingHelpInLaunchSettings_IsBypassedByNoLaunchProfileArguments to verify '--no-launch-profile-arguments' opts out of the check. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addresses a reviewer concern about MSBuild list-separator semantics. While the OS argv parser does not in practice split on ';' (verified empirically with a dotnet exec test), splitting defensively here is zero-cost (the three forbidden tokens never appear inside legitimate arg values) and future-proofs the validation against any upstream pre-processing that might. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous '.NotBe(GenericFailure)' assertion passed coincidentally because the test asset's Program.cs throws on missing '--from-launch-settings', producing exit code -532462766 (.NET unhandled exception) rather than 1. That meant if the bypass logic silently broke, the test would still pass. Now assert directly that the launch-settings validation error fragment does not appear in any output and that the test app actually proceeded to its own pre-launch check (proving '--help' was dropped from argv). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0cb5efc to
0247f87
Compare
This was referenced May 28, 2026
Open
Member
Author
|
@copilot resolve the merge conflicts in this pull request |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #50654.
Problem
When users pass
--help,-?, or--list-teststo a Microsoft Testing Platform (MTP) test app through channels the .NET CLI doesn't observe, the SDK either crashes viaFailFastor silently reports zero tests run. Affected channels:TestingPlatformCommandLineArgumentsMSBuild propertyRunArgumentsMSBuild propertylaunchSettings.json'scommandLineArgsFix
Added a pre-launch validation step in
TestApplication.RunAsyncthat tokenizes args from all three sources and throws aGracefulExceptionwith a clear, actionable message identifying the offending option and its source. The user is told to pass the option directly todotnet testinstead.The check is skipped when the user legitimately passed
--helptodotnet test(TestOptions.IsHelp), and similarly for--list-testsduring discovery (TestOptions.IsDiscovery).Also added a
catch (GracefulException)block inTestApplicationActionQueue.Readso the new error message is printed cleanly (no stack trace) and returnsExitCode.GenericFailure.The existing
OnCommandLineOptionMessagesFailFast safety net is retained as an invariant guard for IPC-layer issues, but should no longer be reached for user-error scenarios.Tests
Added 10 new test cases in
GivenDotnetTestBuildsAndRunsHelp.cs:PassingHelpOrListTestsViaTestingPlatformCommandLineArguments_ShouldFailWithClearError(6 cases:--help/-?/--list-tests× Debug / Release)PassingHelpOrListTestsViaUnmatchedTokens_ShouldFailWithClearError(4 cases:--help/--list-tests× Debug / Release;-?excluded because the CLI parser intercepts it)All 10 new tests pass; existing baseline tests (
RunHelpOnTestProject_ShouldReturnExitCodeSuccess,DiscoverTestProjectWithCustomRunArguments*) still pass.Localization
Added 4 entries to
CliCommandStrings.resxand auto-populated the 13.xlffiles viadotnet build /t:UpdateXlf.