Skip to content

Add HTTP transport for WebAssembly test hosts - #55672

Merged
Evangelink merged 2 commits into
dotnet:mainfrom
Evangelink:dev/amauryleve/investigate-blazor-testing
Aug 7, 2026
Merged

Add HTTP transport for WebAssembly test hosts#55672
Evangelink merged 2 commits into
dotnet:mainfrom
Evangelink:dev/amauryleve/investigate-blazor-testing

Conversation

@Evangelink

Copy link
Copy Markdown
Member

WebAssembly test hosts cannot connect to the named-pipe transport currently used by dotnet test. Microsoft.Testing.Platform now supports the existing dotnettestcli binary protocol over authenticated HTTP, so the SDK needs a matching gateway to enable browser and WASI test execution.

Summary

  • host a unique authenticated loopback HTTP endpoint for each WebAssembly test application
  • route the existing protocol frames through the normal dotnet test handlers without changing the wire contract
  • preserve named pipes for desktop test applications
  • support browser CORS and Private Network Access preflight
  • keep the endpoint and bearer token out of process arguments by using an atomically owner-only response file
  • skip WebAssembly artifact post-processing until a browser-aware merge host exists
  • add a Blazor WebAssembly MSTest probe that documents the remaining browser lifecycle integration

The HTTP path is covered both at the gateway boundary and end-to-end with a real MTP application reporting a passing test through dotnet test. The remaining Blazor-specific work is for Blazor Gateway to consume the bootstrap response file, launch the browser, and provide those values to MTP inside the page.

Validation

  • focused HTTP gateway, launch, protocol negotiation, desktop pipe, WASI/browser selection, and artifact-processing tests
  • end-to-end dotnet test execution through the MTP HTTP client
  • focused Blazor WebAssembly sample build test

Related to #54091

Route browser and WASI Microsoft.Testing.Platform hosts through an authenticated loopback HTTP gateway while preserving named pipes for desktop test applications. Keep bootstrap secrets in an owner-only response file and add focused protocol, security, lifecycle, and integration coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b1bfb191-93c7-4891-85ce-098b0676f861
Copilot AI review requested due to automatic review settings August 7, 2026 10:43
@Evangelink
Evangelink requested review from a team as code owners August 7, 2026 10:43
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

Adds an authenticated loopback HTTP transport path for dotnet test when executing WebAssembly (browser/WASI) test hosts, allowing the existing dotnettestcli binary protocol frames to be routed through the current handlers while preserving named pipes for desktop scenarios.

Changes:

  • Introduces HttpTestHostGateway (authenticated HTTP + CORS/PNA preflight) and ProtocolMessageSerializer to round-trip protocol frames over HTTP.
  • Updates TestApplication to select HTTP vs named-pipe transport based on the module runtime identifier, and writes bootstrap arguments (endpoint + token) to an owner-only response file.
  • Adds targeted regression coverage (gateway behavior, transport selection, response-file redaction/permissions/cleanup, artifact post-processing skip for WASM) plus a Blazor WASM MSTest “probe” asset and build test.
Show a summary per file
File Description
test/TestAssets/TestProjects/DotnetTestDevices/Program.cs Detects whether the HTTP transport was selected (including via response file) for device-orchestration test coverage.
test/TestAssets/TestProjects/DotnetTestDevices/DotnetTestDevices.csproj Adds a test-only hook to force a browser-wasm RID to exercise HTTP transport selection.
test/TestAssets/TestProjects/BlazorWasmTestApp/wwwroot/index.html Adds minimal host page for the Blazor WASM probe asset.
test/TestAssets/TestProjects/BlazorWasmTestApp/SampleTests.cs Adds a basic MSTest test that asserts it’s running in browser-wasm.
test/TestAssets/TestProjects/BlazorWasmTestApp/README.md Documents current limitations and expected future Blazor lifecycle integration for dotnet test.
test/TestAssets/TestProjects/BlazorWasmTestApp/Program.cs Sets up a Blazor WASM app with a test runner service.
test/TestAssets/TestProjects/BlazorWasmTestApp/Pages/Home.razor Runs tests on startup and displays pass/fail status + exit code.
test/TestAssets/TestProjects/BlazorWasmTestApp/BrowserTestRunner.cs Runs MTP + MSTest in-process within the browser app.
test/TestAssets/TestProjects/BlazorWasmTestApp/BlazorWasmTestApp.csproj New Blazor WASM test app asset configured to run MSTest/MTP in browser-wasm.
test/TestAssets/TestProjects/BlazorWasmTestApp/App.razor Minimal router for the Blazor WASM probe asset.
test/TestAssets/TestProjects/BlazorWasmTestApp/_Imports.razor Razor imports for the probe asset.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/VanillaWasmTests.cs Adds a build-only test validating the new Blazor WASM probe asset builds.
test/dotnet.Tests/CommandTests/Test/TestApplicationLaunchTests.cs Adds transport-selection tests (HTTP for WASM, pipes for desktop) and response-file redaction/permissions/cleanup assertions.
test/dotnet.Tests/CommandTests/Test/HttpTestHostGatewayTests.cs Adds unit tests covering authenticated frame dispatch, CORS/PNA preflight behavior, and malformed/corrupt frame handling.
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs Adds an end-to-end device-orchestration test asserting HTTP transport selection.
test/dotnet.Tests/CommandTests/Test/ArtifactPostProcessingManagerTests.cs Adds coverage for skipping artifact post-processing for WASM modules.
src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs Switches between pipe vs HTTP transport; creates owner-only bootstrap response file; redacts args for logging; disables control channel for HTTP.
src/Cli/dotnet/Commands/Test/MTP/IPC/ProtocolMessageSerializer.cs Extracts frame serialize/deserialize logic for reuse by HTTP gateway.
src/Cli/dotnet/Commands/Test/MTP/IPC/HttpTestHostGateway.cs New HTTP listener that authenticates via bearer token and forwards protocol frames (with CORS/PNA support).
src/Cli/dotnet/Commands/Test/MTP/ArtifactPostProcessingManager.cs Skips artifact post-processing for WASM modules until a browser-aware merge host exists.
src/Cli/dotnet/Commands/Test/CliConstants.cs Adds new CLI constants for the HTTP transport and bootstrap options.

Copilot's findings

  • Files reviewed: 21/21 changed files
  • Comments generated: 1

Comment thread src/Cli/dotnet/Commands/Test/MTP/IPC/HttpTestHostGateway.cs Outdated
Parse the request Content-Type and compare its media type so valid application/octet-stream parameters remain interoperable.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b1bfb191-93c7-4891-85ce-098b0676f861
@Evangelink

Copy link
Copy Markdown
Member Author

/ba-g #54914

@Evangelink
Evangelink merged commit 55f2a7b into dotnet:main Aug 7, 2026
23 of 25 checks passed
@pavelsavara

Copy link
Copy Markdown
Member

Is this going to work with <Project Sdk="Microsoft.NET.Sdk.WebAssembly"> ?
Also maybe it would be good to talk about the design with us ?

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.

4 participants