fix(stdio): launch PowerShell (.ps1) servers via a PowerShell host on Windows

Closed
DL
1mo ago
+51-0

Summary

Fixes #3496

On Windows, get_windows_executable_command() resolves a stdio server command to a .ps1 path (via shutil.which extension probing), but CreateProcess cannot execute a PowerShell script directly — the spawn then fails with WinError 193 (%1 is not a valid Win32 application).

Fix: in create_windows_process, when the resolved command ends with .ps1, rewrite the argv to launch through a PowerShell host — pwsh preferred, powershell as fallback — with -NoProfile -NonInteractive -ExecutionPolicy Bypass -File <script> <args...>. If neither host is on PATH, raise a clear FileNotFoundError instead of the opaque WinError 193. Both the anyio.open_process path and the FallbackProcess (SelectorEventLoop) path benefit, since the rewrite happens before either spawn.

Testing:

  • New Windows-only integration test test_a_powershell_script_server_round_trips_messages: writes a real .ps1 echo server, connects via stdio_client, and round-trips a JSON-RPC ping.
  • Verified on Windows 11: fails without the fix (OSError: [WinError 193], exactly the reported error), passes with it (0.68s).
  • ruff check / ruff format clean.