Add [UnsupportedOSPlatform("wasi")] to HangDump / Console / Process surface#8564
Conversation
…urface Fixes #8557. Related: #2196, #5366. MTP projects already advertise wasi support via <SupportedPlatform Include="wasi" />, so CA1416 now requires call sites and exposed members to be annotated for wasi the same way they are for browser/ios/tvos. This PR closes the annotation gap on the parts of MTP that structurally cannot work on wasi-wasm today (single-instance wasm, no PID/process model, no PosixSignalRegistration, no tty buffer/window APIs): - Console abstraction (IConsole / SystemConsole): mirror the existing `browser` annotations on CancelKeyPress, BufferHeight/Width, WindowHeight/Width, and SetForegroundColor/GetForegroundColor. - Process abstraction (SystemProcessHandler): GetCurrentProcess, GetProcessById, Start. - HangDump extension: AddHangDumpProvider entry point (plus matching PNSE runtime guard), TestingPlatformBuilderHook.AddExtensions, HangDumpProcessLifetimeHandler (class + TakeDumpOfTreeAsync), HangDumpActivityIndicator, and the IProcessExtensions helpers. - TestApplication.WaitForDebuggerToAttach: add `wasi` to the attribute and add a sibling runtime guard at both call sites (env-var driven and command-line option driven). New localized resource string WaitDebuggerAttachNotSupportedInWasiErrorMessage. - Terminal helpers (AnsiTerminal/SimpleTerminalBase Width/Height and NativeMethods.QueryIsScreenAndTryEnableAnsiColorCodes): include wasi in the existing `browser/android/ios/tvos` guards so the call sites stop CA1416-warning once the underlying APIs are flagged. CTRLPlusCCancellationTokenSource, NonAnsiTerminal, HotReloadHandler and OutputDeviceManager already had `OperatingSystem.IsWasi()` guards (plus matching `[SupportedOSPlatformGuard("wasi")]`), so they continue to compile cleanly. No public API change: `[UnsupportedOSPlatform]` is not part of the PublicAPI.txt format. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates Microsoft.Testing.Platform (MTP) and the HangDump extension to explicitly mark APIs that are structurally unavailable on wasi-wasm using [UnsupportedOSPlatform("wasi")], and adds corresponding runtime guards where those APIs are conditionally invoked. This prevents future CA1416 platform analyzer warnings from leaking to consumers and avoids runtime failures when running on WASI.
Changes:
- Add
[UnsupportedOSPlatform("wasi")]to Console/Process abstractions and HangDump public entry points and helpers. - Add WASI runtime guards for “wait for debugger attach” and HangDump extension activation, including a new localized error message for debugger attach on WASI.
- Extend terminal sizing / ANSI probing guards to avoid unsupported console APIs on WASI.
Show a summary per file
| File | Description |
|---|---|
| src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs | Adds WASI guard + annotation for debugger-attach wait path and uses new localized resource string. |
| src/Platform/Microsoft.Testing.Platform/Helpers/System/IConsole.cs | Extends console abstraction members with [UnsupportedOSPlatform("wasi")] to propagate platform limitations. |
| src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemConsole.cs | Mirrors WASI unsupported annotations on concrete console implementation members. |
| src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemProcessHandler.cs | Marks Process APIs as unsupported on WASI to match platform reality and avoid CA1416 at call sites. |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/AnsiTerminal.cs | Treats WASI like other non-terminal platforms for width/height to avoid unsupported console window APIs. |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/SimpleTerminalBase.cs | Treats WASI like other non-terminal platforms for width/height to avoid unsupported console window APIs. |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/NativeMethods.cs | Avoids buffer-size probing on WASI by extending the existing platform guard condition. |
| src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx | Adds localized resource key for “wait debugger attach not supported on wasi”. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf | Regenerates localization file to include the new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf | Localization regen for new WASI debugger-attach resource string. |
| src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpExtensions.cs | Marks HangDump entry point as unsupported on WASI and adds a runtime guard for WASI usage. |
| src/Platform/Microsoft.Testing.Extensions.HangDump/TestingPlatformBuilderHook.cs | Marks MSBuild hook entry point as unsupported on WASI. |
| src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpProcessLifetimeHandler.cs | Marks HangDump process lifetime handler and dump-taking path as unsupported on WASI. |
| src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpActivityIndicator.cs | Marks activity indicator as unsupported on WASI alongside existing browser restriction. |
| src/Platform/Microsoft.Testing.Extensions.HangDump/Helpers/IProcessExtensions.cs | Marks process-tree helpers as unsupported on WASI to match Process model limitations. |
Copilot's findings
- Files reviewed: 26/26 changed files
- Comments generated: 0
Localization & Resources — ISSUEProblem: Hardcoded user-facing strings in Concrete Failing Scenarios1. HangDumpExtensions.cs (lines 33, 38, 43)Current code: throw new PlatformNotSupportedException("Hang dump extension is not available on browser");
throw new PlatformNotSupportedException("Hang dump extension is not available on ios nor tvos");
throw new PlatformNotSupportedException("Hang dump extension is not available on wasi");Issue: These are hardcoded English strings, but:
Expected: These three strings should be added to 2. MSBuildExtensions.cs (line 29)Current code: throw new PlatformNotSupportedException("MSBuild extension is not supported in browser environments.");Issue: Hardcoded English string, but:
Expected: Add to Evidence of Pattern Consistency✅ TestApplication.cs (this PR): Uses Why This MattersThese Note: The new
|
Closes #8557. Related: #2196, #5366.
MTP projects already advertise wasi support via
<SupportedPlatform Include="wasi" />, so CA1416 now requires call sites and exposed members to be annotated for wasi the same way they are for browser/ios/tvos. This PR closes the annotation gap on the parts of MTP that structurally cannot work on wasi-wasm today (single-instance wasm, no PID/process model, noPosixSignalRegistration, no tty buffer/window APIs).Why these surfaces?
Console.CancelKeyPressis implemented viaPosixSignalRegistrationwhich is unavailable on wasi (this is the original #5366 crash).System.Diagnostics.Processhas no analog on wasi: one wasm instance per program, no PID, no/proc, noProcess.Start.MiniDumpWriteDump, no threading.Changes
IConsole/SystemConsole): mirror existingbrowserannotations onCancelKeyPress,BufferHeight/Width,WindowHeight/Width, andSetForegroundColor/GetForegroundColor.SystemProcessHandler):GetCurrentProcess,GetProcessById,Start.AddHangDumpProviderentry point (plus matching PNSE runtime guard),TestingPlatformBuilderHook.AddExtensions,HangDumpProcessLifetimeHandler(class +TakeDumpOfTreeAsync),HangDumpActivityIndicator, and theIProcessExtensionshelpers (GetProcessTreeAsync,GetParentPidWindows/Linux/MacOsAsync,IsChildCandidate).TestApplication.WaitForDebuggerToAttach: addwasito the attribute and add a sibling runtime guard at both call sites (env-var driven and command-line option driven). New localized resourceWaitDebuggerAttachNotSupportedInWasiErrorMessage.AnsiTerminal/SimpleTerminalBaseWidth/HeightandNativeMethods.QueryIsScreenAndTryEnableAnsiColorCodes): include wasi in the existingbrowser/android/ios/tvosguards so the call sites stop CA1416-warning once the underlying APIs are flagged.CTRLPlusCCancellationTokenSource,NonAnsiTerminal,HotReloadHandlerandOutputDeviceManageralready hadOperatingSystem.IsWasi()guards (plus matching[SupportedOSPlatformGuard("wasi")]) and continue to compile cleanly.Out of scope
IConsole.Clear()(nobrowserannotation today;Console.Clear()may work on wasi via ANSI escapes — separate concern).HangDumpActivityIndicator'sbrowser-only annotation up to the fullbrowser/ios/tvos/wasiquartet (kept minimal here).IProcessHandlerinterface remains attribute-free (only the concreteSystemProcessHandlerimpl carries the annotations).Validation
.\build.cmd -c Debugsucceeds with no CA1416 warnings.[UnsupportedOSPlatform]is not part of thePublicAPI.txtformat.UpdateXlf.