Skip to content

Commit 682a15b

Browse files
committed
test(scripts): minimize feature metadata regression coverage
1 parent 737f758 commit 682a15b

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

tests/test_timestamp_branches.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
PROJECT_ROOT = Path(__file__).resolve().parent.parent
1616
CREATE_FEATURE = PROJECT_ROOT / "scripts" / "bash" / "create-new-feature.sh"
1717
CREATE_FEATURE_PS = PROJECT_ROOT / "scripts" / "powershell" / "create-new-feature.ps1"
18+
EXT_CREATE_FEATURE = (
19+
PROJECT_ROOT / "extensions" / "git" / "scripts" / "bash" / "create-new-feature.sh"
20+
)
21+
EXT_CREATE_FEATURE_PS = (
22+
PROJECT_ROOT / "extensions" / "git" / "scripts" / "powershell" / "create-new-feature.ps1"
23+
)
1824
COMMON_SH = PROJECT_ROOT / "scripts" / "bash" / "common.sh"
1925

2026

@@ -106,7 +112,7 @@ def test_json_output_keys(self, git_repo: Path):
106112
assert re.match(r"^\d{8}-\d{6}$", data["FEATURE_NUM"])
107113

108114
def test_writes_feature_metadata_file(self, git_repo: Path):
109-
"""The create script persists .specify/feature.json for downstream commands."""
115+
"""Feature creation persists .specify/feature.json with the created spec dir."""
110116
import json
111117

112118
result = run_script(git_repo, "--json", "--short-name", "meta-test", "Metadata test")
@@ -450,6 +456,35 @@ def test_powershell_supports_allow_existing_branch_flag(self):
450456
# Ensure the flag is referenced in script logic, not just declared
451457
assert "AllowExistingBranch" in contents.replace("-AllowExistingBranch", "")
452458

459+
def test_powershell_persists_feature_metadata(self):
460+
"""Static guard: PS script writes .specify/feature.json."""
461+
contents = CREATE_FEATURE_PS.read_text(encoding="utf-8")
462+
assert "feature_directory = \"specs/$branchName\"" in contents
463+
assert "feature.json" in contents
464+
465+
def test_powershell_surfaces_checkout_errors(self):
466+
"""Static guard: PS script preserves checkout stderr on existing-branch failures."""
467+
contents = CREATE_FEATURE_PS.read_text(encoding="utf-8")
468+
assert "exists but could not be checked out" in contents
469+
470+
471+
class TestGitExtensionParity:
472+
def test_bash_extension_surfaces_checkout_errors(self):
473+
"""Static guard: git extension bash script preserves checkout stderr."""
474+
if not EXT_CREATE_FEATURE.exists():
475+
pytest.skip("git extension bash script not present in this checkout")
476+
contents = EXT_CREATE_FEATURE.read_text(encoding="utf-8")
477+
assert 'switch_branch_error=$(git checkout -q "$BRANCH_NAME" 2>&1)' in contents
478+
assert "Failed to switch to existing branch '$BRANCH_NAME'" in contents
479+
480+
def test_powershell_extension_surfaces_checkout_errors(self):
481+
"""Static guard: git extension PowerShell script preserves checkout stderr."""
482+
if not EXT_CREATE_FEATURE_PS.exists():
483+
pytest.skip("git extension PowerShell script not present in this checkout")
484+
contents = EXT_CREATE_FEATURE_PS.read_text(encoding="utf-8")
485+
assert "$switchBranchError = git checkout -q $branchName 2>&1 | Out-String" in contents
486+
assert "exists but could not be checked out.`n$($switchBranchError.Trim())" in contents
487+
453488

454489
# ── Dry-Run Tests ────────────────────────────────────────────────────────────
455490

@@ -787,18 +822,3 @@ def test_ps_dry_run_json_absent_without_flag(self, ps_git_repo: Path):
787822
assert result.returncode == 0, result.stderr
788823
data = json.loads(result.stdout)
789824
assert "DRY_RUN" not in data, f"DRY_RUN should not be in normal JSON: {data}"
790-
791-
def test_ps_writes_feature_metadata_file(self, ps_git_repo: Path):
792-
"""PowerShell create script persists .specify/feature.json."""
793-
import json
794-
795-
result = run_ps_script(
796-
ps_git_repo, "-Json", "-ShortName", "ps-meta", "PowerShell metadata"
797-
)
798-
assert result.returncode == 0, result.stderr
799-
data = json.loads(result.stdout)
800-
801-
metadata_file = ps_git_repo / ".specify" / "feature.json"
802-
assert metadata_file.exists(), "feature metadata file was not created"
803-
metadata = json.loads(metadata_file.read_text(encoding="utf-8-sig"))
804-
assert metadata == {"feature_directory": f"specs/{data['BRANCH_NAME']}"}

0 commit comments

Comments
 (0)