Skip to content

Commit 5df27f1

Browse files
committed
test: reject WSL bash, accept only MSYS/MINGW on Windows
On Windows, verify uname -s reports MSYS, MINGW, or CYGWIN so the WSL launcher (System32\bash.exe) is rejected — it cannot handle native Windows paths used by test fixtures. Add SPECKIT_TEST_BASH=1 env var escape hatch to force-enable bash tests in non-standard setups.
1 parent 25b6aff commit 5df27f1

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

tests/conftest.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
11
"""Shared test helpers for the Spec Kit test suite."""
22

3+
import os
34
import re
45
import shutil
56
import subprocess
7+
import sys
68

79
import pytest
810

911
_ANSI_ESCAPE_RE = re.compile(r"\x1b\[[0-?]*[ -/]*[@-~]")
1012

1113

1214
def _has_working_bash() -> bool:
13-
"""Check whether a functional bash is available (not just a WSL stub)."""
15+
"""Check whether a functional native bash is available.
16+
17+
On Windows, only Git-for-Windows bash (MSYS2/MINGW) is accepted.
18+
The WSL launcher (System32\\bash.exe) is rejected because it runs in
19+
a separate Linux filesystem and cannot handle native Windows paths
20+
used by the test fixtures.
21+
22+
Set SPECKIT_TEST_BASH=1 to force-enable bash tests regardless.
23+
"""
24+
if os.environ.get("SPECKIT_TEST_BASH") == "1":
25+
return True
1426
if shutil.which("bash") is None:
1527
return False
1628
try:
1729
r = subprocess.run(
1830
["bash", "-c", "echo ok"],
1931
capture_output=True, text=True, timeout=5,
2032
)
21-
return r.returncode == 0 and "ok" in r.stdout
33+
if r.returncode != 0 or "ok" not in r.stdout:
34+
return False
2235
except (OSError, subprocess.TimeoutExpired):
2336
return False
37+
# On Windows, verify we have MSYS/MINGW bash (Git for Windows),
38+
# not the WSL launcher which can't handle native paths.
39+
if sys.platform == "win32":
40+
try:
41+
u = subprocess.run(
42+
["bash", "-c", "uname -s"],
43+
capture_output=True, text=True, timeout=5,
44+
)
45+
kernel = u.stdout.strip().upper()
46+
if not any(k in kernel for k in ("MSYS", "MINGW", "CYGWIN")):
47+
return False
48+
except (OSError, subprocess.TimeoutExpired):
49+
return False
50+
return True
2451

2552

2653
requires_bash = pytest.mark.skipif(

0 commit comments

Comments
 (0)