Skip to content

fix(scripts): reconfigure check_prerequisites.py streams as UTF-8 - #5578

Open
leninworld wants to merge 2 commits into
github:mainfrom
leninworld:fix/check-prerequisites-utf8-streams
Open

leninworld wants to merge 2 commits into
github:mainfrom
leninworld:fix/check-prerequisites-utf8-streams

Conversation

@leninworld

Copy link
Copy Markdown
Contributor

Description

scripts/python/check_prerequisites.py prints feature paths with plain print() 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 with PYTHONIOENCODING=cp1252 or ascii), a project or feature path with characters outside that code page breaks it:

  • text mode and --paths-only text mode crash with UnicodeEncodeError at the first FEATURE_DIR: / REPO_ROOT: line, exit 1;
  • stderr diagnostics such as ERROR: plan.md not found in <path> show the path as \uXXXX escapes.

Its siblings were fixed the same way in #5569 (setup_plan.py) and #5555 (setup_tasks.py); check_prerequisites.py was the remaining core Python helper without it. This PR adds the same _configure_utf8_streams() helper as setup_plan.py and calls it at the script entrypoint. --json output is unchanged (still pure ASCII), and direct in-process main() calls keep the ASCII [OK]/[FAIL] status-marker fallback.

Reproduction on main (macOS): specify init proj-日本語 --integration claude --script py --ignore-agent-tools, create specs/001-功能/plan.md and spec.md, then run .specify/scripts/python/check_prerequisites.py with SPECIFY_FEATURE_DIRECTORY set to that directory and PYTHONIOENCODING=cp1252 (or ascii): text mode and --paths-only both end in UnicodeEncodeError, exit 1. With this change a fresh specify init from the fixed checkout prints the real paths and exits 0.

One existing assertion changes: test_python_text_output_survives_a_legacy_stdout_code_page ran 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, like setup_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 .venv and 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 and LC_ALL=en_US.UTF-8 on macOS

  • Tested with a sample project (if applicable)

  • New tests/test_check_prerequisites_utf8_output.py (non-ASCII written as escapes), parametrized over cp1252 and ascii: text mode, --paths-only text mode and missing-plan.md stderr 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: --json and --paths-only --json stay 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 no reconfigure() or whose reconfigure() raises ValueError (removing the try/except makes 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 8 on 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 py reproduction above, before and after.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

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.

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)
@leninworld
leninworld requested a review from mnriem as a code owner November 25, 2026 20:22
Copilot AI adaptive review requested due to automatic review settings November 25, 2026 20:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)

Comment on lines +422 to +423
assert " \u2713 research.md" in result.stdout, result.stdout
assert " \u2717 quickstart.md" in result.stdout, result.stdout
@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 25, 2026
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)
Copilot AI adaptive review requested due to automatic review settings November 26, 2026 01:37
@leninworld

Copy link
Copy Markdown
Contributor Author

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 .venv): tests/test_check_prerequisites_python_parity.py and tests/test_check_prerequisites_utf8_output.py give 59 passed, 17 skipped (PowerShell cases); uvx ruff@0.15.0 check src tests passes. The Windows job has not run for this PR yet, so Windows behaviour is not verified locally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants