From a84004b2be255ed8dc4ae7cf53c7e76504d1e71a Mon Sep 17 00:00:00 2001 From: Rahul Singh Khokhar Date: Fri, 15 May 2026 19:17:52 -0700 Subject: [PATCH] feat(dev): scripts\dev.ps1 PowerShell wrapper to bypass Windows' WSL-relay bash.exe Windows ships C:\Windows\System32\bash.exe that routes 'bash' calls from cmd.exe or PowerShell into WSL. If a WSL distro isn't installed, you get: <3>WSL (xxx - Relay) ERROR: CreateProcessCommon:800: execvpe(/bin/bash) failed: No such file or directory The fix is to invoke Git for Windows' real bash.exe directly. dev.ps1 locates it across the common install paths (Program Files, AppData, git-on-PATH) and runs dev.sh through it with all flags passed through. Helpful error if Git for Windows isn't installed at all. DEV.md updated with both invocation forms + a troubleshooting note for the WSL-relay error. Tested: .\scripts\dev.ps1 --help works from PowerShell on Windows 11 with Git for Windows installed at the default location. --- docs/operations/DEV.md | 20 ++++++++++- scripts/dev.ps1 | 79 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 scripts/dev.ps1 diff --git a/docs/operations/DEV.md b/docs/operations/DEV.md index b4566c5..8ad1ff9 100644 --- a/docs/operations/DEV.md +++ b/docs/operations/DEV.md @@ -11,10 +11,22 @@ ## The fast path +**From Git Bash, WSL, macOS Terminal, or any Linux shell:** + ```bash bash scripts/dev.sh ``` +**From Windows PowerShell or cmd.exe** (in case you don't have Git Bash on PATH, or Windows' +`C:\Windows\System32\bash.exe` is shadowing it and tries to route into WSL): + +```powershell +.\scripts\dev.ps1 +``` + +`dev.ps1` is a thin wrapper that locates Git for Windows' real `bash.exe` and runs +`dev.sh` through it. All flags pass through (`.\scripts\dev.ps1 --fresh`, `--down`, etc.). + That's it. The script: 1. Verifies the prereqs above. @@ -89,8 +101,14 @@ docker compose -f infra/docker/docker-compose.dev.yaml \ ## Troubleshooting +- **`<3>WSL (xxx - Relay) ERROR: CreateProcessCommon:800: execvpe(/bin/bash) failed`** — + you're invoking `bash` from PowerShell/cmd, and Windows is routing that to its WSL + relay (`C:\Windows\System32\bash.exe`). If you don't have a WSL distro installed, the + relay fails like this. Use the PowerShell wrapper instead: `.\scripts\dev.ps1`. Or + run the original `bash scripts/dev.sh` from a Git Bash terminal. - **"Port 3000 / 4000 is already in use"** — something else is using the port. - `netstat -an | grep :3000` to find it; kill that process. + `netstat -an | grep :3000` to find it; kill that process. Or run + `bash scripts/dev.sh --down` to clear an orphaned previous run. - **Piston in restart loop** — see STORY-065. On Windows you can ignore it unless you need to run code; everything else works. - **DB bootstrap fails** — check `.dev-logs/bootstrap.log`. Most common cause is diff --git a/scripts/dev.ps1 b/scripts/dev.ps1 new file mode 100644 index 0000000..c139d2d --- /dev/null +++ b/scripts/dev.ps1 @@ -0,0 +1,79 @@ +# scripts\dev.ps1 — PowerShell wrapper around scripts\dev.sh for Windows users who don't +# have Git Bash on their PATH (or have Windows' WSL-relay bash.exe shadowing it). Locates +# Git for Windows' real bash.exe and invokes the bash script with the user's flags. +# +# Usage (from PowerShell or cmd.exe): +# powershell -ExecutionPolicy Bypass -File scripts\dev.ps1 +# powershell -ExecutionPolicy Bypass -File scripts\dev.ps1 --fresh +# powershell -ExecutionPolicy Bypass -File scripts\dev.ps1 --down +# +# Or from PowerShell directly (if execution policy allows): +# .\scripts\dev.ps1 +# +# Why this wrapper exists: +# - Windows ships its own C:\Windows\System32\bash.exe that routes to WSL. If you don't +# have a WSL distro installed, you get +# <3>WSL (xxx - Relay) ERROR: CreateProcessCommon:800: execvpe(/bin/bash) failed: +# No such file or directory +# This wrapper bypasses that by calling Git for Windows' bash.exe directly. + +$ErrorActionPreference = "Stop" + +# Find Git for Windows' bash.exe. Try the common install locations in order. +$candidates = @( + "$env:ProgramFiles\Git\bin\bash.exe", + "$env:ProgramFiles\Git\usr\bin\bash.exe", + "${env:ProgramFiles(x86)}\Git\bin\bash.exe", + "${env:ProgramFiles(x86)}\Git\usr\bin\bash.exe", + "$env:LocalAppData\Programs\Git\bin\bash.exe" +) + +# Also try resolving via `git --exec-path` — works when Git is on PATH but in an unusual spot. +$gitCmd = Get-Command git -ErrorAction SilentlyContinue +if ($gitCmd) { + $gitDir = Split-Path -Parent $gitCmd.Source + $candidates += "$gitDir\bash.exe" + $candidates += "$gitDir\..\bin\bash.exe" + $candidates += "$gitDir\..\usr\bin\bash.exe" +} + +$bashExe = $null +foreach ($c in $candidates) { + if ($c -and (Test-Path $c -PathType Leaf)) { + $bashExe = (Resolve-Path $c).Path + break + } +} + +if (-not $bashExe) { + Write-Host "" + Write-Host "ERROR: Could not find Git for Windows' bash.exe." -ForegroundColor Red + Write-Host "" + Write-Host "Either install Git for Windows (https://git-scm.com/download/win), or run" -ForegroundColor Yellow + Write-Host "this script from a Git Bash terminal directly:" -ForegroundColor Yellow + Write-Host "" + Write-Host " bash scripts/dev.sh" -ForegroundColor Cyan + Write-Host "" + Write-Host "Tried these paths:" -ForegroundColor DarkGray + foreach ($c in $candidates) { Write-Host " $c" -ForegroundColor DarkGray } + exit 1 +} + +# Resolve the script's directory and the bash script we want to run. +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$bashScript = Join-Path $scriptDir "dev.sh" +if (-not (Test-Path $bashScript -PathType Leaf)) { + Write-Host "ERROR: dev.sh not found next to dev.ps1: $bashScript" -ForegroundColor Red + exit 1 +} + +# Translate the Windows-style path to a form Git Bash accepts. Git Bash handles both +# "D:/...\path" and Unix-style "/d/..." paths; we use forward-slashed Windows so users +# see a familiar location in any error messages. +$bashScriptUnix = $bashScript -replace '\\', '/' + +# Run the bash script with all of our args passed through. We deliberately avoid --login +# (skip the user's .bash_profile which may pollute the env) and -i (skip interactive +# rc loading which slows startup). The script itself manages its own environment. +& $bashExe $bashScriptUnix @args +exit $LASTEXITCODE