Skip to content

Restore MTP startup diagnostics under dotnet test - #11971

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/mtp-startup-diagnostics
Oct 16, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/mtp-startup-diagnostics

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Pull request

Summary

Restore MTP startup diagnostics under native dotnet test. Command-line validation can fail before the pipe connection exists, leaving the SDK with only exit code 5 and no explanation.

Fixes #11964.

Design and decision record

The issue investigation provides the rationale for this regression fix; no separate feature design record is needed.

Write warning/error diagnostics through the existing console service only when no dotnet-test connection is registered. Preserve the early-host/no-handshake lifecycle and exit code 5 rather than moving connection establishment ahead of validation. Once connected, negotiated forwarding and legacy-protocol suppression are unchanged; ordinary informational output remains suppressed.

Demonstration

Reproduced with SDK 10.0.402 and MSTest 4.5.1. Keeping that SDK/framework and consuming locally packed MTP/MSBuild 2.6.0-dev restores the diagnostic:

Before (MTP 2.5.1):
  Zero tests ran
  Exit code: 5
  [no provider diagnostic]

After:
  Exit code: 5
    Standard output: Option '--my-option' is declared by multiple providers: 'ProviderA', 'ProviderB'

The transcript abbreviates surrounding SDK summary/path lines; both commands exited 5. Text is clearer than screenshots for this diagnostic-only change.

# In the issue's reproduction project, using an isolated NuGet cache:
& 'C:\Program Files\dotnet\dotnet.exe' test --project Repro.csproj '-bl:baseline-sdk-reproduced.binlog'
# With explicit references to the locally packed MTP and MSBuild 2.6.0-dev packages:
& 'C:\Program Files\dotnet\dotnet.exe' test --project Repro.csproj '-bl:fixed-duplicate-sdk10.binlog'

Validation and regression proof

Tested source: base 3ebfc8dc5cb48afe704cac6bce1b5ef0b834a12e plus the changes committed as bc3491eecf137534f2b76584f8e7db182b920188. Committed source/test bytes were verified unchanged after validation.

Passed locally: all five MTP package TFMs; 8 net8.0 unit cases and 7 net11.0 acceptance cases, all Release, with no failures or skips. Acceptance discovery and the execution verifier reconciled all seven expected cases. TRX, JUnit, and CTRF reports were parsed and matched the executed counts.

The real shipping SDK 10.0.402 also passed/discovered the one-test normal consumer, displayed diagnostics for unknown options, missing extension packages and -m:4, and correctly aggregated one passing module with one invalid module: parent exit 5, one passing test, and one valid-module TRX. It was not necessary to change the SDK or transfer the issue.

Recorded commands and outcomes

Repository SDK: 12.0.100-alpha.1.26509.101, bootstrapped through eng\build.ps1. Commands ran from the task worktree root with process-local DOTNET_ROOT pointing to .dotnet and MSBuild server reuse disabled. Variables below abbreviate the original absolute paths to the same repository result directories.

$repo = (Get-Location).Path
$unit = 'test\UnitTests\Microsoft.Testing.Platform.UnitTests\Microsoft.Testing.Platform.UnitTests.csproj'
$acceptance = 'test\IntegrationTests\Microsoft.Testing.Platform.Acceptance.IntegrationTests\Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj'
$filter = 'FullyQualifiedName~DotnetTestPipeStartupErrorTests|FullyQualifiedName~DotnetTestPipeDisplayMessageForwardingTests|FullyQualifiedName~DotnetTestPipe_ChildEmitsNoStdoutOrStderrForPassingRun_Baseline'

# Exit 0: complete net8.0/net9.0/net10.0/net11.0/netstandard2.0 package.
& .\.dotnet\dotnet.exe pack src\Platform\Microsoft.Testing.Platform\Microsoft.Testing.Platform.csproj -c Release --no-restore '-bl:artifacts\green-core-pack.binlog' -v minimal

# Exit 0: 8 executed, 8 passed, 0 skipped.
& .\.dotnet\dotnet.exe test --project $unit --no-restore -c Release -f net8.0 --filter FullyQualifiedName~DotnetTestPassthroughOutputDeviceTests -p:UsingDotNetTest=true -p:EnableCodeCoverage=false "-p:ArtifactsTestResultsDir=$repo\artifacts\TestResults\startup-green-final" '-bl:artifacts\green-unit-final.binlog' --show-test-results all

# Exit 0: build succeeded with zero warnings/errors.
& .\.dotnet\dotnet.exe build $acceptance --no-restore -c Release -f net11.0 --disable-build-servers '-bl:artifacts\green-acceptance-build-final.binlog' -v minimal

