Skip to content

Commit 804e732

Browse files
jawwad-aliclaude
andauthored
fix(scripts): route 'Plan template not found' per --json in setup-plan.ps1 (parity with bash) (#3241)
The 'template not found' fallback used Write-Warning, which emits 'WARNING: Plan template not found' on the warning stream -- diverging from the bash twin (echo 'Warning: Plan template not found' to stderr in --json, stdout in text mode) in both wording and routing, and inconsistent with the sibling 'Copied plan template' message (#3198) in the same block. Route it the same way so the two scripts share one status-output contract. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c5fb3dc commit 804e732

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

scripts/powershell/setup-plan.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ if (Test-Path $paths.IMPL_PLAN -PathType Leaf) {
4848
Write-Output "Copied plan template to $($paths.IMPL_PLAN)"
4949
}
5050
} else {
51-
Write-Warning "Plan template not found"
51+
# Match the bash twin's wording and stream routing (stderr in -Json so
52+
# stdout stays pure JSON, stdout otherwise), consistent with the sibling
53+
# "Copied plan template" message above.
54+
if ($Json) {
55+
[Console]::Error.WriteLine("Warning: Plan template not found")
56+
} else {
57+
Write-Output "Warning: Plan template not found"
58+
}
5259
# Create a basic plan file if template doesn't exist
5360
New-Item -ItemType File -Path $paths.IMPL_PLAN -Force | Out-Null
5461
}

tests/test_setup_plan_no_overwrite.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,27 @@ def test_ps_setup_plan_copied_message_on_stderr_in_json_mode(plan_repo: Path) ->
246246
data = json.loads(result.stdout)
247247
assert "IMPL_PLAN" in data
248248
assert "Copied plan template" in result.stderr
249+
250+
251+
@pytest.mark.skipif(not (HAS_PWSH or _WINDOWS_POWERSHELL), reason="no PowerShell available")
252+
def test_ps_setup_plan_template_not_found_warning_matches_bash(plan_repo: Path) -> None:
253+
"""When no plan template resolves, -Json mode must emit 'Warning: Plan template
254+
not found' on stderr (matching the bash twin's wording and stream routing) while
255+
keeping stdout pure JSON. Before the fix the PowerShell script used Write-Warning,
256+
producing a different 'WARNING:' prefix on the warning stream instead."""
257+
# Remove the template the fixture installs so resolution finds nothing.
258+
(plan_repo / ".specify" / "templates" / "plan-template.md").unlink()
259+
script = plan_repo / ".specify" / "scripts" / "powershell" / "setup-plan.ps1"
260+
exe = "pwsh" if HAS_PWSH else _WINDOWS_POWERSHELL
261+
result = subprocess.run(
262+
[exe, "-NoProfile", "-File", str(script), "-Json"],
263+
cwd=plan_repo,
264+
capture_output=True,
265+
text=True,
266+
check=False,
267+
env=_clean_env(),
268+
)
269+
assert result.returncode == 0, result.stderr
270+
data = json.loads(result.stdout)
271+
assert "IMPL_PLAN" in data
272+
assert "Warning: Plan template not found" in result.stderr

0 commit comments

Comments
 (0)