Repository navigation
fix: reject whitespace-only plan templates and plan.md across scripts - #5515
Gaoshou101 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unicode-whitespace handling differs across ports, and prerequisite read-error paths lack deterministic negative test coverage.
2 open issues
What changed in this PR
Addresses #5035 by replacing byte-length checks with whitespace-content validation in Spec Kit’s plan setup and prerequisite scripts.
Changes:
- Reject whitespace-only templates and plans across Bash, PowerShell, and Python.
- Handle prerequisite read failures explicitly.
- Expand parity tests for LF/CRLF whitespace, template overrides, and preservation of existing plans.
| File | Description |
|---|---|
tests/test_setup_plan_python_parity.py |
Tests whitespace-template rejection, retry, and existing-plan preservation. |
tests/test_check_prerequisites_python_parity.py |
Adds LF/CRLF whitespace-plan rejection cases. |
scripts/python/setup_plan.py |
Uses strip() to reject whitespace-only templates. |
scripts/python/check_prerequisites.py |
Reads plan content and handles whitespace and read failures. |
scripts/powershell/setup-plan.ps1 |
Uses IsNullOrWhiteSpace for template validation. |
scripts/powershell/check-prerequisites.ps1 |
Adds content validation and explicit read-error handling. |
scripts/bash/setup-plan.sh |
Checks template content with grep and propagates errors. |
scripts/bash/check-prerequisites.sh |
Checks plan content with grep and propagates errors. |
Review effort: Balanced (adaptive)
| if resolve_template_content "plan-template" "$REPO_ROOT" > "$template_file"; then | ||
| if [[ ! -s "$template_file" ]]; then | ||
| _template_grep_status=0 | ||
| LC_ALL=C grep -q '[^[:space:]]' "$template_file" || _template_grep_status=$? |
There was a problem hiding this comment.
Addressed in 6c68b64:
- Added
file_has_non_whitespaceinscripts/bash/common.shand wired bothscripts/bash/setup-plan.shandscripts/bash/check-prerequisites.shto it. It keeps a fastLC_ALL=C grep -q '[!-~]'check for visible ASCII and strips UTF-8 Unicode whitespace (U+0085,U+00A0,U+1680,U+2000–U+200A,U+2028,U+2029,U+202F,U+205F,U+3000) plus ASCII whitespace via pure POSIXLC_ALL=C sed+tr(no Python 3 runtime dependency). - Added UTF-8 Unicode-whitespace cases (
U+00A0+U+2003LF,U+3000+U+202FCRLF, override templates, and no-Python Bash tests) to bothtests/test_setup_plan_python_parity.pyandtests/test_check_prerequisites_python_parity.py.
| except OSError as exc: | ||
| print(f"ERROR: Failed to read {paths.impl_plan}: {exc}", file=sys.stderr) | ||
| return 1 |
There was a problem hiding this comment.
Addressed in 6c68b64:
- Added
test_plan_prerequisite_read_error_fails_explicitlyacross Bash, PowerShell, and Python (chmod 0on POSIX when enforced;msvcrt.lockingexclusive byte-range lock on Windows) plustest_bash_plan_prerequisite_propagates_grep_read_error, asserting emptystdout, explicitERROR: Failed to read ...diagnostic (notplan.md is empty), unchangedplan.mdbytes/mtime, exit1for Python/PowerShell, and propagated status> 1for Bash (scripts/bash/check-prerequisites.shalso now emitsERROR: Failed to read ...before exiting). - Updated the PR description with Windows PowerShell 5.1 (.NET Framework 4.x) API compatibility verification (
[string]::IsNullOrWhiteSpace,[System.IO.File]::ReadAllText(..., [System.Text.Encoding]::UTF8), ASCII-only.ps1check intests/test_ps1_encoding.py, and.NET Core-only member guard intests/test_init_dir.py) along with local Linux test limitations.
…tests - Add pure-POSIX file_has_non_whitespace in scripts/bash/common.sh (visible ASCII grep fast path + UTF-8 Unicode whitespace sed/tr strip) so setup-plan.sh and check-prerequisites.sh reject Unicode whitespace (such as U+00A0, U+2003, U+3000, U+202F) consistently with Python and PowerShell without requiring Python 3 - Emit explicit 'ERROR: Failed to read ...' diagnostic on unreadable plan.md in Bash check-prerequisites.sh while propagating error status > 1 - Expand setup-plan and check-prerequisites parity suites with Unicode whitespace template, override, and plan.md cases - Add deterministic negative tests for unreadable plan.md across ports and propagated Bash grep read errors
|
Thanks for the review feedback! Both findings have been addressed in 6c68b64:
Verification
|
| rm -f "$_tmp_in" "$_tmp_out" | ||
| return 2 | ||
| fi | ||
| _rem_len=$(LC_ALL=C tr -d '[:space:]' < "$_tmp_out" | wc -c | tr -d '[:space:]') || { rm -f "$_tmp_in" "$_tmp_out"; return 2; } |
|
Please address Copilot feedback |