# Exit 0: 7 executed, 7 passed, 0 skipped.
& .\.dotnet\dotnet.exe test --project $acceptance --no-build -c Release --filter $filter -p:UsingDotNetTest=true -p:EnableCodeCoverage=false -p:TestRunnerAdditionalArguments= "-p:ArtifactsTestResultsDir=$repo\artifacts\TestResults\startup-acceptance-green" '-bl:artifacts\green-startup-acceptance.binlog' --show-test-results all

Baseline acceptance used the same selection and assertions against the separately packed pre-fix product, with results in startup-acceptance-red-proven: exit 2, four intended missing-diagnostic assertion failures and three passing preservation cases.

The final unit counterfactual substituted the original early-return behavior during compilation in isolated outputs, retaining the exact final tests. $comparisonTargets denotes the task-owned UseBaselineOutputDevice.targets file which replaced only that compile input:

# Exit 2: 8 executed, 6 passed, 2 failed at the missing-console-write verification.
& .\.dotnet\dotnet.exe test --project $unit -c Release -f net8.0 --filter FullyQualifiedName~DotnetTestPassthroughOutputDeviceTests -p:UsingDotNetTest=true -p:EnableCodeCoverage=false "-p:ArtifactsDir=$repo\artifacts\startup-unit-counterfactual\" "-p:CustomBeforeMicrosoftCommonTargets=$comparisonTargets" "-p:ArtifactsTestResultsDir=$repo\artifacts\TestResults\startup-unit-counterfactual" '-bl:artifacts\counterfactual-unit-final.binlog' --show-test-results all

The counterfactual import produced nonfatal duplicate-import warnings; detection came from the two executed assertions, not those warnings or setup failures.

Baseline/fixed packages used isolated consumer caches. All four generated acceptance DLLs matched the fixed packed payload; the shipping SDK consumer's cached nupkg and executed DLL were also hash-verified.

MTP 2.6.0-dev package SHA-256
Baseline 2F3A3659090AD9E7F3CF04FAAF5E6FC22E2DDA71466E95A3BA87274ECD29CB28
Fixed DD6682477FC9499C6A745FE87ADA97F82F6C26974823C329C2104BFCB61723FB

Logs, TRX/JUnit/CTRF reports, package provenance and archived consumer restore metadata are retained in the Copilot session; they are not published CI artifacts.

Limitations: Windows-only local execution; no remote CI, Ubuntu or servicing-branch validation. A broader Windows solution pack with UAP deliberately excluded failed the MSTest package file-count audit because the expected UAP assets were absent. That attempt is not counted as successful full-solution packaging; the owning MTP package build passed.

Test-value evidence

Contract / test Without fix With fix
DotnetTest_CommandLineValidationFailure_ShowsHostDiagnostic: StartupError_UnknownOption, StartupError_MissingExtension, StartupError_DuplicateProviders, StartupError_MalformedConfiguration Executed: all 4 failed specifically on missing diagnostic output; native child exit 5 was preserved. Executed: all 4 passed.
DisplayAsync_WithDiagnosticButNoConnection_WritesToConsole (False/True) Executed targeted counterfactual: both failed because the exact console write never occurred. Executed: both passed, including exactly-once verification.
Six unchanged unit cases and the three normal/protocol 1.2/protocol 1.3 acceptance guards Executed: all 9 passed. Executed: all 9 passed; connected hosts emit no stdout/stderr.

Write early warning and error diagnostics to the console before the dotnet test connection exists, preserving normal pipe suppression and negotiated forwarding. Add native-CLI regressions and compatibility guards.

Fixes #11964.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: fadefeee-c287-4412-8c04-6b0942981e1f
Copilot AI balanced review requested due to automatic review settings October 16, 2026 08:47
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Oct 16, 2026

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.

🟢 Approval recommended

The narrow fallback preserves existing protocol behavior, and focused regression coverage supports the change with no unresolved blocking findings.

0 open findings

What changed in this PR

Restores MTP startup diagnostics under native dotnet test, addressing #11964 without changing handshake timing or exit codes.

Changes:

  • Writes warnings and errors to the console when no dotnet-test connection is registered.
  • Adds regression coverage for four startup-validation failures.
  • Strengthens checks that connected hosts keep stdout and stderr empty.

Test-value evidence: For revision bc3491eecf137534f2b76584f8e7db182b920188, the PR reports 8 passing unit cases and 7 passing acceptance cases, with targeted failures without the fix. These execution artifacts were not independently inspected; the supplied assertions statically support regression detection.

🟢 Confidence at a glance — MTP startup diagnostics

The fallback is narrowly scoped, preserves connected-protocol behavior, and has focused regression assertions. Reported execution was Windows-only.

