mirror of
https://github.com/github/spec-kit.git
synced 2026-07-03 12:28:06 +08:00
* feat(init)!: make git extension opt-in and remove --no-git at v0.10.0 - Remove --no-git parameter from specify init command - Remove git extension auto-installation from init flow - Git repository initialization (git init) still runs when git is available - Remove --no-git from all test invocations across the test suite - Update docs to reflect opt-in git extension behavior - Replace TestGitExtensionAutoInstall with TestGitExtensionOptIn tests BREAKING CHANGE: specify init no longer auto-installs the git extension. Use `specify extension add git` to install it explicitly. The --no-git flag has been removed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(scripts): remove git operations from core scripts Git functionality is now entirely managed by the git extension. Core scripts only handle directory-based feature creation and numbering. - Remove has_git(), check_feature_branch(), git branch creation from core - Simplify number detection to use only spec directory scanning - Remove HAS_GIT output from get_feature_paths() - Remove git remote fetching and branch querying - Keep BRANCH_NAME output key for backward compatibility Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor: remove all git operations from core - Remove is_git_repo() and init_git_repo() dead code from _utils.py - Remove --branch-numbering from init command - Remove git from 'specify check' (now extension-only) - Update docs: git is optional prerequisite, check command description - Fix tests to reflect no-git-in-core reality (fallback to main) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(scripts): remove directory scanning and branch fallback from core Core scripts now resolve feature context exclusively from: 1. SPECIFY_FEATURE env var (set by git extension) 2. .specify/feature.json (persisted by specify command) Removed find_feature_dir_by_prefix() and directory scanning heuristics — these are the git extension's responsibility. Scripts error clearly when no feature context is available. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * feat: introduce feature_numbering, deprecate branch_numbering in init-options - specify command template now reads feature_numbering (preferred) with fallback to branch_numbering (deprecated) from init-options.json - Git extension reads git-config.yml > feature_numbering > branch_numbering - init now writes feature_numbering: sequential to init-options.json - Deprecation warning emitted when branch_numbering is used as fallback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: remove trailing whitespace in common.ps1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * feat(scripts): persist SPECIFY_FEATURE_DIRECTORY env var to feature.json When SPECIFY_FEATURE_DIRECTORY is set, get_feature_paths() now writes the value to .specify/feature.json so future sessions without the env var can still resolve the feature directory. The write is idempotent — it skips when the file already contains the same value. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: address review feedback — error messages and docs - Update error messages in common.sh and common.ps1 to reference SPECIFY_FEATURE_DIRECTORY instead of SPECIFY_FEATURE (which no longer resolves feature directories) - Fix get_current_branch comment (returns empty string, not error) - Update upgrade.md to reference SPECIFY_FEATURE_DIRECTORY with correct example paths - Update local-development.md troubleshooting: replace stale 'Git step skipped' row with actionable git extension guidance Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): harden feature.json persistence - Use json_escape in printf fallback when jq is unavailable (common.sh) - Replace utf8NoBOM encoding with UTF8Encoding($false) for PowerShell 5.1 compatibility (common.ps1) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(scripts): remove dead feature_json_matches_feature_dir functions These guards are no longer needed since the branch-name validation they protected against has been removed from check-prerequisites. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(git-ext): rename create-new-feature to create-new-feature-branch The git extension's script only creates the git branch — rename it to reflect that responsibility. The core create-new-feature.sh/.ps1 handles feature directory creation and feature.json persistence. Also includes fixes from review feedback: - common.sh: _persist_feature_json uses json_escape fallback - common.ps1: Save-FeatureJson uses UTF8Encoding for PS 5.1 compat - common.ps1: case-sensitive path stripping on non-Windows - create-new-feature.sh/ps1: output both SPECIFY_FEATURE and SPECIFY_FEATURE_DIRECTORY - setup-tasks.sh: fix stale 'Validate branch' comment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(tests): update references to renamed git extension scripts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(tests): remove duplicate EXT_CREATE_FEATURE assignments Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Manfred Riem <mnriem@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
227 lines
7.7 KiB
Python
227 lines
7.7 KiB
Python
"""Tests for setup-plan preserving existing plan.md (#2653)."""
|
|
|
|
import json
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from tests.conftest import requires_bash
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
|
COMMON_SH = PROJECT_ROOT / "scripts" / "bash" / "common.sh"
|
|
SETUP_PLAN_SH = PROJECT_ROOT / "scripts" / "bash" / "setup-plan.sh"
|
|
COMMON_PS = PROJECT_ROOT / "scripts" / "powershell" / "common.ps1"
|
|
SETUP_PLAN_PS = PROJECT_ROOT / "scripts" / "powershell" / "setup-plan.ps1"
|
|
PLAN_TEMPLATE = PROJECT_ROOT / "templates" / "plan-template.md"
|
|
|
|
HAS_PWSH = shutil.which("pwsh") is not None
|
|
_POWERSHELL = shutil.which("powershell.exe") or shutil.which("powershell")
|
|
|
|
|
|
def _install_bash_scripts(repo: Path) -> None:
|
|
d = repo / ".specify" / "scripts" / "bash"
|
|
d.mkdir(parents=True, exist_ok=True)
|
|
shutil.copy(COMMON_SH, d / "common.sh")
|
|
shutil.copy(SETUP_PLAN_SH, d / "setup-plan.sh")
|
|
|
|
|
|
def _install_ps_scripts(repo: Path) -> None:
|
|
d = repo / ".specify" / "scripts" / "powershell"
|
|
d.mkdir(parents=True, exist_ok=True)
|
|
shutil.copy(COMMON_PS, d / "common.ps1")
|
|
shutil.copy(SETUP_PLAN_PS, d / "setup-plan.ps1")
|
|
|
|
|
|
def _minimal_templates(repo: Path) -> None:
|
|
tdir = repo / ".specify" / "templates"
|
|
tdir.mkdir(parents=True, exist_ok=True)
|
|
shutil.copy(PLAN_TEMPLATE, tdir / "plan-template.md")
|
|
|
|
|
|
def _write_feature_json(
|
|
repo: Path, feature_directory: str = "specs/001-my-feature"
|
|
) -> None:
|
|
(repo / ".specify" / "feature.json").write_text(
|
|
json.dumps({"feature_directory": feature_directory}),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
|
|
def _clean_env() -> dict[str, str]:
|
|
env = os.environ.copy()
|
|
for key in list(env):
|
|
if key.startswith("SPECIFY_"):
|
|
env.pop(key)
|
|
return env
|
|
|
|
|
|
def _git_init(repo: Path) -> None:
|
|
subprocess.run(["git", "init", "-q"], cwd=repo, check=True)
|
|
subprocess.run(
|
|
["git", "config", "user.email", "test@example.com"], cwd=repo, check=True
|
|
)
|
|
subprocess.run(["git", "config", "user.name", "Test User"], cwd=repo, check=True)
|
|
subprocess.run(
|
|
["git", "commit", "--allow-empty", "-m", "init", "-q"], cwd=repo, check=True
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def plan_repo(tmp_path: Path) -> Path:
|
|
repo = tmp_path / "proj"
|
|
repo.mkdir()
|
|
_git_init(repo)
|
|
subprocess.run(
|
|
["git", "checkout", "-q", "-b", "001-my-feature"],
|
|
cwd=repo,
|
|
check=True,
|
|
)
|
|
(repo / ".specify").mkdir()
|
|
_minimal_templates(repo)
|
|
_install_bash_scripts(repo)
|
|
_install_ps_scripts(repo)
|
|
_write_feature_json(repo)
|
|
return repo
|
|
|
|
|
|
# ── Bash tests ────────────────────────────────────────────────────────────
|
|
|
|
|
|
@requires_bash
|
|
def test_setup_plan_creates_plan_when_missing(plan_repo: Path) -> None:
|
|
"""First run must create plan.md from the template."""
|
|
script = plan_repo / ".specify" / "scripts" / "bash" / "setup-plan.sh"
|
|
result = subprocess.run(
|
|
["bash", str(script), "--json"],
|
|
cwd=plan_repo,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
env=_clean_env(),
|
|
)
|
|
assert result.returncode == 0, result.stderr
|
|
data = json.loads(result.stdout)
|
|
plan_path = Path(data["IMPL_PLAN"])
|
|
assert plan_path.is_file()
|
|
# Template content should be present
|
|
content = plan_path.read_text(encoding="utf-8")
|
|
assert len(content) > 0
|
|
|
|
|
|
@requires_bash
|
|
def test_setup_plan_preserves_existing_plan(plan_repo: Path) -> None:
|
|
"""Rerun must not overwrite an existing plan.md."""
|
|
feat = plan_repo / "specs" / "001-my-feature"
|
|
feat.mkdir(parents=True)
|
|
existing_content = "# My carefully authored plan\n\nDo not overwrite me.\n"
|
|
(feat / "plan.md").write_text(existing_content, encoding="utf-8")
|
|
|
|
script = plan_repo / ".specify" / "scripts" / "bash" / "setup-plan.sh"
|
|
result = subprocess.run(
|
|
["bash", str(script), "--json"],
|
|
cwd=plan_repo,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
env=_clean_env(),
|
|
)
|
|
assert result.returncode == 0, result.stderr
|
|
# Plan must be unchanged
|
|
assert (feat / "plan.md").read_text(encoding="utf-8") == existing_content
|
|
|
|
|
|
@requires_bash
|
|
def test_setup_plan_skip_message_on_stderr_in_json_mode(plan_repo: Path) -> None:
|
|
"""In --json mode, status messages must go to stderr, not stdout."""
|
|
feat = plan_repo / "specs" / "001-my-feature"
|
|
feat.mkdir(parents=True)
|
|
(feat / "plan.md").write_text("# existing\n", encoding="utf-8")
|
|
|
|
script = plan_repo / ".specify" / "scripts" / "bash" / "setup-plan.sh"
|
|
result = subprocess.run(
|
|
["bash", str(script), "--json"],
|
|
cwd=plan_repo,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
env=_clean_env(),
|
|
)
|
|
assert result.returncode == 0, result.stderr
|
|
# stdout must be valid JSON (no status messages mixed in)
|
|
data = json.loads(result.stdout)
|
|
assert "IMPL_PLAN" in data
|
|
# The skip message should be on stderr
|
|
assert "already exists" in result.stderr
|
|
|
|
|
|
@requires_bash
|
|
def test_setup_plan_json_parseable_on_first_run(plan_repo: Path) -> None:
|
|
"""In --json mode, first-run stdout must be parseable JSON (no status on stdout)."""
|
|
script = plan_repo / ".specify" / "scripts" / "bash" / "setup-plan.sh"
|
|
result = subprocess.run(
|
|
["bash", str(script), "--json"],
|
|
cwd=plan_repo,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
env=_clean_env(),
|
|
)
|
|
assert result.returncode == 0, result.stderr
|
|
data = json.loads(result.stdout)
|
|
assert "IMPL_PLAN" in data
|
|
assert "Copied plan template" in result.stderr
|
|
|
|
|
|
# ── PowerShell tests ──────────────────────────────────────────────────────
|
|
|
|
|
|
@pytest.mark.skipif(not (HAS_PWSH or _POWERSHELL), reason="no PowerShell available")
|
|
def test_ps_setup_plan_creates_plan_when_missing(plan_repo: Path) -> None:
|
|
"""First run must create plan.md from the template."""
|
|
script = plan_repo / ".specify" / "scripts" / "powershell" / "setup-plan.ps1"
|
|
exe = "pwsh" if HAS_PWSH else _POWERSHELL
|
|
result = subprocess.run(
|
|
[exe, "-NoProfile", "-File", str(script), "-Json"],
|
|
cwd=plan_repo,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
env=_clean_env(),
|
|
)
|
|
assert result.returncode == 0, result.stderr
|
|
data = json.loads(result.stdout)
|
|
plan_path = Path(data["IMPL_PLAN"])
|
|
assert plan_path.is_file()
|
|
content = plan_path.read_text(encoding="utf-8")
|
|
assert len(content) > 0
|
|
|
|
|
|
@pytest.mark.skipif(not (HAS_PWSH or _POWERSHELL), reason="no PowerShell available")
|
|
def test_ps_setup_plan_preserves_existing_plan(plan_repo: Path) -> None:
|
|
"""Rerun must not overwrite an existing plan.md."""
|
|
feat = plan_repo / "specs" / "001-my-feature"
|
|
feat.mkdir(parents=True)
|
|
existing_content = "# My carefully authored plan\n\nDo not overwrite me.\n"
|
|
(feat / "plan.md").write_text(existing_content, encoding="utf-8")
|
|
|
|
script = plan_repo / ".specify" / "scripts" / "powershell" / "setup-plan.ps1"
|
|
exe = "pwsh" if HAS_PWSH else _POWERSHELL
|
|
result = subprocess.run(
|
|
[exe, "-NoProfile", "-File", str(script), "-Json"],
|
|
cwd=plan_repo,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
env=_clean_env(),
|
|
)
|
|
assert result.returncode == 0, result.stderr
|
|
assert (feat / "plan.md").read_text(encoding="utf-8") == existing_content
|
|
# stdout must be valid JSON (no status messages mixed in)
|
|
data = json.loads(result.stdout)
|
|
assert "IMPL_PLAN" in data
|
|
# The skip message should be on stderr
|
|
assert "already exists" in result.stderr
|