Fixes #5035
Description
Previously,
setup-planandcheck-prerequisiteschecked for an emptyplan-template.mdorplan.mdby byte length (-s/Length -eq 0/template_content == ""/st_size == 0), allowing whitespace-only files (such as\n \n\t\n, CRLF whitespace, or UTF-8 Unicode spaces likeU+00A0/U+2003/U+3000) to pass validation.This PR aligns all three script ports (Bash, PowerShell, and Python) so whitespace-only content is treated as empty while preserving existing behavior for missing or valid non-whitespace files and failing explicitly on unreadable
plan.mdfiles:scripts/python/setup_plan.py: Checknot template_content.strip()before writingplan.md.scripts/python/check_prerequisites.py: Readplan.md(OSErrorfails explicitly with exit1) and checknot plan_content.strip().scripts/bash/common.sh,scripts/bash/setup-plan.sh&scripts/bash/check-prerequisites.sh: Addfile_has_non_whitespacehelper so Bash matches Python/PowerShell whitespace semantics across ASCII and UTF-8 Unicode whitespace (LC_ALL=C grep -q '[!-~]'fast path for visible ASCII, plus a pure-POSIXLC_ALL=C sed+trUTF-8 Unicode-whitespace strip with zero Python dependency), while treating status1as empty/whitespace-only and emittingERROR: Failed to read ...+ propagatinggreperror status (> 1) on unreadable/I/O errors.scripts/powershell/setup-plan.ps1&scripts/powershell/check-prerequisites.ps1: Check[string]::IsNullOrWhiteSpace(...)(with explicit[System.IO.File]::ReadAllText(..., [System.Text.Encoding]::UTF8)read error handling incheck-prerequisites.ps1).tests/test_setup_plan_python_parity.py&tests/test_check_prerequisites_python_parity.py: Updatetest_plan_prerequisite_diagnostics,test_plan_template_failure_and_retry,test_existing_plan_is_preserved, and replacetest_whitespace_plan_template_is_not_emptywithtest_whitespace_plan_template_is_rejected(covering LF, CRLF, and UTF-8 Unicode whitespace across template, override, Bash no-Python fallback, andplan.md), plus add deterministicplan.mdread-failure negative tests (test_plan_prerequisite_read_error_fails_explicitlyandtest_bash_plan_prerequisite_propagates_grep_read_error).Windows PowerShell 5.1 compatibility & test scope
.ps1files remain strictly ASCII-only (tests/test_ps1_encoding.pypassed) and avoid.NET Core-only[System.IO.Path]members (tests/test_init_dir.pystatic 5.1 guard passed).[string]::IsNullOrWhiteSpace(string)(.NET Framework 4.0+),[System.IO.File]::ReadAllText(string, System.Text.Encoding)(.NET Framework 2.0+, already used throughoutscripts/powershell/common.ps1),[System.Text.Encoding]::UTF8,[Console]::Error.WriteLine(...), andTest-Path -LiteralPath ... -PathType Leaf(PowerShell 3.0+)—are native to Windows PowerShell 5.1.pwsh, Windows PowerShell 5.1, orshellcheckinstalled, so the 105 PowerShell runtime parity cases were skipped locally bypytest(they run onwindows-latest/pwshin CI). Bash + Python parity (298 passed),.ps1ASCII/static PS 5.1 checks,bash -n, Bash 3.2 case-modification portability checks,check_file_helper_migration.py,git diff --check, anduvx ruff@0.15.0 checkpassed locally. Existingsetup-planpreservation of an already-present empty or whitespace-onlyplan.mdremains unchanged.Testing
Set up this checkout's
.venvand editable install using the local development guide. Run commands from the checkout root..venv/bin/specify --help(Windows PowerShell:.\.venv\Scripts\specify.exe --help).venv/bin/python -m pytest tests -q(Windows PowerShell:.\.venv\Scripts\python.exe -m pytest tests -q); focused suite (tests/test_setup_plan_python_parity.py,tests/test_setup_plan_no_overwrite.py,tests/test_setup_plan_feature_json.py,tests/test_check_prerequisites_python_parity.py,tests/test_check_prerequisites_paths_only.py,tests/test_ps1_encoding.py,tests/test_init_dir.py,tests/test_agent_config_consistency.py,tests/contract/test_wheel_core_pack_scripts.py,tests/contract/test_file_helper_migration_guard.py) passed: 298 passed, 105 skipped (PowerShell unavailable on Linux)AI Disclosure
AI disclosure: Assisted by Hermes Agent (
gemini-4-hydrogen-xhigh/gemini-4-carbon) for root-cause analysis, cross-port patch generation (Bash/PowerShell/Python), and parity/negative test updates, with independent review passes bygpt-6.2-solandclaude-opus-5-5. All code edits and Bash/Python parity tests were executed and verified locally in the repository.venv.