Repository navigation
fix(scripts): reconfigure check_prerequisites.py streams as UTF-8 - #5578
leninworld wants to merge 2 commits into
Conversation
check_prerequisites.py printed feature paths with plain print() and never reconfigured its streams. On a legacy or redirected code page (Windows pipes, PYTHONIOENCODING=cp1252 or ascii), text mode and --paths-only text mode raised UnicodeEncodeError for a non-ASCII project or feature path, and stderr diagnostics turned non-ASCII paths into \uXXXX escapes. Reconfigure stdout and stderr to UTF-8 at the script entrypoint with the same helper as setup_plan.py (github#5569) and setup_tasks.py (github#5555). JSON output stays pure ASCII, and direct in-process main() calls keep the ASCII status-marker fallback. Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous) Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
There was a problem hiding this comment.
🟡 Changes recommended
An active moderate issue remains because the test decodes subprocess output using the platform locale while asserting UTF-8 glyphs, causing failures on Windows even when the script is correct.
1 open issue
What changed in this PR
This PR updates the Python prerequisite-checking helper to emit non-ASCII paths reliably under legacy output encodings while preserving ASCII JSON output and in-process status-marker behavior.
Changes:
- Adds tolerant UTF-8 stream reconfiguration at the script entrypoint.
- Adds regression coverage for text, paths-only, JSON, diagnostic, and stream-compatibility scenarios.
- Updates parity expectations for UTF-8 status glyphs from the script entrypoint.
| File | Description |
|---|---|
| tests/test_check_prerequisites_utf8_output.py | Adds regression tests covering non-ASCII paths, diagnostics, JSON output, and stream compatibility under legacy encodings. |
| tests/test_check_prerequisites_python_parity.py | Updates parity expectations for status output produced by the UTF-8-configured script entrypoint. |
| scripts/python/check_prerequisites.py | Reconfigures standard output and error streams to UTF-8 before running prerequisite checks. |
Review effort: Lite (adaptive)
| assert " \u2713 research.md" in result.stdout, result.stdout | ||
| assert " \u2717 quickstart.md" in result.stdout, result.stdout |
The legacy-code-page text test now asserts the real check/cross glyphs, which the script writes as UTF-8. It ran the child through the local _run() helper, which decodes with the parent's locale encoding; on Windows that is the ANSI code page, so the glyphs would arrive as mojibake and the test would fail although the script is correct. Use the shared run() helper from tests/parity_helpers.py, which decodes captured output as UTF-8, for this test only. Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous) Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
|
Review round summary for b19bef6 (posted for @leninworld by Claude Code, model Claude Opus 5.5, autonomous; the fix was implemented by OpenAI Codex CLI, model gpt-5.6-sol, autonomous, and checked by Claude Code).
Checks on macOS (Python 3.13, checkout |

Description
scripts/python/check_prerequisites.pyprints feature paths with plainprint()and never reconfigures its streams. When stdout or stderr uses a legacy code page (Windows falls back to the ANSI code page whenever the output is redirected to a pipe or file, as it is when an agent runs the script; simulated here withPYTHONIOENCODING=cp1252orascii), a project or feature path with characters outside that code page breaks it:--paths-onlytext mode crash withUnicodeEncodeErrorat the firstFEATURE_DIR:/REPO_ROOT:line, exit 1;ERROR: plan.md not found in <path>show the path as\uXXXXescapes.Its siblings were fixed the same way in #5569 (
setup_plan.py) and #5555 (setup_tasks.py);check_prerequisites.pywas the remaining core Python helper without it. This PR adds the same_configure_utf8_streams()helper assetup_plan.pyand calls it at the script entrypoint.--jsonoutput is unchanged (still pure ASCII), and direct in-processmain()calls keep the ASCII[OK]/[FAIL]status-marker fallback.Reproduction on main (macOS):
specify init proj-日本語 --integration claude --script py --ignore-agent-tools, createspecs/001-功能/plan.mdandspec.md, then run.specify/scripts/python/check_prerequisites.pywithSPECIFY_FEATURE_DIRECTORYset to that directory andPYTHONIOENCODING=cp1252(orascii): text mode and--paths-onlyboth end inUnicodeEncodeError, exit 1. With this change a freshspecify initfrom the fixed checkout prints the real paths and exits 0.One existing assertion changes:
test_python_text_output_survives_a_legacy_stdout_code_pageran the script as a cp1252 subprocess and expected the ASCII[OK]/[FAIL]markers. The entrypoint now writes UTF-8, so that subprocess prints the real✓/✗glyphs (matching the bash script), and the test asserts both glyphs. The ASCII fallback is now covered in-process on a cp1252 stream, likesetup_tasks.py's test.Not changed here: the Python helpers shipped with the bundled extensions (
extensions/*/scripts/python/), which are versioned separately.Testing
Set up this checkout's
.venvand editable install using the local development guide. Run commands from the checkout root.Tested locally with
.venv/bin/specify --help(Windows PowerShell:.\.venv\Scripts\specify.exe --help)Ran relevant existing tests with
.venv/bin/python -m pytest tests -q(Windows PowerShell:.\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks andLC_ALL=en_US.UTF-8on macOSTested with a sample project (if applicable)
New
tests/test_check_prerequisites_utf8_output.py(non-ASCII written as escapes), parametrized overcp1252andascii: text mode,--paths-onlytext mode and missing-plan.mdstderr keep the real non-ASCII paths. These 6 cases and the updated parity assertion fail on main and pass with the fix. Guards that pass on both:--jsonand--paths-only --jsonstay pure ASCII with the real path after decoding, the in-process cp1252 fallback still prints[OK]and[FAIL], and the entrypoint works with streams that have noreconfigure()or whosereconfigure()raisesValueError(removing thetry/exceptmakes that case fail).Focused:
tests/test_check_prerequisites_utf8_output.py,tests/test_check_prerequisites_python_parity.py,tests/test_setup_plan_utf8_output.py,tests/test_setup_tasks_utf8_output.py,tests/test_command_template_py_scripts.py: 122 passed, 19 skipped (PowerShell not installed).Full suite with
-n 8on macOS: 17320 passed, 635 skipped, 1 failed:test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer, which fails on main in my environment too (unrelated).uvx ruff@0.15.0 check src tests: all checks passed. pre-commit hooks pass on the changed files.Sample project: the
specify init --script pyreproduction above, before and after.AI Disclosure
AI disclosure: Claude Code (model: Claude Opus 5.5, autonomous) found the missing stream setup by comparing the Python helpers, reproduced it end to end, reviewed the change, adjusted the parity test, ran the tests, lint and hooks, and wrote this description. OpenAI Codex CLI (model: gpt-5.6-sol, autonomous) wrote the fix and tests (code generation) from Claude's task description. The commit carries
Assisted-by:trailers.