Skip to content

fix(cli): try the Windows browser first on WSL, and warn when it can't open - #73

Merged
hyamero merged 1 commit into
stagingfrom
fix/wsl-open-fallback
Nov 13, 2026
Merged

hyamero merged 1 commit into
stagingfrom
fix/wsl-open-fallback

Conversation

@hyamero

@hyamero hyamero commented Nov 13, 2026

Copy link
Copy Markdown
Member

Follow-up to #71, from a review of it. Refs #70.

Summary

The WSL fallback from #71 could still leave a user with no browser and no warning:

  • explorer.exe exits with 1 whether or not it opened the file, so its exit code was ignored. With broken interop (a stale WSL_INTEROP socket, say) nothing opened and nothing was reported.
  • xdg-open ran first. Where it is installed but has no Linux browser, it can exit 0 having opened nothing, and that ended the chain before the Windows side was tried.

The WSL chain is now:

 darwin   open
 win32    cmd /c start "" "<path>"
 linux    xdg-open
-WSL      xdg-open → wslview → explorer.exe "$(wslpath -w <path>)"
+WSL      wslview → powershell.exe Start-Process '<wslpath -w path>' → xdg-open
  • powershell.exe: it exits non-zero when it can't start the file, so a failure reaches the warning. The command goes through -EncodedCommand, with the path single-quoted and every quote PowerShell recognises doubled.
  • Off the PATH: with appendWindowsPath=false, powershell.exe isn't found by name, so it is retried at /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe. This assumes the default /mnt/c mount.
  • wslpath: its stderr no longer prints ahead of the warning, and a missing wslpath reads wslpath not found instead of a conversion failure.
  • Signals: an opener killed by a signal counts as a failure and hands over to the next one. It used to count as success.
  • Behaviour change: a WSL user with a Linux browser set up through WSLg now gets the Windows browser.

Evidence

  • Before: the eight new tests fail (openWith is not a function).
    After: open.test.ts passes, 13 of 13. The new tests spawn real child processes for the fallback loop, exit codes, a signal kill, the off-PATH retry and the encoded command. The CLI suite passes, 62 of 62, and bun run typecheck is clean.
  • I faked WSL on macOS under Node 24, with stub commands as the only entries on PATH:
    • Only powershell.exe, exiting 0: success. It received Start-Process -FilePath '\\wsl.localhost\Ubuntu\home\u\it''s diagram.html' for /home/u/it's diagram.html.
    • powershell.exe exiting 1: wslview not found; powershell.exe exited with 1; xdg-open not found. Before, this was a silent success.
    • xdg-open exiting 0 and powershell.exe both present: powershell.exe runs and xdg-open doesn't.
    • wslview present: it opens the file and nothing else runs.
    • wslpath failing with text on stderr: wslview not found; wslpath couldn't convert the path; xdg-open not found, and stderr stays empty.
    • Nothing present: wslview not found; wslpath not found; xdg-open not found.
  • Not tried on real WSL or against a real PowerShell. What the stubs can't show is that Start-Process opens the browser on a \\wsl.localhost\… path and exits non-zero when it can't.

Merge Danger

Door: two-way

Blast Radius: cli-open-on-wsl

Only --open on WSL changes. Outside WSL, Linux still runs xdg-open alone, and darwin and win32 run the same commands as before.

@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
stackmap-site Skipped Skipped Nov 13, 2026 3:34pm UTC

@hyamero
hyamero merged commit 80c4757 into staging Nov 13, 2026
8 checks passed
@hyamero
hyamero deleted the fix/wsl-open-fallback branch November 13, 2026 15:48
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.6.2-rc.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.6.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

This branch was previously deployed

1 inactive deployment
Preview — cff8fedb Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant