Fix GetCurrentExecutableInfo to use CreateBuilderAsync arguments instead of Environment.GetCommandLineArgs #6180
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.
The
CurrentTestApplicationModuleInfo.GetCurrentExecutableInfo()
method was always usingEnvironment.GetCommandLineArgs()
to retrieve command line arguments, ignoring any custom arguments passed toTestApplication.CreateBuilderAsync()
. This caused issues with extensions like retry that depend on seeing the actual arguments used to configure the test application.Problem
When users write custom code to modify arguments before calling
CreateBuilderAsync()
:The retry extension would fail because
GetCurrentExecutableInfo()
returned the original empty command line arguments fromEnvironment.GetCommandLineArgs()
, not the modified args["--retry-failed-tests", "1"]
passed toCreateBuilderAsync()
.Solution
This PR implements a service-based approach to capture and provide access to the original arguments passed to
CreateBuilderAsync()
:ICommandLineArgumentsProvider
interface and implementation to store the original argumentsTestApplication
→TestApplicationBuilder
→TestHostBuilder
GetCurrentExecutableInfo()
to intelligently combine custom arguments with environment argumentsKey Features
Smart Argument Handling: The implementation correctly handles different execution scenarios:
Example transformations:
Testing
Added comprehensive unit tests covering:
The fix ensures that retry and other extensions now correctly see and use the arguments that were actually passed to
CreateBuilderAsync()
, while maintaining full compatibility with dotnet execution scenarios.Fixes #5239.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.