Skip to content

Use args passed to CreateBuilderAsync in GetCurrentExecutableInfo - #8570

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/fix-executable-info-args
May 25, 2026
Merged

Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/fix-executable-info-args

Conversation

@Evangelink

Copy link
Copy Markdown
Member

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.

Fix

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.

Repro from the issue

if (args.Length == 0)
{
    args = ["--retry-failed-tests", "1"];
}

var builder = await TestApplication.CreateBuilderAsync(args);
SelfRegisteredExtensions.AddSelfRegisteredExtensions(builder, args);
using var app = await builder.BuildAsync();
return await app.RunAsync();

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 CurrentTestApplicationModuleInfoTests covering the AppHost and dotnet muxer paths with and without user-passed args (5 new tests). 290 related unit tests continue to pass.

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>
Copilot AI review requested due to automatic review settings May 25, 2026 14:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 args passed to CreateBuilderAsync into CurrentTestApplicationModuleInfo and prefers them when building ExecutableInfo.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>
@Evangelink
Amaury Levé (Evangelink) merged commit 585be0c into main May 25, 2026
39 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/fix-executable-info-args branch May 25, 2026 17:05
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] GetCurrentExecutableInfo shouldn't calculate command line arguments via Environment

2 participants