-
Notifications
You must be signed in to change notification settings - Fork 7.8k
fix(plan): use .specify/feature.json to allow /speckit.plan on custom git branches (#2305) #2349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
491b60a
fix: allow plan setup to use feature metadata on custom branches
Adr1an04 d584e7f
fix: harden feature metadata validation
Adr1an04 15f173c
fix: use portable feature metadata path
Adr1an04 588c6fc
fix: share feature.json parser and make path compare OS aware
Adr1an04 bf18024
test: isolate setup plan subprocess environment
Adr1an04 b6912ab
fix: normalize feature metadata paths with pwd -P
Adr1an04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| """Tests for setup-plan bypassing branch-pattern checks when feature.json is valid.""" | ||
|
|
||
| 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 | ||
| 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 _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) | ||
| (repo / ".specify").mkdir() | ||
| _minimal_templates(repo) | ||
| _install_bash_scripts(repo) | ||
| _install_ps_scripts(repo) | ||
| return repo | ||
|
|
||
|
|
||
| @requires_bash | ||
| def test_setup_plan_passes_custom_branch_when_feature_json_valid(plan_repo: Path) -> None: | ||
| subprocess.run( | ||
| ["git", "checkout", "-q", "-b", "feature/my-feature-branch"], | ||
| cwd=plan_repo, | ||
| check=True, | ||
| ) | ||
| feat = plan_repo / "specs" / "001-tiny-notes-app" | ||
| feat.mkdir(parents=True) | ||
| (feat / "spec.md").write_text("# spec\n", encoding="utf-8") | ||
| (plan_repo / ".specify" / "feature.json").write_text( | ||
| json.dumps({"feature_directory": "specs/001-tiny-notes-app"}), | ||
| encoding="utf-8", | ||
| ) | ||
| script = plan_repo / ".specify" / "scripts" / "bash" / "setup-plan.sh" | ||
| result = subprocess.run( | ||
| ["bash", str(script)], | ||
| cwd=plan_repo, | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
|
mnriem marked this conversation as resolved.
|
||
| assert result.returncode == 0, result.stderr + result.stdout | ||
| assert (feat / "plan.md").is_file() | ||
|
|
||
|
|
||
| @requires_bash | ||
| def test_setup_plan_fails_custom_branch_without_feature_json(plan_repo: Path) -> None: | ||
| subprocess.run( | ||
| ["git", "checkout", "-q", "-b", "feature/my-feature-branch"], | ||
| cwd=plan_repo, | ||
| check=True, | ||
| ) | ||
| script = plan_repo / ".specify" / "scripts" / "bash" / "setup-plan.sh" | ||
| result = subprocess.run( | ||
| ["bash", str(script)], | ||
| cwd=plan_repo, | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
| assert result.returncode != 0 | ||
| assert "Not on a feature branch" in result.stderr | ||
|
|
||
|
|
||
| @requires_bash | ||
| def test_setup_plan_numbered_branch_unchanged_without_feature_json( | ||
| plan_repo: Path, | ||
| ) -> None: | ||
| subprocess.run( | ||
| ["git", "checkout", "-q", "-b", "001-tiny-notes-app"], | ||
| cwd=plan_repo, | ||
| check=True, | ||
| ) | ||
| feat = plan_repo / "specs" / "001-tiny-notes-app" | ||
| feat.mkdir(parents=True) | ||
| (feat / "spec.md").write_text("# spec\n", encoding="utf-8") | ||
| script = plan_repo / ".specify" / "scripts" / "bash" / "setup-plan.sh" | ||
| result = subprocess.run( | ||
| ["bash", str(script)], | ||
| cwd=plan_repo, | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
| assert result.returncode == 0, result.stderr + result.stdout | ||
| assert (feat / "plan.md").is_file() | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not (HAS_PWSH or _POWERSHELL), reason="no PowerShell available") | ||
| def test_setup_plan_ps_passes_custom_branch_when_feature_json_valid(plan_repo: Path) -> None: | ||
| subprocess.run( | ||
| ["git", "checkout", "-q", "-b", "feature/my-feature-branch"], | ||
| cwd=plan_repo, | ||
| check=True, | ||
| ) | ||
| feat = plan_repo / "specs" / "001-tiny-notes-app" | ||
| feat.mkdir(parents=True) | ||
| (feat / "spec.md").write_text("# spec\n", encoding="utf-8") | ||
| (plan_repo / ".specify" / "feature.json").write_text( | ||
| json.dumps({"feature_directory": "specs/001-tiny-notes-app"}), | ||
| 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)], | ||
| cwd=plan_repo, | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
| assert result.returncode == 0, result.stderr + result.stdout | ||
| assert (feat / "plan.md").is_file() | ||
|
mnriem marked this conversation as resolved.
|
||
|
|
||
|
|
||
| @pytest.mark.skipif(not (HAS_PWSH or _POWERSHELL), reason="no PowerShell available") | ||
| def test_setup_plan_ps_fails_custom_branch_without_feature_json( | ||
| plan_repo: Path, | ||
| ) -> None: | ||
| subprocess.run( | ||
| ["git", "checkout", "-q", "-b", "feature/my-feature-branch"], | ||
| cwd=plan_repo, | ||
| check=True, | ||
| ) | ||
| script = plan_repo / ".specify" / "scripts" / "powershell" / "setup-plan.ps1" | ||
| exe = "pwsh" if HAS_PWSH else _POWERSHELL | ||
| result = subprocess.run( | ||
| [exe, "-NoProfile", "-File", str(script)], | ||
| cwd=plan_repo, | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
| assert result.returncode != 0 | ||
| assert "Not on a feature branch" in result.stderr | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.