Skip to content

Enable Microsoft.Testing.Platform on browser-wasm (#2196) - #9857

Merged
Amaury Levé (Evangelink) merged 18 commits into
mainfrom
dev/amauryleve/psychic-tribble
Jul 13, 2026
Merged

Amaury Levé (Evangelink) merged 18 commits into
mainfrom
dev/amauryleve/psychic-tribble

Conversation

@Evangelink

@Evangelink Amaury Levé (Evangelink) commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to the wasi-wasm work (#2196). The platform runtime was already browser-aware — the single-threaded fallbacks (RuntimeFeatureHelper.IsMultiThreaded / RuntimeContext.IsMultiThreaded), BrowserOutputDevice, and the OperatingSystem.IsBrowser() guards throughout the platform and extensions were all shared with the wasi effort. What was missing was the JS host harness + tooling that wasi never needed (wasi runs headless under wasmtime; browser-wasm boots through a JS module that loads dotnet.js).

This PR adds that layer and validates it end-to-end.

Changes

  • BrowserOutputDevice — JSConsoleWarn used [JSImport("globalThis.console.warn", "main.js")], but no setModuleImports('main.js', …) module is ever registered, so the binding would throw at call time. Dropped the stray module arg so warn resolves against globalThis like error/log.
  • samples/BrowserPlayground/ (new) — a browser-wasm MTP sample mirroring WasiPlayground: Program.cs (DummyFramework, registers only the browser-safe telemetry provider), a JS boot module (wwwroot/main.js), index.html, a headless node runner (wwwroot/runtests.mjs), and a README documenting the browser + node run flows and the unsupported-feature matrix. Intentionally not added to TestFx.slnx (browser-wasm needs the wasm-tools workload even to build).
  • BrowserWasmExecutionTests (new) — gated acceptance tests mirroring WasmExecutionTests, built on the shared WasmRuntime helper:
    • an entry-point build assertion,
    • a node-hosted end-to-end run of a real MSTest project (asserts AtLeastOneTestFailed),
    • a node-hosted run of a custom framework that emits a warning + error through IOutputDevice, asserting both reach the node output via the [JSImport] console bindings — directly guarding the JSConsoleWarn fix.
      Each skips (Inconclusive) only on the specific NETSDK1147 missing-wasm-tools signature or when node is unavailable; any other build/publish failure fails the test.
  • eng/restore-toolset.{ps1,sh} — the repo bootstrap now installs the wasm-tools-net10 workload (main already added it for the wasi publish step; this PR documents the browser-wasm requirement alongside it), so CI and local bootstrap exercise the browser-wasm build and, where node is present, the end-to-end run — the gated tests are no longer perpetually Inconclusive.
  • FileLoggerTests — the pre-existing CA1416 break is fixed on main (Fix CA1416 build failure in FileLoggerTests #9844, method-level [UnsupportedOSPlatform("browser")]); this branch defers to that fix.

Verification

Installed the wasm-tools-net10 workload, published samples/BrowserPlayground for browser-wasm, and ran the published AppBundle headlessly under node (node runtests.mjs):

Microsoft.Testing.Platform v2.4.0-dev (UTC ...) [browser-wasm - net10.0]
BrowserPlayground.dll (net10.0|browser-wasm)
Test run summary: Passed!
  total: 1
  failed: 0
  succeeded: 1
  skipped: 0

Separately validated the warning path end-to-end (a framework emitting WarningMessageOutputDeviceData / ErrorMessageOutputDeviceData): both markers reach node stderr via the console.warn/console.error [JSImport] bindings with a clean exit — proving the JSConsoleWarn fix.

Node works headlessly because Microsoft.Testing.Platform never touches the DOM, so the same bundle the browser loads also boots under the dotnet.js loader in node.

Publish-config notes (captured in the sample csproj + README): SelfContained=true is required (otherwise the mono browser-wasm runtime pack isn't resolved when targeting net10.0 under an 11.0 SDK); InvariantGlobalization is left unset (on browser-wasm it forces WasmBuildNative=true/an emscripten relink); WasmExtraFilesToDeploy lands the node runner / index.html in the AppBundle.

Build status: Microsoft.Testing.Platform (incl. browser TFM / CA1416), the acceptance project, and the full merged tree all build clean.

Feature matrix

Several capabilities remain unavailable on browser-wasm (guarded by OperatingSystem.IsBrowser()): TRX report (--report-trx; its streaming writer uses ITask.RunLongRunning / BlockingCollection<T>), hang/crash dumps (System.Diagnostics.Process, #8557), Azure DevOps report (HttpClient.AutomaticDecompression), server mode / dotnet test pipe (TCP/named-pipe IPC), --exit-on-process-exit and wait-for-debugger, and synchronous file-logger flush. The sample therefore registers only the telemetry provider.

Follow-up to the wasi-wasm work: the platform runtime was already browser-aware
(single-threaded fallbacks, BrowserOutputDevice, OperatingSystem.IsBrowser guards);
what was missing was the JS host harness and tooling that wasi never needed.

- BrowserOutputDevice: fix JSConsoleWarn to resolve against globalThis (drop the stray
  'main.js' module arg that was never registered and would throw at call time).
- samples/BrowserPlayground: browser-wasm MTP sample mirroring WasiPlayground, with a JS
  boot module (wwwroot/main.js), index.html, a headless node runner (runtests.mjs), and a
  README documenting the run flows and unsupported-feature matrix. Verified end-to-end
  under node: MTP boots ([browser-wasm - net10.0]) and the test passes.
- BrowserWasmExecutionTests: gated acceptance test mirroring WasmExecutionTests (always-on
  entry-point build assertion + node-hosted end-to-end run), Inconclusive when the
  wasm-tools workload or node is unavailable.
- eng/restore-toolset.{ps1,sh}: document the wasm-tools workload requirement (kept opt-in).
- FileLoggerTests: mark [UnsupportedOSPlatform("browser")] to fix a pre-existing CA1416
  break (test doubles forward to ITask.RunLongRunning, which is browser-unsupported).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Copilot AI review requested due to automatic review settings July 11, 2026 12:18

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 browser-wasm hosting and validation for Microsoft.Testing.Platform.

Changes:

  • Fixes browser console warning interop.
  • Adds a browser/Node WASM sample and tooling guidance.
  • Adds gated browser-wasm acceptance coverage.
Show a summary per file
File Description
BrowserOutputDevice.cs Fixes global console warning binding.
BrowserWasmExecutionTests.cs Adds build and Node execution tests.
FileLoggerTests.cs Marks tests unsupported on browsers.
BrowserPlayground.csproj Configures browser-wasm publishing.
Program.cs Hosts MTP with browser-safe extensions.
README.md Documents setup, execution, and limitations.
wwwroot/main.js Boots MTP in browsers.
wwwroot/runtests.mjs Runs the bundle under Node.
wwwroot/index.html Provides the browser host page.
restore-toolset.sh Documents the optional workload.
restore-toolset.ps1 Documents the optional workload.

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 6
  • Review effort level: Medium

Comment thread eng/restore-toolset.sh Resolved
- restore-toolset.{ps1,sh}: install the wasm-tools-net10 workload in CI so the
  browser-wasm build/run is actually exercised instead of always Inconclusive.
- BrowserWasmExecutionTests: detect the wasm-tools workload up front (via
  'dotnet workload list') and skip only when it is genuinely absent; once present,
  build and publish must succeed (no longer swallow failures as "workload missing").
- Assert the exact ExitCode.AtLeastOneTestFailed (2) instead of a generic non-zero
  check, so post-run crashes can't masquerade as the expected failing-test outcome.
- JS runners (sample runtests.mjs + the acceptance test's node runner): set
  process.exitCode instead of calling process.exit(), so Node drains redirected
  stdout/stderr before exiting and the asserted MTP summary isn't truncated.
- Docs updated to reflect that the bootstrap now installs the workload.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Copilot AI review requested due to automatic review settings July 11, 2026 12:33

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.

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 4
  • Review effort level: Medium

Comment thread samples/BrowserPlayground/Program.cs Resolved
Comment thread eng/restore-toolset.sh Resolved
Comment thread samples/BrowserPlayground/README.md Resolved
…c-tribble

# Conflicts:
#	eng/restore-toolset.ps1
#	eng/restore-toolset.sh
…time reuse

- Remove AddTrxReportProvider from BrowserPlayground (TRX's streaming writer uses ITask.RunLongRunning / BlockingCollection, unsupported on browser); list TRX as unavailable in the README matrix and drop the unused project reference.

- Add BrowserWasmExecution_FrameworkWarningReachesNode: a custom-framework asset emits a WarningMessageOutputDeviceData + ErrorMessageOutputDeviceData that must reach Node output via the [JSImport] console bindings, directly guarding the BrowserOutputDevice.JSConsoleWarn fix. Validated end-to-end under node.

- Reuse the shared WasmRuntime helper (extended with browser-wasm LocateNode/PublishForBrowserAsync/GetBrowserAppBundlePath/RunUnderNodeAsync) instead of bespoke detection, mirroring the wasi tests: skip only on the NETSDK1147 missing-'wasm-tools' signature, fail on any other build/publish error.

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

Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Copilot AI review requested due to automatic review settings July 11, 2026 13:14

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.

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 2
  • Review effort level: Medium

Comment thread samples/BrowserPlayground/README.md Resolved
Comment thread samples/BrowserPlayground/README.md Resolved
@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review July 11, 2026 20:32
@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jul 11, 2026
@github-actions

This comment has been minimized.

Comment thread samples/BrowserPlayground/Program.cs Resolved
Copilot AI review requested due to automatic review settings July 11, 2026 20:47
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) July 11, 2026 20:48

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.

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 5
  • Review effort level: Medium

Comment thread samples/BrowserPlayground/README.md Resolved
Comment thread samples/BrowserPlayground/README.md Resolved
Comment thread samples/BrowserPlayground/README.md Resolved
Comment thread eng/restore-toolset.sh Resolved
Comment thread eng/restore-toolset.ps1 Resolved
@github-actions

This comment has been minimized.

- README: replace Windows-only commands/paths with cross-platform forms (repo-local dotnet path shown for both OSes, forward-slash paths), and replace the 'dotnet serve' browser step (not an SDK command / not provisioned by the repo) with 'npx http-server' or 'python3 -m http.server'. Verified the browser flow end-to-end in a headless Chromium: MTP boots [browser-wasm - net10.0], the test passes, exit 0.

- csproj: use singular <TargetFramework> (single TFM) instead of <TargetFrameworks>, matching the other playground samples and avoiding the outer multi-TFM build loop.

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

Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Copilot AI review requested due to automatic review settings July 11, 2026 20:53
main removed samples/WasiPlayground (its wasi coverage is now the inline WasmExecutionTests acceptance asset). Repoint the BrowserPlayground README and the eng/restore-toolset.{ps1,sh} comments away from the deleted sample to the wasi acceptance assets (WasmExecutionTests.cs) so contributors can actually find the referenced code.

Also clarify the 'Not part of TestFx.slnx' note: the bootstrap installs wasm-tools, so the exclusion is to protect solution/IDE builds that bypass the bootstrap, not the default build.cmd.

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

Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7

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.

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 4
  • Review effort level: Medium

Comment thread samples/BrowserPlayground/README.md Resolved
@github-actions

This comment has been minimized.

…rowser

The Linux CI leg for BrowserWasmExecution_RunsTestsUnderNode failed because the standard MSTest runner flow crashes at startup on browser-wasm. Two auto-registered extensions throw PlatformNotSupportedException on browser:

1. Microsoft.Testing.Platform.MSBuild's TestingPlatformBuilderHook.AddExtensions (auto-registered because MSTest.TestAdapter references it) called AddMSBuild, which throws on browser. The MSBuild/dotnet-test integration relies on named-pipe IPC unavailable on browser, so skip it there instead of throwing.

2. MSTest's AddMSTest registered a TestHostControllers environment-variable provider (applies runsettings <EnvironmentVariables> by relaunching the host); test host controllers require process restart, which browser-wasm does not support. Guard the registration with !OperatingSystem.IsBrowser().

Both are real bugs for any browser-wasm MSTest user, not just the test. Validated end-to-end under node with locally-packed packages: MSTest boots ([browser-wasm - net10.0]) and reports succeeded: 2 / failed: 1, exit 2 (AtLeastOneTestFailed).

Also adjust the acceptance test to assert the run summary against combined stdout+stderr: on browser-wasm the failed-run summary is routed through BrowserOutputDevice.ConsoleError -> console.error (stderr), unlike wasi where everything lands on stdout.

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

Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Copilot AI review requested due to automatic review settings July 13, 2026 12:49

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.

Review details

  • Files reviewed: 13/13 changed files
  • Comments generated: 1
  • Review effort level: Medium

@github-actions

This comment has been minimized.

…entVariables on browser

Markdown lint (MD040/MD012): add the 'sh' language to the four fenced code blocks in samples/BrowserPlayground/README.md and drop the extra trailing blank line.

Review feedback: skipping the MSTest env-var provider on browser silently dropped a requested runsettings <EnvironmentVariables> section, changing test semantics. Applying it in-process is not possible (it needs a test-host-controller process restart, unsupported on browser), so instead the shared '--settings' command-line validation (RunSettingsCommandLineOptionsProviderBase, used by both the MSTest adapter and the VSTest bridge) now fails with a clear unsupported-platform diagnostic when a browser run supplies runsettings that declare <EnvironmentVariables>. Guarded to NETCOREAPP (browser-wasm only runs there; OperatingSystem.IsBrowser is built-in since .NET 8, no polyfill needed).

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

Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Copilot AI review requested due to automatic review settings July 13, 2026 13:36

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.

Review details

  • Files reviewed: 14/14 changed files
  • Comments generated: 2
  • Review effort level: Medium

@github-actions

This comment has been minimized.

…lize diagnostic

Two review points on the browser-wasm runsettings <EnvironmentVariables> handling:

1. The previous guard only rejected the section when supplied via --settings (ValidateOptionArgumentsAsync). MSTest/VSTest also accept runsettings from the TESTINGPLATFORM_EXPERIMENTAL_VSTEST_RUNSETTINGS and TESTINGPLATFORM_VSTESTBRIDGE_RUNSETTINGS_FILE environment variables, which bypass that hook. Moved the browser check to ValidateCommandLineOptionsAsync (runs once, always) and resolve the runsettings via RunSettingsProviderHelper.TryLoadRunSettingsAsync, which covers all three sources.

2. The diagnostic was hard-coded in the resource-independent shared base. Made it an abstract EnvironmentVariablesNotSupportedOnBrowserError property that each concrete provider supplies from its own resources (ExtensionResources for the VSTest bridge, PlatformAdapterResources for the MSTest adapter), so it is localizable. Added the resource entries and regenerated the XLF for all languages; declared the new internal API members in InternalAPI.Unshipped.txt for both projects.

Builds clean (0 warnings) across net9.0/net8.0/net462/netstandard2.0.

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

Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Copilot AI review requested due to automatic review settings July 13, 2026 14:26

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.

Review details

  • Files reviewed: 46/46 changed files
  • Comments generated: 1
  • Review effort level: Medium

@github-actions

This comment has been minimized.

…ariables rejection

Adds BrowserWasmExecution_RunSettingsEnvironmentVariables_FailsWithClearDiagnostic: publishes a browser-wasm MSTest project, boots it under node with a runsettings <EnvironmentVariables> section supplied via the TESTINGPLATFORM_EXPERIMENTAL_VSTEST_RUNSETTINGS content environment variable (using the dotnet.js withEnvironmentVariable API), and asserts the run is rejected with the localized unsupported-platform diagnostic and exit code InvalidCommandLine (5).

This exercises RunSettingsCommandLineOptionsProviderBase.ValidateCommandLineOptionsAsync -> TryLoadRunSettingsAsync end-to-end, i.e. the environment-variable runsettings resolution path (not just --settings). Validated locally: the run exits 5 and emits the exact diagnostic 'The runsettings EnvironmentVariables section is not supported on browser/WebAssembly platforms...'. (The --settings and file env-var sources fail earlier on the wasm virtual filesystem's file-path resolution, unrelated to this validation, so the content source is used for reliable coverage.)

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

Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Copilot AI review requested due to automatic review settings July 13, 2026 15:23

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.

Review details

  • Files reviewed: 46/46 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test quality grade — PR #9857

GradeTestNotes
A (90–100) new BrowserWasmExecutionTests.
BrowserWasmExecution_
RunSettingsEnvironmentVariables_
FailsWithClearDiagnostic
Three distinct meaningful assertions (exit code, diagnostic content, regression absence); clear AAA structure; descriptive name — no issues found.

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · 42.1 AIC · ⌖ 6.04 AIC · ⊞ 8.9K · [◷]( · ◷)

@Evangelink

Copy link
Copy Markdown
Member Author

/azp run microsoft.testfx

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@Evangelink
Amaury Levé (Evangelink) merged commit b033338 into main Jul 13, 2026
49 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/psychic-tribble branch July 13, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants