Skip to content

Report PID-qualified testhost controller pipe env var#8498

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-pipe-connection-failure
Open

Report PID-qualified testhost controller pipe env var#8498
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-pipe-connection-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 22, 2026

When the testhost controller pipe-name lookup failed, the error reported the base environment variable instead of the PID-qualified key that was actually read. This made startup diagnostics point at the wrong variable.

  • Diagnostic fix
    • Report the computed TESTINGPLATFORM_TESTHOSTCONTROLLER_PIPENAME_<pid> key in the missing pipe-name exception.
string pipeEnvironmentVariable =
    $"{EnvironmentVariableConstants.TESTINGPLATFORM_TESTHOSTCONTROLLER_PIPENAME}_{testHostControllerInfo.GetTestHostControllerPID()}";

string pipeName = environment.GetEnvironmentVariable(pipeEnvironmentVariable)
    ?? throw new InvalidOperationException(
        $"Unexpected null pipe name from environment variable '{pipeEnvironmentVariable}'");
  • Regression coverage
    • Added a focused unit test that verifies the exception message includes the PID-qualified environment variable name.

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 22, 2026 12:49
Copilot AI changed the title [WIP] Fix pipe connection failure error message Report PID-qualified testhost controller pipe env var May 22, 2026
Copilot AI requested a review from Evangelink May 22, 2026 12:50
@Evangelink Evangelink marked this pull request as ready for review May 22, 2026 13:49
Copilot AI review requested due to automatic review settings May 22, 2026 13:49
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

Fixes a startup diagnostic in Microsoft.Testing.Platform where a missing testhost-controller pipe-name error reported the wrong environment variable key, and adds a unit test to prevent regressions.

Changes:

  • Update the thrown exception message to include the PID-qualified environment variable name that was actually read.
  • Add a unit test asserting the exception message contains the PID-qualified key when the pipe name is missing.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Platform.UnitTests/TestHostBuilderTests.cs Adds regression test verifying the PID-qualified env-var name is present in the thrown exception message.
src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.Utilities.cs Fixes the exception message to report the PID-qualified pipe env-var key instead of the base constant.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

SystemEnvironment environment)
{
using CTRLPlusCCancellationTokenSource cancellationTokenSource = new();
var connectTask = (Task)method.Invoke(null, [cancellationTokenSource, new NopLogger(), testHostControllerInfo, configuration, environment])!;

try
{
MethodInfo method = typeof(TestHostBuilder).GetMethod("ConnectToTestHostProcessMonitorIfAvailableAsync", BindingFlags.NonPublic | BindingFlags.Static)!;
@Evangelink
Copy link
Copy Markdown
Member

@copilot address review comments

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 22, 2026

@copilot address review comments

Addressed in c0f71cb. The test now fails clearly if the reflected method cannot be found and unwraps synchronous TargetInvocationException from MethodInfo.Invoke while preserving the original exception stack.

Copilot AI requested a review from Evangelink May 22, 2026 16:03
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 Core Analysis] Pipe connection failure mentions the wrong environment variable

3 participants