From eb7f8a52dc446e68ff3feabffbd556521ae0a8d8 Mon Sep 17 00:00:00 2001 From: prantikmedhi <140103052+prantikmedhi@users.noreply.github.com> Date: Fri, 15 May 2026 10:24:23 +0530 Subject: [PATCH] fix: skip branch check for paths-only --- scripts/bash/check-prerequisites.sh | 5 +- scripts/powershell/check-prerequisites.ps1 | 10 +-- tests/test_check_prerequisites_paths_only.py | 64 ++++++++++++++++++++ 3 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 tests/test_check_prerequisites_paths_only.py diff --git a/scripts/bash/check-prerequisites.sh b/scripts/bash/check-prerequisites.sh index 88a5559460..169646d674 100644 --- a/scripts/bash/check-prerequisites.sh +++ b/scripts/bash/check-prerequisites.sh @@ -78,11 +78,10 @@ done SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/common.sh" -# Get feature paths and validate branch +# Get feature paths _paths_output=$(get_feature_paths) || { echo "ERROR: Failed to resolve feature paths" >&2; exit 1; } eval "$_paths_output" unset _paths_output -check_feature_branch "$CURRENT_BRANCH" "$HAS_GIT" || exit 1 # If paths-only mode, output paths and exit (support JSON + paths-only combined) if $PATHS_ONLY; then @@ -112,6 +111,8 @@ if $PATHS_ONLY; then exit 0 fi +check_feature_branch "$CURRENT_BRANCH" "$HAS_GIT" || exit 1 + # Validate required directories and files if [[ ! -d "$FEATURE_DIR" ]]; then echo "ERROR: Feature directory not found: $FEATURE_DIR" >&2 diff --git a/scripts/powershell/check-prerequisites.ps1 b/scripts/powershell/check-prerequisites.ps1 index 91667e9ef1..ca7f22e0a5 100644 --- a/scripts/powershell/check-prerequisites.ps1 +++ b/scripts/powershell/check-prerequisites.ps1 @@ -56,13 +56,9 @@ EXAMPLES: # Source common functions . "$PSScriptRoot/common.ps1" -# Get feature paths and validate branch +# Get feature paths $paths = Get-FeaturePathsEnv -if (-not (Test-FeatureBranch -Branch $paths.CURRENT_BRANCH -HasGit:$paths.HAS_GIT)) { - exit 1 -} - # If paths-only mode, output paths and exit (support combined -Json -PathsOnly) if ($PathsOnly) { if ($Json) { @@ -85,6 +81,10 @@ if ($PathsOnly) { exit 0 } +if (-not (Test-FeatureBranch -Branch $paths.CURRENT_BRANCH -HasGit:$paths.HAS_GIT)) { + exit 1 +} + # Validate required directories and files if (-not (Test-Path $paths.FEATURE_DIR -PathType Container)) { Write-Output "ERROR: Feature directory not found: $($paths.FEATURE_DIR)" diff --git a/tests/test_check_prerequisites_paths_only.py b/tests/test_check_prerequisites_paths_only.py new file mode 100644 index 0000000000..5c0a770a2f --- /dev/null +++ b/tests/test_check_prerequisites_paths_only.py @@ -0,0 +1,64 @@ +"""Regression tests for check-prerequisites paths-only behavior.""" + +import json +import shutil +import subprocess +from pathlib import Path + +import pytest + +from tests.conftest import requires_bash + +PROJECT_ROOT = Path(__file__).resolve().parent.parent +BASH_SCRIPT = PROJECT_ROOT / "scripts" / "bash" / "check-prerequisites.sh" +PS_SCRIPT = PROJECT_ROOT / "scripts" / "powershell" / "check-prerequisites.ps1" +HAS_PWSH = shutil.which("pwsh") is not None + + +@pytest.fixture +def git_repo(tmp_path: Path) -> Path: + """Create a minimal spec-kit-style git repo with a fixed feature directory.""" + subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True) + subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True) + subprocess.run(["git", "config", "user.name", "Test User"], cwd=tmp_path, check=True) + subprocess.run(["git", "checkout", "-b", "main"], cwd=tmp_path, check=True) + + specify_dir = tmp_path / ".specify" + specify_dir.mkdir() + (specify_dir / "feature.json").write_text( + json.dumps({"feature_directory": "specs/001-test"}), encoding="utf-8" + ) + (tmp_path / "specs" / "001-test").mkdir(parents=True) + return tmp_path + + +@requires_bash +def test_bash_paths_only_skips_branch_validation(git_repo: Path) -> None: + result = subprocess.run( + ["bash", str(BASH_SCRIPT), "--json", "--paths-only"], + cwd=git_repo, + text=True, + capture_output=True, + check=False, + ) + + assert result.returncode == 0, result.stderr + payload = json.loads(result.stdout) + assert payload["BRANCH"] == "main" + assert payload["FEATURE_DIR"].endswith("specs/001-test") + + +@pytest.mark.skipif(not HAS_PWSH, reason="pwsh not available") +def test_powershell_paths_only_skips_branch_validation(git_repo: Path) -> None: + result = subprocess.run( + ["pwsh", "-NoLogo", "-NoProfile", "-File", str(PS_SCRIPT), "-Json", "-PathsOnly"], + cwd=git_repo, + text=True, + capture_output=True, + check=False, + ) + + assert result.returncode == 0, result.stderr + payload = json.loads(result.stdout) + assert payload["BRANCH"] == "main" + assert payload["FEATURE_DIR"].endswith("specs/001-test")