Skip to content

Commit 2e7e49c

Browse files
test: add PowerShell normal-mode persistence guard (#3025)
Addresses Copilot review feedback on #3190: the bash side had a `test_normal_mode_still_persists_feature_json` guard, but there was no symmetric PowerShell test asserting that running check-prerequisites.ps1 *without* -PathsOnly still persists the SPECIFY_FEATURE_DIRECTORY override into .specify/feature.json. Add test_ps_normal_mode_still_persists_feature_json, which guards against accidentally passing -NoPersist unconditionally (or flipping the default) in a future refactor. Verified it fails when -NoPersist is passed in the non -PathsOnly branch and passes with the current conditional. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 024ccda commit 2e7e49c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎tests/test_check_prerequisites_paths_only.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,35 @@ def test_ps_paths_only_does_not_persist_feature_json(prereq_repo: Path) -> None:
372372
data = json.loads(result.stdout)
373373
assert "002-other" in data["FEATURE_DIR"]
374374
assert fj.read_text(encoding="utf-8") == before
375+
376+
377+
@pytest.mark.skipif(not (HAS_PWSH or _WINDOWS_POWERSHELL), reason="no PowerShell available")
378+
def test_ps_normal_mode_still_persists_feature_json(prereq_repo: Path) -> None:
379+
"""Without -PathsOnly, the env override is still persisted to feature.json,
380+
so the -NoPersist opt-out does not regress normal write behavior (#3025).
381+
382+
Symmetric to the bash test_normal_mode_still_persists_feature_json guard:
383+
asserts the default path still persists and that -NoPersist is not passed
384+
unconditionally.
385+
"""
386+
(prereq_repo / "specs" / "001-my-feature").mkdir(parents=True, exist_ok=True)
387+
feat = prereq_repo / "specs" / "002-other"
388+
feat.mkdir(parents=True, exist_ok=True)
389+
(feat / "plan.md").write_text("# plan\n", encoding="utf-8")
390+
_write_feature_json(prereq_repo, "specs/001-my-feature")
391+
fj = prereq_repo / ".specify" / "feature.json"
392+
393+
script = prereq_repo / ".specify" / "scripts" / "powershell" / "check-prerequisites.ps1"
394+
exe = "pwsh" if HAS_PWSH else _WINDOWS_POWERSHELL
395+
env = _clean_env()
396+
env["SPECIFY_FEATURE_DIRECTORY"] = "specs/002-other"
397+
result = subprocess.run(
398+
[exe, "-NoProfile", "-File", str(script), "-Json"],
399+
cwd=prereq_repo,
400+
capture_output=True,
401+
text=True,
402+
check=False,
403+
env=env,
404+
)
405+
assert result.returncode == 0, result.stderr
406+
assert json.loads(fj.read_text(encoding="utf-8"))["feature_directory"] == "specs/002-other"

0 commit comments

Comments
 (0)