Inject runsettings environment variables on the MTP execution path - #16283
Merged
Azat Mukhametshin (azat-msft) merged 3 commits intoJul 14, 2026
Merged
Conversation
On the MTP-as-testhost path the MTP application is its own host, so the classic testhost code that applies runsettings RunConfiguration/EnvironmentVariables was bypassed and those variables never reached the test process (only inherited process env vars did). MtpProxyExecutionManager now reads them via InferRunSettingsHelper.GetEnvironmentVariables and merges them into the launch environment before BeforeTestRun, so datacollector-provided profiler variables still win on collision (matching the classic ordering). Adds acceptance test RunMtpApplicationInjectsRunSettingsEnvironmentVariables and a guarded RunSettingsEnvironmentVariableIsInjected test in the MTP asset; existing MTP summary counts updated for the added asset test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fb7de7a6-b8a1-4ebb-8266-5c5a948f245c
Copilot started reviewing on behalf of
Azat Mukhametshin (azat-msft)
July 14, 2026 10:30
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a gap in the Microsoft.Testing.Platform (MTP) execution path where .runsettings RunConfiguration/EnvironmentVariables were not being applied to the self-hosted MTP process launched by vstest.console, aligning behavior with the classic testhost-based path.
Changes:
- Inject runsettings environment variables into the MTP application launch via
InferRunSettingsHelper.GetEnvironmentVariables, before datacollector initialization so profiler vars still take precedence on collisions. - Add an acceptance test that validates runsettings env var injection end-to-end using a guarded asset test.
- Update existing MTP acceptance test expected summary counts to reflect the added asset test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/TestAssets/MtpMSTestProject/UnitTests.cs | Adds a guarded test that asserts the runsettings-injected env var is visible inside the MTP process. |
| test/Microsoft.TestPlatform.Acceptance.IntegrationTests/MtpUnderVstestTests.cs | Adds acceptance coverage for runsettings env var injection and updates expected result counts. |
| src/Microsoft.TestPlatform.CrossPlatEngine/Client/MTP/MtpProxyExecutionManager.cs | Implements runsettings env var injection for the MTP launch path prior to datacollector env var merging. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Azat Mukhametshin (azat-msft)
July 14, 2026 10:49
View session
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Azat Mukhametshin (azat-msft)
July 14, 2026 10:59
View session
Jakub Jareš (nohwnd)
approved these changes
Jul 14, 2026
Azat Mukhametshin (azat-msft)
merged commit Jul 14, 2026
4294cde
into
microsoft:main
20 checks passed
Azat Mukhametshin (azat-msft)
added a commit
to azat-msft/vstest
that referenced
this pull request
Jul 14, 2026
- RunMtpApplicationSurfacesPerTestStandardOutput asserted the old 4-test summary (2,1,1); the shared MtpMSTestProject asset gained a 5th test (RunSettingsEnvironmentVariableIsInjected), so the run is (3,1,1). This is a semantic collision between microsoft#16283 and microsoft#16284 that only surfaces when both are on main. Update the expected summary. - Address review feedback: extract the near-identical MTP discovery routine from MtpProxyDiscoveryManager and MtpProxyExecutionManager into a single MtpClientHelpers.DiscoverSourceTests helper so the two paths cannot drift (timeouts, cancellation, sentinel drain, env-var policy). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 61d9a1c3-3c9f-4dab-8ba3-5baba8d55ed6
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.
Problem
On the
vstest.consolepath that runs a Microsoft.Testing.Platform (MTP) app as its own testhost (#16201), environment variables declared in a.runsettingsRunConfiguration/EnvironmentVariablesblock were not passed to the MTP test process. Inherited process env vars reached the app, but the documented runsettings-driven injection was silently dropped.Root cause
On the classic path
ProxyOperationManagerreads the runsettings env vars and merges them into the testhostProcessStartInfo. The MTP application is its own host, so that code is bypassed andMtpProxyExecutionManageronly ever populated the launch environment with datacollector-provided profiler variables.Fix
MtpProxyExecutionManagernow reads the runsettings env vars viaInferRunSettingsHelper.GetEnvironmentVariablesand merges them into the launch environment beforeBeforeTestRun, so datacollector profiler variables still win on collision (matching the classic ordering).Test
New acceptance test
RunMtpApplicationInjectsRunSettingsEnvironmentVariablesruns the MTP app with a runsettings file that injectsMTP_FROM_RUNSETTINGSand a guardedRunSettingsEnvironmentVariableIsInjectedasset test (opted in via aCHECK_RUNSETTINGS_VARprocess env var inherited by the host). The guarded test passes only when the runsettings value actually reaches the host, so a broken injection turns the 3/1/1 summary into 2/2/1. Existing MTP summary counts are updated for the added asset test.Validation
RunMtpApplicationInjectsRunSettingsEnvironmentVariablesand the count-updatedRunMtpApplicationExecutesTestsOverMtpProtocol: 4/4 matrix cases pass.Microsoft.TestPlatform.CrossPlatEngineand the acceptance project: clean.