mirror of
https://github.com/github/spec-kit.git
synced 2026-07-03 12:28:06 +08:00
fix(scripts): warn when spec template is missing in create-new-feature.ps1 (parity with bash) (#3230)
* fix(scripts): warn when spec template is missing in create-new-feature.ps1 (parity with bash) create-new-feature.sh prints 'Warning: Spec template not found; created empty spec file' to stderr when no spec template resolves, then touches an empty spec. The PowerShell twin created the empty file silently with no warning, so on Windows a missing/broken template tree gave no signal. Emit the same warning on stderr (keeps stdout/JSON pure), matching the bash wording and stream. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: assert create-new-feature.ps1 warns on missing spec template Regression test for the bash/PowerShell parity fix: with no resolvable spec template, the PowerShell script must emit 'Spec template not found' on stderr (matching bash) while keeping stdout parseable JSON and still creating the empty spec file. Gated on pwsh; decodes stdout/stderr as UTF-8. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -211,6 +211,10 @@ if (-not $DryRun) {
|
||||
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||
[System.IO.File]::WriteAllText($specFile, $content, $utf8NoBom)
|
||||
} else {
|
||||
# Match the bash twin (create-new-feature.sh): warn on stderr that no
|
||||
# spec template was found before creating an empty spec file, so the
|
||||
# missing-template signal is not silently swallowed on Windows.
|
||||
[Console]::Error.WriteLine("Warning: Spec template not found; created empty spec file")
|
||||
New-Item -ItemType File -Path $specFile -Force | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,6 +332,27 @@ class TestSequentialBranchPowerShell:
|
||||
assert data["FEATURE_NUM"] == "000"
|
||||
assert data["BRANCH_NAME"] == "000-zero"
|
||||
|
||||
@pytest.mark.skipif(not _has_pwsh(), reason="pwsh not installed")
|
||||
def test_missing_spec_template_warns_matching_bash(self, ps_git_repo: Path):
|
||||
"""When no spec template can be resolved, create-new-feature.ps1 must warn on
|
||||
stderr (and still create an empty spec file), matching the bash twin's
|
||||
'Warning: Spec template not found; created empty spec file'. Before the fix
|
||||
PowerShell created the empty file silently."""
|
||||
# Remove the template the fixture installs so resolution finds nothing.
|
||||
(ps_git_repo / ".specify" / "templates" / "spec-template.md").unlink()
|
||||
script = ps_git_repo / "scripts" / "powershell" / "create-new-feature.ps1"
|
||||
result = subprocess.run(
|
||||
["pwsh", "-NoProfile", "-File", str(script),
|
||||
"-Json", "-ShortName", "no-tmpl", "No template feature"],
|
||||
cwd=ps_git_repo, capture_output=True, text=True, encoding="utf-8",
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert "Spec template not found" in result.stderr
|
||||
# stdout stays parseable JSON and the empty spec file is still created.
|
||||
data = json.loads(result.stdout)
|
||||
spec_file = Path(data["SPEC_FILE"])
|
||||
assert spec_file.is_file()
|
||||
|
||||
|
||||
# ── check_feature_branch Tests ───────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user