|
15 | 15 | PROJECT_ROOT = Path(__file__).resolve().parent.parent |
16 | 16 | CREATE_FEATURE = PROJECT_ROOT / "scripts" / "bash" / "create-new-feature.sh" |
17 | 17 | 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 | +) |
18 | 24 | COMMON_SH = PROJECT_ROOT / "scripts" / "bash" / "common.sh" |
19 | 25 |
|
20 | 26 |
|
@@ -106,7 +112,7 @@ def test_json_output_keys(self, git_repo: Path): |
106 | 112 | assert re.match(r"^\d{8}-\d{6}$", data["FEATURE_NUM"]) |
107 | 113 |
|
108 | 114 | 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.""" |
110 | 116 | import json |
111 | 117 |
|
112 | 118 | 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): |
450 | 456 | # Ensure the flag is referenced in script logic, not just declared |
451 | 457 | assert "AllowExistingBranch" in contents.replace("-AllowExistingBranch", "") |
452 | 458 |
|
| 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 | + |
453 | 488 |
|
454 | 489 | # ── Dry-Run Tests ──────────────────────────────────────────────────────────── |
455 | 490 |
|
@@ -787,18 +822,3 @@ def test_ps_dry_run_json_absent_without_flag(self, ps_git_repo: Path): |
787 | 822 | assert result.returncode == 0, result.stderr |
788 | 823 | data = json.loads(result.stdout) |
789 | 824 | 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