From 8ac77337fad751d43dc9c7a08d4d591ff1b74549 Mon Sep 17 00:00:00 2001 From: orange Date: Tue, 4 Aug 2026 18:05:58 +0900 Subject: [PATCH] fix(spawn): pin Git Bash for Windows Terminal --- scripts/spawn.sh | 12 ++++++++++-- tests/test_spawn.bats | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/scripts/spawn.sh b/scripts/spawn.sh index ca6f4ead..d7867a2c 100755 --- a/scripts/spawn.sh +++ b/scripts/spawn.sh @@ -562,12 +562,20 @@ launch_linux_terminal() { } launch_windows_terminal() { + # wt is a native Windows executable, so a bare bash is resolved through the + # Windows PATH and may select WSL's bash.exe. Pin the Bash that is running + # agmsg and convert its MSYS/Cygwin path before crossing the native boundary. + local bash_path + bash_path="$(command -v bash)" || die "current bash executable not found" + if command -v cygpath >/dev/null 2>&1; then + bash_path="$(cygpath -w "$bash_path")" || die "failed to convert bash path for Windows Terminal" + fi if command -v wt.exe >/dev/null 2>&1; then - wt.exe new-tab bash -l "$BOOT" + wt.exe new-tab "$bash_path" -l "$BOOT" return 0 fi if command -v wt >/dev/null 2>&1; then - wt new-tab bash -l "$BOOT" + wt new-tab "$bash_path" -l "$BOOT" return 0 fi die "Windows Terminal (wt) not found; set AGMSG_TERMINAL or run inside tmux" diff --git a/tests/test_spawn.bats b/tests/test_spawn.bats index c47e2244..85434e45 100644 --- a/tests/test_spawn.bats +++ b/tests/test_spawn.bats @@ -743,6 +743,41 @@ YAML fi } +@test "spawn: Windows Terminal receives the current Git Bash executable, not bare bash (#39)" { + bash "$SCRIPTS/join.sh" myteam existing claude-code "$PROJ" + unset AGMSG_TERMINAL + + cat > "$STUB_BIN/uname" <<'SH' +#!/usr/bin/env bash +printf '%s\n' MINGW64_NT-10.0 +SH + cat > "$STUB_BIN/cygpath" <<'SH' +#!/usr/bin/env bash +if [ "$1" = "-w" ] && [[ "$2" == */bash ]]; then + printf '%s\n' 'C:\Program Files\Git\usr\bin\bash.exe' +else + if [ -x /usr/bin/cygpath ]; then + exec /usr/bin/cygpath "$@" + fi + printf '%s\n' "${!#}" +fi +SH + cat > "$STUB_BIN/wt.exe" <<'SH' +#!/usr/bin/env bash +printf '%s\n' "$@" > "$CAPTURE" +SH + chmod +x "$STUB_BIN/uname" "$STUB_BIN/cygpath" "$STUB_BIN/wt.exe" + + run bash "$SCRIPTS/spawn.sh" claude-code alice --project "$PROJ" --no-wait + [ "$status" -eq 0 ] + + [ "$(sed -n '1p' "$CAPTURE")" = "new-tab" ] + [ "$(sed -n '2p' "$CAPTURE")" = 'C:\Program Files\Git\usr\bin\bash.exe' ] + [ "$(sed -n '3p' "$CAPTURE")" = "-l" ] + local boot_path; boot_path="$(sed -n '4p' "$CAPTURE")" + [ -f "$boot_path" ] +} + @test "spawn: macOS terminal launch does not steal focus (Terminal and iTerm)" { # A no-op-Terminal spawn (no $TMUX, no AGMSG_TERMINAL override) exercises # launch_macos_terminal() itself, which every other test in this file