File Description
test/​UnitTests/​Microsoft.Testing.Platform.UnitTests/​OutputDevice/​DotnetTestPassthroughOutputDeviceTests.cs Verifies exact, once-only diagnostic console writes.
test/​IntegrationTests/​Microsoft.Testing.Platform.Acceptance.IntegrationTests/​DotnetTestPipe/​DotnetTestPipeStartupErrorTests.cs Covers four startup failures through native dotnet test.
test/​IntegrationTests/​Microsoft.Testing.Platform.Acceptance.IntegrationTests/​DotnetTestPipe/​DotnetTestPipeDisplayMessageForwardingTests.cs Checks connected hosts produce no console output.
src/​Platform/​Microsoft.Testing.Platform/​OutputDevice/​OutputDeviceManager.cs Updates comments describing the startup fallback.
src/​Platform/​Microsoft.Testing.Platform/​OutputDevice/​DotnetTestPassthroughOutputDevice.cs Adds console fallback for warnings and errors before connection registration.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot 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.

🧪 Test quality review — PR #11971

Compared merge base 3ebfc8dc5cb48afe704cac6bce1b5ef0b834a12e with head
bc3491eecf137534f2b76584f8e7db182b920188. Evidence applies to this head, not
every intermediate commit.

Test-value evidence

Traced the production diff: DotnetTestPassthroughOutputDevice.ForwardDisplayMessageAsync now writes error/warning text to IServiceProvider.GetConsole() when no DotnetTestConnection is resolved (previously it silently dropped). OutputDeviceManager.cs's change is comment-only. The error/warning path is reached from TestHostBuilder.CommonServices.cs (ErrorMessageOutputDeviceData on command-line validation failures), confirming the test scenarios exercise a real production call chain.

