fix(scripts): stop setup-tasks text mode crashing on a legacy code page (#3892)

_check_file/_check_dir hard-code U+2713/U+2717 and print() them to
sys.stdout. On Windows sys.stdout falls back to the ANSI code page whenever
stdout is not a console — which is every time an agent or a workflow step
captures the output — and U+2713 is unencodable in cp1252, so the document
listing aborted mid-report with UnicodeEncodeError.

This is the byte-identical twin of the block in
scripts/python/check_prerequisites.py, which I flagged in the PR for that
file rather than widening its scope.

Fall back to ASCII when stdout cannot encode the glyph. "[OK]"/"[FAIL]" is
the rendering these markers already have in-tree: Test-FileExists in
scripts/powershell/common.ps1 emits exactly those, and
normalize_status_text in tests/parity_helpers.py maps the glyphs onto them.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali jawwad
2026-08-05 08:44:43 -05:00
committed by GitHub
co-authored by Claude Opus 5
parent 6fa8c9aaef
commit f01cac6300
2 changed files with 46 additions and 4 deletions
+25
View File
@@ -205,3 +205,28 @@ def test_missing_template_error_matches_all_variants(repo: Path) -> None:
assert bash.returncode == ps.returncode == py.returncode == 1
assert bash.stdout == ps.stdout == py.stdout == ""
assert bash.stderr == ps.stderr == py.stderr
def test_python_text_output_survives_a_legacy_stdout_code_page(repo: Path) -> None:
"""Text mode must not crash when stdout cannot encode the status glyphs.
On Windows sys.stdout falls back to the ANSI code page whenever it is not a
console — which is every time an agent or a workflow step captures the
output. U+2713 is unencodable in cp1252, so printing it raised
UnicodeEncodeError and truncated the document listing. The ASCII fallback is
the rendering these markers already have in-tree (Test-FileExists in
scripts/powershell/common.ps1, and normalize_status_text).
"""
feature = repo / "specs" / "001-my-feature"
(feature / "research.md").write_text("# research\n", encoding="utf-8")
(feature / "contracts").mkdir()
env = clean_env()
env["PYTHONIOENCODING"] = "cp1252"
result = run(py_cmd(repo, SCRIPT), repo, env=env)
assert result.returncode == 0, result.stderr
assert "UnicodeEncodeError" not in result.stderr
for doc in ("research.md", "data-model.md", "contracts/", "quickstart.md"):
assert doc in result.stdout, (doc, result.stdout)
assert "[OK] research.md" in normalize_status_text(result.stdout), result.stdout