Repository navigation
Use args passed to CreateBuilderAsync in GetCurrentExecutableInfo - #8570
Merged
Amaury Levé (Evangelink) merged 2 commits intoMay 25, 2026
Merged
Conversation
Fixes #5239. Previously, CurrentTestApplicationModuleInfo.GetCurrentExecutableInfo derived its arguments from Environment.GetCommandLineArgs(). If a custom Main mutated the args before forwarding them to TestApplication .CreateBuilderAsync (for example to inject `--retry-failed-tests 1` as a default), the platform options reflected the mutation but the executable info did not. Extensions like Retry that re-launch the test host using these arguments would then throw. CurrentTestApplicationModuleInfo now accepts the args passed to CreateBuilderAsync and uses them when computing GetCurrentExecutableInfo. The dll path is still recovered from Environment.GetCommandLineArgs()[0] for the dotnet/mono muxer cases, preserving the existing behavior when running under dotnet.exe. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an argument mismatch in Microsoft.Testing.Platform where CurrentTestApplicationModuleInfo.GetCurrentExecutableInfo() previously derived arguments from Environment.GetCommandLineArgs() instead of the args actually passed to TestApplication.CreateBuilderAsync, which could break extensions (e.g., Retry) that relaunch the test host.
Changes:
- Plumbs the
argspassed toCreateBuilderAsyncintoCurrentTestApplicationModuleInfoand prefers them when buildingExecutableInfo.Arguments. - Preserves the dotnet/mono muxer behavior by still recovering the DLL path from
Environment.GetCommandLineArgs()[0]. - Adds unit tests for AppHost and dotnet muxer scenarios covering passed vs environment args.
Show a summary per file
| File | Description |
|---|---|
| src/Platform/Microsoft.Testing.Platform/Services/CurrentTestApplicationModuleInfo.cs | Accepts passed-in args and updates GetCurrentExecutableInfo() to prefer them, with special handling for dotnet/mono muxers. |
| src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs | Passes args from CreateBuilderAsync into CurrentTestApplicationModuleInfo and TestApplicationBuilder. |
| src/Platform/Microsoft.Testing.Platform/Builder/TestApplicationBuilder.cs | Threads args into the CurrentTestApplicationModuleInfo used by the internal TestHostBuilder. |
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/CurrentTestApplicationModuleInfoTests.cs | Adds coverage for AppHost and dotnet muxer argument selection behavior. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Snapshot commandLineArguments in the constructor so later mutation of the caller's array does not affect GetCurrentExecutableInfo. - Add unit tests for the mono muxer code path (no passed args, with passed args, and empty envArgs edge case) plus a dotnet-muxer empty envArgs case and a snapshot/defensive-copy test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Amaury Levé (Evangelink)
deleted the
dev/amauryleve/fix-executable-info-args
branch
May 25, 2026 17:05
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 #5239.
Previously,
CurrentTestApplicationModuleInfo.GetCurrentExecutableInfoderived its arguments fromEnvironment.GetCommandLineArgs(). If a customMainmutated the args before forwarding them toTestApplication.CreateBuilderAsync(for example, to inject--retry-failed-tests 1as a default), the platform options reflected the mutation but the executable info did not. Extensions like Retry that re-launch the test host using these arguments would then throw.Fix
CurrentTestApplicationModuleInfonow accepts the args passed toCreateBuilderAsyncand uses them when computingGetCurrentExecutableInfo. The DLL path is still recovered fromEnvironment.GetCommandLineArgs()[0]for thedotnet/monomuxer cases, preserving the existing behavior when running underdotnet.exe.Repro from the issue
With the fix, the Retry extension now sees
[--retry-failed-tests, 1]in the executable info regardless of what was on the OS command line.Tests
Added
CurrentTestApplicationModuleInfoTestscovering the AppHost and dotnet muxer paths with and without user-passed args (5 new tests). 290 related unit tests continue to pass.