Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions scripts/bash/check-prerequisites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions scripts/powershell/check-prerequisites.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)"
Expand Down
64 changes: 64 additions & 0 deletions tests/test_check_prerequisites_paths_only.py
Original file line number Diff line number Diff line change
@@ -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)
Comment on lines +21 to +24
Comment on lines +21 to +24

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,
)
Comment on lines +37 to +43

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,
)
Comment on lines +53 to +59

assert result.returncode == 0, result.stderr
payload = json.loads(result.stdout)
assert payload["BRANCH"] == "main"
assert payload["FEATURE_DIR"].endswith("specs/001-test")