Contract / test case Counterfactual Without behavior Correct implementation Evidence / gap
DotnetTestPassthroughOutputDeviceTests.DisplayAsync_WithDiagnosticButNoConnection_WritesToConsole(false/true) — warning/error written to console when no connection exists Pre-fix: early-return without touching IConsole static: predicts the strict-mock console.Verify(WriteLine, Times.Once) fails (no call made) static: predicts pass — WriteLine called exactly once with the exact message, VerifyNoOtherCalls guards against extra writes Static prediction only; PR description reports a matching executed counterfactual (2 failed→2 passed) but this review did not independently execute it
DotnetTestPipeStartupErrorTests.DotnetTest_CommandLineValidationFailure_ShowsHostDiagnostic (4 DataRows: unknown option, missing extension, duplicate providers, malformed config) — startup diagnostic surfaces through native dotnet test before the pipe handshake Pre-fix: diagnostic dropped, only exit code 5 observed static: predicts AssertOutputContains(expectedDiagnostic) fails on the dotnet test-driven run (direct-host run already passed pre-fix since it doesn't go through the pipe device) static: predicts pass — exit code InvalidCommandLine plus diagnostic text on both the direct-host and dotnet test-wrapped runs, and Usage {AssetName} is absent from stdout Static prediction only; PR description reports a matching executed counterfactual (4 failed→4 passed) but this review did not independently execute it
DotnetTestPipeDisplayMessageForwardingTests.DotnetTestPipe_WhenSdkSupports130_* / *_WhenSdkOnlySupports120_* — connected hosts (protocol 1.2.0 and 1.3.0) must still produce no direct console output Refactor/strengthening: the fallback is correctly gated on "no connection" so a connected host's warnings/errors still route only through the pipe, never the console not applicable — strengthening addition to already-passing tests; no connection path exists to resolve to a console write executed-equivalent static prediction: pass — StandardOutput/StandardError both string.Empty New negative assertions guard against the console fallback firing when a connection is registered; a plausible regression (e.g. an inverted or unconditioned null-check) would be caught here

No unassessed contract groups; the two changed source files map fully to the three test files above.

🧵 Parallel safety

STATUS: CLEAN (delegated to parallel-safety-reviewer). Microsoft.Testing.Platform.Acceptance.IntegrationTests runs MethodLevel parallelization; Microsoft.Testing.Platform.UnitTests has no assembly-level parallelization. The new DotnetTestPipeStartupErrorTests's 4 DataRow cases each call TestAsset.GenerateAssetAsync with a shared AssetName constant, but TestAsset always allocates a fresh randomized TempDirectory, so concurrent DataRow executions build to physically distinct bin/obj trees — no [DoNotParallelize] is needed. DotnetCli.RunAsync passes workingDirectory per-process (never mutates a shared CWD), and the one relative path (modulePath) resolves against that per-process working directory. No findings (Critical=0, High=0, Warning=0, Info=0).

Per-test assessment

Pseudo-mutation evidence below consists of static predictions, not executed mutation results.

ResultQualityTestNotesHow to improve
Pass A (90–100) new DotnetTestPassthroughOutputDeviceTests.
DisplayAsync_
WithDiagnosticButNoConnection_
WritesToConsole
Strict mock verifies exact message written exactly once; VerifyNoOtherCalls rules out extra writes. None
Pass A (90–100) new DotnetTestPipeStartupErrorTests.
DotnetTest_
CommandLineValidationFailure_
ShowsHostDiagnostic
Exit code, diagnostic text, and absence of leaked usage text are all checked across both entry points. None
Pass A (90–100) mod DotnetTestPipeDisplayMessageForwardingTests.
DotnetTestPipe_
WhenSdkSupports130_
ForwardsSessionWarningAndErrorAsDisplayMessages
New assertions confirm connected hosts stay silent on stdout/stderr, complementing existing forwarding checks. None
Pass A (90–100) mod DotnetTestPipeDisplayMessageForwardingTests.
DotnetTestPipe_
WhenSdkOnlySupports120_
DoesNotForwardDisplayMessages
Same console-silence guard added for the legacy-protocol (1.2.0) path. None

This advisory review is heuristic and non-blocking.

Re-run the combined review with /review-tests, or only the parallel-safety
specialist with /parallel-audit.

🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · auto · 327.4 AIC · ⌖ 9.77 AIC · ⊞ 22.4K · ◷

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 16, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 16, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 16, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Oct 16, 2026
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Final test-triage resolution — Azure Pipelines build 1637970

This supersedes the earlier preliminary comment from the Linux Release leg.

1. Aspire NU1902 restore failure (Linux Release) — not actionable against this PR

MSTest.Acceptance.IntegrationTests.AspireSdkTests.EnableAspireProperty_WhenUsingRunner_AllowsToRunAspireTests and ...WhenUsingVSTest_AllowsToRunAspireTests both failed in ClassInitialize with the same NU1902 restore error for the generated AspireProject test asset:

AspireProject.csproj : error NU1902: Warning As Error: Package 'MessagePack' 2.5.302 has a known moderate severity vulnerability, https://github.com/advisories/GHSA-qhrr-8q5h-9q3h

PR #11971 only touches DotnetTestPassthroughOutputDevice/OutputDeviceManager and their tests — unrelated to this failure. The repo's Directory.Packages.props pins MessagePack to 3.1.10, but the dynamically generated AspireProject asset only references Microsoft.NET.Test.Sdk directly and pulls MessagePack 2.5.302 transitively via the Aspire testing SDK, outside central package management for that generated project. No issue is warranted for this PR; this looks like a pre-existing test-asset/dependency-pinning gap worth a separate look, but I did not find an existing open issue tracking it and recurrence-across-independent-commits evidence for this exact PR isn't the right vehicle to create one.

2. Windows Release leg — HangDumpTests.QueryOnceAndDumpTree_StartsEveryDumpBeforeAwaitingCompletion — evidence incomplete, cannot confirm

The pipeline timeline shows this test failed on the Windows Release leg, but the TestResults_Windows_Release_Attempt1 artifact failed to download (artifactDownloadFailures: 1, evidenceIncomplete: true in the collected metadata), so no corresponding CTRF/TRX record exists in the collected evidence to analyze the failure signature, retries, or correlate with history. I cannot report this as clean — it remains inconclusive for lack of evidence. Re-running the Windows Release leg, or re-fetching that artifact, would be needed to triage it further.

3. Other Windows failures (retry-probe assets) — expected, not defects

WinUIMtpPackagedApp.UnitTest1.RetryFailsFirstAttempt, NativeTests.Outcome, and PackagedWinUI.PackagedWinUITestCases.RetryTestMethod_PassesOnSecondAppContainerHost fail-then-pass by design — these are intentional MTP Retry-extension probe tests (their messages explicitly say "This probe deliberately fails the first retry attempt and passes the next one" / "Retry must activate a second host"). The same fail-then-pass pattern recurs identically across all available history builds (1637755, 1637752, 1637326), confirming this is expected behavior of the retry probes, not a regression.

No issue created: the only unresolved signal (HangDumpTests) lacks evidence due to the missing Windows Release artifact, and the Aspire/NU1902 failure is unrelated to this PR's diff. No durable, actionable, PR-attributable regression was identified.

🤖 Automated content by GitHub Copilot. Generated by the Pipeline Test Triage workflow. · copilot · auto · 139.8 AIC · ⌖ 5.06 AIC · ⊞ 9.9K

@Evangelink
Amaury Levé (Evangelink) merged commit a93dbf2 into main Oct 16, 2026
32 of 35 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/mtp-startup-diagnostics branch October 16, 2026 12:32
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Oct 16, 2026
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.

Regression in Microsoft.Testing.Platform 2.3.0: dotnet test no longer shows the test host's command-line validation errors

3 participants