Skip to content

Commit ca70454

Browse files
committed
test: early-reject WSL launcher, fix remaining f-string JSON
- Check resolved bash path for System32 before spawning any subprocess to avoid WSL init prompts and timeout during test collection - Convert remaining feature_json f-string writes to json.dumps() so paths with backslashes produce valid JSON on Windows
1 parent db8134d commit ca70454

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

tests/conftest.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,33 @@ def _has_working_bash() -> bool:
2323
"""
2424
if os.environ.get("SPECKIT_TEST_BASH") == "1":
2525
return True
26-
if shutil.which("bash") is None:
26+
bash_path = shutil.which("bash")
27+
if bash_path is None:
2728
return False
28-
try:
29-
r = subprocess.run(
30-
["bash", "-c", "echo ok"],
31-
capture_output=True, text=True, timeout=5,
32-
)
33-
if r.returncode != 0 or "ok" not in r.stdout:
34-
return False
35-
except (OSError, subprocess.TimeoutExpired):
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.
29+
# On Windows, reject the WSL launcher early (avoids WSL init prompts
30+
# and the 5 s timeout) and only accept MSYS/MINGW/CYGWIN bash.
3931
if sys.platform == "win32":
32+
if "system32" in bash_path.lower():
33+
return False
4034
try:
4135
u = subprocess.run(
42-
["bash", "-c", "uname -s"],
36+
[bash_path, "-c", "uname -s"],
4337
capture_output=True, text=True, timeout=5,
4438
)
4539
kernel = u.stdout.strip().upper()
4640
if not any(k in kernel for k in ("MSYS", "MINGW", "CYGWIN")):
4741
return False
4842
except (OSError, subprocess.TimeoutExpired):
4943
return False
44+
try:
45+
r = subprocess.run(
46+
[bash_path, "-c", "echo ok"],
47+
capture_output=True, text=True, timeout=5,
48+
)
49+
if r.returncode != 0 or "ok" not in r.stdout:
50+
return False
51+
except (OSError, subprocess.TimeoutExpired):
52+
return False
5053
return True
5154

5255

tests/test_timestamp_branches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ def test_feature_json_overrides_branch_lookup(self, git_repo: Path):
11341134

11351135
feature_json = git_repo / ".specify" / "feature.json"
11361136
feature_json.write_text(
1137-
f'{{"feature_directory": "{custom_dir}"}}\n',
1137+
json.dumps({"feature_directory": str(custom_dir)}) + "\n",
11381138
encoding="utf-8",
11391139
)
11401140

@@ -1163,7 +1163,7 @@ def test_env_var_takes_priority_over_feature_json(self, git_repo: Path):
11631163

11641164
feature_json = git_repo / ".specify" / "feature.json"
11651165
feature_json.write_text(
1166-
f'{{"feature_directory": "{json_dir}"}}\n',
1166+
json.dumps({"feature_directory": str(json_dir)}) + "\n",
11671167
encoding="utf-8",
11681168
)
11691169

0 commit comments

Comments
 (0)