π« Toolkit to help you get started with SDD or any other process!
ci: add windows-latest to test matrix (#2233)
Manfred Riem9988a46d96f7
diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 18b039f02..44b026988 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -27,9 +27,10 @@ jobs:run: uvx ruff check src/pytest:- runs-on: ubuntu-latest+ runs-on: ${{ matrix.os }}strategy:matrix:+ os: [ubuntu-latest, windows-latest]python-version: ["3.11", "3.12", "3.13"]steps:- name: Checkout@@ -46,5 +47,9 @@ jobs:- name: Install dependenciesrun: uv sync --extra test+ # On windows-latest, bash tests auto-skip unless Git-for-Windows+ # bash (MSYS2/MINGW) is detected. The WSL launcher is rejected+ # because it cannot handle native Windows paths in test fixtures.+ # See tests/conftest.py::_has_working_bash() for details.- name: Run testsrun: uv run pytestdiff --git a/tests/conftest.py b/tests/conftest.pyindex 4387c9ac8..9e8ffaae5 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -1,10 +1,68 @@"""Shared test helpers for the Spec Kit test suite."""+import osimport re+import shutil+import subprocess+import sys++import pytest_ANSI_ESCAPE_RE = re.compile(r"\x1b\[[0-?]*[ -/]*[@-~]")+def _has_working_bash() -> bool:+ """Check whether a functional native bash is available.++ On Windows, ``subprocess.run(["bash", ...])`` uses CreateProcess,+ which searches System32 *before* PATH β so it may find the WSL+ launcher even when Git-for-Windows bash appears first in PATH via+ ``shutil.which``. We therefore probe with bare ``"bash"`` (the+ same way test helpers invoke it) to get an accurate result.++ On Windows, only Git-for-Windows bash (MSYS2/MINGW) is accepted.+ The WSL launcher is rejected because it runs in a separate Linux+ filesystem and cannot handle native Windows paths used by the+ test fixtures.++ Set SPECKIT_TEST_BASH=1 to force-enable bash tests regardless.+ """+ if os.environ.get("SPECKIT_TEST_BASH") == "1":+ return True+ if shutil.which("bash") is None:+ return False+ # Probe with bare "bash" β same as the test helpers β so that+ # Windows CreateProcess resolution order is respected.+ try:+ r = subprocess.run(+ ["bash", "-c", "echo ok"],+ capture_output=True, text=True, timeout=5,+ )+ if r.returncode != 0 or "ok" not in r.stdout:+ return False+ except (OSError, subprocess.TimeoutExpired):+ return False+ # On Windows, verify we have MSYS/MINGW bash (Git for Windows),+ # not the WSL launcher which can't handle native paths.+ if sys.platform == "win32":+ try:+ u = subprocess.run(+ ["bash", "-c", "uname -s"],+ capture_output=True, text=True, timeout=5,+ )+ kernel = u.stdout.strip().upper()+ if not any(k in kernel for k in ("MSYS", "MINGW", "CYGWIN")):+ return False+ except (OSError, subprocess.TimeoutExpired):+ return False+ return True+++requires_bash = pytest.mark.skipif(+ not _has_working_bash(), reason="working bash not available"+)++def strip_ansi(text: str) -> str:"""Remove ANSI escape codes from Rich-formatted CLI output."""return _ANSI_ESCAPE_RE.sub("", text)diff --git a/tests/extensions/git/test_git_extension.py b/tests/extensions/git/test_git_extension.pyindex a04acba10..30694fc9d 100644--- a/tests/extensions/git/test_git_extension.py+++ b/tests/extensions/git/test_git_extension.py@@ -18,6 +18,8 @@ from pathlib import Pathimport pytest+from tests.conftest import requires_bash+PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent.parentEXT_DIR = PROJECT_ROOT / "extensions" / "git"EXT_BASH = EXT_DIR / "scripts" / "bash"@@ -211,6 +213,7 @@ class TestGitExtensionInstall:# ββ initialize-repo.sh Tests βββββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestInitializeRepoBash:def test_initializes_git_repo(self, tmp_path: Path):"""initialize-repo.sh creates a git repo with initial commit."""@@ -269,6 +272,7 @@ class TestInitializeRepoPowerShell:# ββ create-new-feature.sh Tests ββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestCreateFeatureBash:def test_creates_branch_sequential(self, tmp_path: Path):"""Extension create-new-feature.sh creates sequential branch."""@@ -376,6 +380,7 @@ class TestCreateFeaturePowerShell:# ββ auto-commit.sh Tests βββββββββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestAutoCommitBash:def test_disabled_by_default(self, tmp_path: Path):"""auto-commit.sh exits silently when config is all false."""@@ -583,6 +588,7 @@ class TestAutoCommitPowerShell:# ββ git-common.sh Tests ββββββββββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestGitCommonBash:def test_has_git_true(self, tmp_path: Path):"""has_git returns 0 in a git repo."""diff --git a/tests/integrations/test_manifest.py b/tests/integrations/test_manifest.pyindex b5d5bc39f..596397d4f 100644--- a/tests/integrations/test_manifest.py+++ b/tests/integrations/test_manifest.py@@ -2,6 +2,7 @@import hashlibimport json+import sysimport pytest@@ -41,8 +42,9 @@ class TestManifestPathTraversal:def test_record_file_rejects_absolute_path(self, tmp_path):m = IntegrationManifest("test", tmp_path)+ abs_path = "C:\\tmp\\escape.txt" if sys.platform == "win32" else "/tmp/escape.txt"with pytest.raises(ValueError, match="Absolute paths"):- m.record_file("/tmp/escape.txt", "bad")+ m.record_file(abs_path, "bad")def test_record_existing_rejects_parent_traversal(self, tmp_path):escape = tmp_path.parent / "escape.txt"diff --git a/tests/test_cursor_frontmatter.py b/tests/test_cursor_frontmatter.pyindex d9d0e3423..9f8c31ce1 100644--- a/tests/test_cursor_frontmatter.py+++ b/tests/test_cursor_frontmatter.py@@ -12,6 +12,8 @@ import textwrapimport pytest+from tests.conftest import requires_bash+SCRIPT_PATH = os.path.join(os.path.dirname(__file__),os.pardir,@@ -73,6 +75,7 @@ class TestScriptFrontmatterPattern:@requires_git+@requires_bashclass TestCursorFrontmatterIntegration:"""Integration tests using a real git repo."""diff --git a/tests/test_extensions.py b/tests/test_extensions.pyindex bec939702..460404d59 100644--- a/tests/test_extensions.py+++ b/tests/test_extensions.py@@ -11,6 +11,7 @@ Tests cover:import pytestimport json+import platformimport tempfileimport shutilimport tomllib@@ -1452,6 +1453,7 @@ scripts:ps: ../../scripts/powershell/setup-plan.ps1 -Jsonagent_scripts:sh: ../../scripts/bash/update-agent-context.sh __AGENT__+ ps: ../../scripts/powershell/update-agent-context.ps1 __AGENT__---Run {SCRIPT}@@ -1473,8 +1475,12 @@ Then {AGENT_SCRIPT}content = skill_file.read_text()assert "{SCRIPT}" not in contentassert "{AGENT_SCRIPT}" not in content- assert '.specify/scripts/bash/setup-plan.sh --json "$ARGUMENTS"' in content- assert ".specify/scripts/bash/update-agent-context.sh codex" in content+ if platform.system().lower().startswith("win"):+ assert ".specify/scripts/powershell/setup-plan.ps1 -Json" in content+ assert ".specify/scripts/powershell/update-agent-context.ps1 codex" in content+ else:+ assert '.specify/scripts/bash/setup-plan.sh --json "$ARGUMENTS"' in content+ assert ".specify/scripts/bash/update-agent-context.sh codex" in contentdef test_codex_skill_registration_handles_non_dict_init_options(self, project_dir, temp_dirdiff --git a/tests/test_timestamp_branches.py b/tests/test_timestamp_branches.pyindex b258fa98d..39228d945 100644--- a/tests/test_timestamp_branches.py+++ b/tests/test_timestamp_branches.py@@ -13,6 +13,8 @@ from pathlib import Pathimport pytest+from tests.conftest import requires_bash+PROJECT_ROOT = Path(__file__).resolve().parent.parentCREATE_FEATURE = PROJECT_ROOT / "scripts" / "bash" / "create-new-feature.sh"CREATE_FEATURE_PS = PROJECT_ROOT / "scripts" / "powershell" / "create-new-feature.ps1"@@ -149,6 +151,7 @@ def source_and_call(func_call: str, env: dict | None = None) -> subprocess.Compl# ββ Timestamp Branch Tests βββββββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestTimestampBranch:def test_timestamp_creates_branch(self, git_repo: Path):"""Test 1: --timestamp creates branch with YYYYMMDD-HHMMSS prefix."""@@ -194,6 +197,7 @@ class TestTimestampBranch:# ββ Sequential Branch Tests ββββββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestSequentialBranch:def test_sequential_default_with_existing_specs(self, git_repo: Path):"""Test 2: Sequential default with existing specs."""@@ -232,6 +236,8 @@ class TestSequentialBranch:branch = line.split(":", 1)[1].strip()assert branch == "1001-next-feat", f"expected 1001-next-feat, got: {branch}"++class TestSequentialBranchPowerShell:def test_powershell_scanner_uses_long_tryparse_for_large_prefixes(self):"""PowerShell scanner should parse large prefixes without [int] casts."""content = CREATE_FEATURE_PS.read_text(encoding="utf-8")@@ -242,6 +248,7 @@ class TestSequentialBranch:# ββ check_feature_branch Tests βββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestCheckFeatureBranch:def test_accepts_timestamp_branch(self):"""Test 6: check_feature_branch accepts timestamp branch."""@@ -306,6 +313,7 @@ class TestCheckFeatureBranch:# ββ find_feature_dir_by_prefix Tests βββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestFindFeatureDirByPrefix:def test_timestamp_branch(self, tmp_path: Path):"""Test 10: find_feature_dir_by_prefix with timestamp branch."""@@ -356,6 +364,7 @@ class TestFindFeatureDirByPrefix:class TestGetFeaturePathsSinglePrefix:+ @requires_bashdef test_bash_specify_feature_prefixed_resolves_by_prefix(self, tmp_path: Path):"""get_feature_paths: SPECIFY_FEATURE with one optional prefix uses effective name for lookup."""(tmp_path / ".specify").mkdir()@@ -399,6 +408,7 @@ class TestGetFeaturePathsSinglePrefix:# ββ get_current_branch Tests βββββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestGetCurrentBranch:def test_env_var(self):"""Test 12: get_current_branch returns SPECIFY_FEATURE env var."""@@ -409,6 +419,7 @@ class TestGetCurrentBranch:# ββ No-git Tests βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestNoGitTimestamp:def test_no_git_timestamp(self, no_git_dir: Path):"""Test 13: No-git repo + timestamp creates spec dir with warning."""@@ -422,6 +433,7 @@ class TestNoGitTimestamp:# ββ E2E Flow Tests βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestE2EFlow:def test_e2e_timestamp(self, git_repo: Path):"""Test 14: E2E timestamp flow β branch, dir, validation."""@@ -455,6 +467,7 @@ class TestE2EFlow:# ββ Allow Existing Branch Tests ββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestAllowExistingBranch:def test_allow_existing_switches_to_branch(self, git_repo: Path):"""T006: Pre-create branch, verify script switches to it."""@@ -655,6 +668,7 @@ class TestGitExtensionParity:# ββ Dry-Run Tests ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestDryRun:def test_dry_run_sequential_outputs_name(self, git_repo: Path):"""T009: Dry-run computes correct branch name with existing specs."""@@ -984,6 +998,7 @@ class TestPowerShellDryRun:# ββ GIT_BRANCH_NAME Override Tests ββββββββββββββββββββββββββββββββββββββββββ+@requires_bashclass TestGitBranchNameOverrideBash:"""Tests for GIT_BRANCH_NAME env var override in extension create-new-feature.sh."""@@ -1088,6 +1103,7 @@ class TestGitBranchNameOverridePowerShell:class TestFeatureDirectoryResolution:"""Tests for SPECIFY_FEATURE_DIRECTORY and .specify/feature.json resolution."""+ @requires_bashdef test_env_var_overrides_branch_lookup(self, git_repo: Path):"""SPECIFY_FEATURE_DIRECTORY env var takes priority over branch-based lookup."""custom_dir = git_repo / "my-custom-specs" / "my-feature"@@ -1110,6 +1126,7 @@ class TestFeatureDirectoryResolution:else:pytest.fail("FEATURE_DIR not found in output")+ @requires_bashdef test_feature_json_overrides_branch_lookup(self, git_repo: Path):"""feature.json feature_directory takes priority over branch-based lookup."""custom_dir = git_repo / "specs" / "custom-feature"@@ -1117,7 +1134,7 @@ class TestFeatureDirectoryResolution:feature_json = git_repo / ".specify" / "feature.json"feature_json.write_text(- f'{{"feature_directory": "{custom_dir}"}}\n',+ json.dumps({"feature_directory": str(custom_dir)}) + "\n",encoding="utf-8",)@@ -1136,6 +1153,7 @@ class TestFeatureDirectoryResolution:else:pytest.fail("FEATURE_DIR not found in output")+ @requires_bashdef test_env_var_takes_priority_over_feature_json(self, git_repo: Path):"""Env var wins over feature.json."""env_dir = git_repo / "specs" / "env-feature"@@ -1145,7 +1163,7 @@ class TestFeatureDirectoryResolution:feature_json = git_repo / ".specify" / "feature.json"feature_json.write_text(- f'{{"feature_directory": "{json_dir}"}}\n',+ json.dumps({"feature_directory": str(json_dir)}) + "\n",encoding="utf-8",)@@ -1165,6 +1183,7 @@ class TestFeatureDirectoryResolution:else:pytest.fail("FEATURE_DIR not found in output")+ @requires_bashdef test_fallback_to_branch_lookup(self, git_repo: Path):"""Without env var or feature.json, falls back to branch-based lookup."""subprocess.run(["git", "checkout", "-q", "-b", "001-test-feat"], cwd=git_repo, check=True)@@ -1219,7 +1238,7 @@ class TestFeatureDirectoryResolution:feature_json = git_repo / ".specify" / "feature.json"feature_json.write_text(- f'{{"feature_directory": "{custom_dir}"}}\n',+ json.dumps({"feature_directory": str(custom_dir)}) + "\n",encoding="utf-8",)