|
1 | 1 | """Shared test helpers for the Spec Kit test suite.""" |
2 | 2 |
|
| 3 | +import os |
3 | 4 | import re |
4 | 5 | import shutil |
5 | 6 | import subprocess |
| 7 | +import sys |
6 | 8 |
|
7 | 9 | import pytest |
8 | 10 |
|
9 | 11 | _ANSI_ESCAPE_RE = re.compile(r"\x1b\[[0-?]*[ -/]*[@-~]") |
10 | 12 |
|
11 | 13 |
|
12 | 14 | 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 |
14 | 26 | if shutil.which("bash") is None: |
15 | 27 | return False |
16 | 28 | try: |
17 | 29 | r = subprocess.run( |
18 | 30 | ["bash", "-c", "echo ok"], |
19 | 31 | capture_output=True, text=True, timeout=5, |
20 | 32 | ) |
21 | | - return r.returncode == 0 and "ok" in r.stdout |
| 33 | + if r.returncode != 0 or "ok" not in r.stdout: |
| 34 | + return False |
22 | 35 | except (OSError, subprocess.TimeoutExpired): |
23 | 36 | 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 |
24 | 51 |
|
25 | 52 |
|
26 | 53 | requires_bash = pytest.mark.skipif( |
|
0 commit comments