Skip to content

Include full command line in MTP validation errors#8255

Open
Copilot wants to merge 5 commits into
mainfrom
copilot/mtp-command-line-validation
Open

Include full command line in MTP validation errors#8255
Copilot wants to merge 5 commits into
mainfrom
copilot/mtp-command-line-validation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

Bug Fix

Invalid MTP command-line errors only reported the failing option, which is insufficient when the invoked command is hidden by test infrastructure or CI logs.

  • Command context

    • Preserve the original parsed command line in CommandLineParseResult.
    • Append it to relevant validation failures.
  • Validation coverage

    • Applies to parser errors, unknown options, invalid arity, and invalid option arguments.
    • Adds targeted coverage for --dotnet-test-pipe arity failures with a test DLL/tool name.

Example output:

Option '--dotnet-test-pipe' from provider 'Platform command line provider' (UID: PlatformCommandLineProvider) expects at most 1 arguments
Command line: TestProject.dll --dotnet-test-pipe pipe extra

Copilot AI requested review from Copilot and removed request for Copilot May 15, 2026 12:23
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 15, 2026 12:34
Copilot AI changed the title [WIP] Fix MTP command-line validation error messages Include full command line in MTP validation errors May 15, 2026
Copilot AI requested a review from Evangelink May 15, 2026 12:35
@Evangelink Evangelink marked this pull request as ready for review May 15, 2026 13:30
Copilot AI review requested due to automatic review settings May 15, 2026 13:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Augments MTP command-line validation errors to include the full original command line, making failures easier to diagnose when the invocation is hidden by surrounding test/CI infrastructure.

Changes:

  • CommandLineParseResult now carries the original argv joined as a CommandLine string, populated by Parser from a snapshot taken before parsing mutates the argument list.
  • CommandLineOptionsValidator appends a localized Command line: {0} line (new CommandLineValidationCommandLine resource) to parser errors, unknown-option errors, arity errors, and option-argument validation errors.
  • Tests updated for the new error format and a new --dotnet-test-pipe arity-failure test exercises the tool-name + extra-argument case; resx + xlf resources updated across all locales.
Show a summary per file
File Description
src/Platform/Microsoft.Testing.Platform/CommandLine/ParseResult.cs Replaces primary constructor with explicit constructors; adds internal CommandLine property storing the joined original args.
src/Platform/Microsoft.Testing.Platform/CommandLine/Parser.cs Snapshots args before parsing and forwards them to the new internal constructor.
src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.cs Wraps invalid validation results with the new Command line: suffix via AddCommandLine/InvalidWithCommandLine helpers.
src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx Adds CommandLineValidationCommandLine resource string.
src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.*.xlf Generated new-state translation entries for the new resource across all locales.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs Updates expected error strings and adds tool-name + arity test.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ArgumentArityTests.cs Updates expected error strings to include the appended command line.

Copilot's findings

  • Files reviewed: 19/19 changed files
  • Comments generated: 0

Evangelink and others added 2 commits May 16, 2026 13:37
const string wildcardMatchPattern = $"""
Microsoft.Testing.Platform v*
Unknown option '--{UnknownOption}'
Command line: *
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot let's use real content and not wildcard here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 1337c8a by asserting the exact command line instead of using a wildcard.

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 16, 2026 14:32
Copilot AI requested a review from Evangelink May 16, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MTP command-line validation should include the whole command used for running

4 participants