tools/scripts: set errors=replace on stdout in the eight remaining programs (TOOL-STDOUT-GUARD-REMAINING) #2531
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2531"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by cweohme on 2026-11-28T00:50:48Z.
Claimed in the coordination issue as: TOOL-STDOUT-GUARD-REMAINING (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231230764)
What and why
tests/test_tool_stdout_encoding.pyfails on currentmain: eight programs undertools/andscripts/still start their__main__block withoutsys.stdout.reconfigure(errors="replace"). With stdout redirected on a Windows ANSI code page (python -IignoresPYTHONUTF8), a path outside the code page — a Cyrillic user name, for example — ends the run withUnicodeEncodeError, the same crash #1406 fixed inmake_game.py.This adds the one-line guard to the eight remaining programs, following the existing pattern (
exe_sha.py, #605):tools/leonida_launcher.pytools/ps_prompt_glyphs.pytools/victory_saves.pytools/volume_stats.pytools/world_hotspots.pyscripts/fetch_vkd3d_proton.pyscripts/port_ctl.pyscripts/sync_victory.pyNo open PR or recent claim touches these files (searched open PRs by each name and the latest coordination comments in #1608).
scripts/run_wine_tests.pystays inNOT_YET_GUARDEDas before.Tested
python -I tests/test_tool_stdout_encoding.py— fails onmain(8 programs missing the guard), passes with this change (4 tests, OK)python -I tests/test_tool_startup.py— OKpython -I tests/test_victory_saves.py— OKpython -m compileall -q make_game.py tools tests— cleanpython -I scripts/run_semantic_tests.py tests/semantic— 505 files, 6397 tests, 0 failed (198 s, 16 jobs)test_docs_cli_flags,test_docs_python_deps,test_docs_repo_paths,test_make_game_preflight,test_progress_dashboard) are pre-existing onmainand untouched here.GPUs tested: n/a (no GPU code touched)
AI-assisted: yes (Qwen Code agent, reviewed by the submitter)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a — no translator rule)Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T03:02:26Z.
#2531 | head
635bab171f(merged cleanly with main02f71ccfe) |python -I tests/test_tool_stdout_encoding.py| red on main: FAILED (failures=1) in 4 tests (8 unguarded__main__programs) | green on PR+main: Ran 4 tests, OK | Windows 11, Python 3.12.10 | AI-assisted: yesDiff reviewed line-by-line across all 8 files (each adds only
sys.stdout.reconfigure(errors="replace")inif __name__ == "__main__":). Also verified on mergedPR+main:python -I tests/test_tool_startup.py(2/2 OK),python -I tests/test_victory_saves.py(3/3 OK),python -I tests/test_text_write_line_endings.py(3/3 OK),python -m compileall -q make_game.py tools scripts tests,git diff --check, andscripts/check_no_game_data.pyon all 8 touched files (clean).Imported from ubiquitarianism/leonida. Originally posted by GrahamboJangles on 2026-11-28T08:07:18Z.
Reviewed
635bab171f309c23525c834f578de41ab46f8e77(my clone; Windows 11, Python 3.13.14,python3 -I -X utf8=0, no game data).The eight guards check out. Each of the eight files adds exactly one line,
sys.stdout.reconfigure(errors="replace"), as the first statement of the__main__block — before the call, so it applies to everythingmain()prints. All eight already callsys.exit(main())/sys.argvin that same block, sosysis imported: no new import needed. None of the eight reassignssys.stdoutor wraps it (no colorama-style re-wrapping anywhere in them), so theerrors="replace"setting survives to the actual writes — grep forsys.stdout =/coloramain all eight: zero hits.Delta, tested both sides.
tests/test_tool_stdout_encoding.pyis a pre-existing file, not touched by this PR — so the test-count delta comes from its static class. At the PR base (431ceba4f4a55c69c26fcf0e36fd83e86e1b9a32) I replayed the static scan (same regex, same dirs,git showblobs, no checkout needed) and it reports exactly the eight programs this PR fixes, top level. At the head,python3 -I -X utf8=0 tests/test_tool_stdout_encoding.py -vruns 4 tests, all OK in 3.6s, including the two measured-crash tools (analyze_4240_full.py,meshlet_page.py) andscripts/audit_shader4_regs.py+viewer/serve.pycases — those four were already guarded before the PR; they pass at the head as before. So green-on-PR is a real fix, not a test that moved.One coverage gap worth a follow-up (not a defect in this PR). The static scan walks
os.listdiroftools/,scripts/,viewer/— one level deep. Two nested programs have__main__blocks and carry no guard anywhere in the file, and the scan will never see them:tools/conformance/compare.pytools/hw_oracle/runner.pyBoth are invoked in CI (
.github/workflows/runtime.ymlruns them with piped stdout), so they meet the same "run the same way" condition the docstring states for the guard requirement. CI paths are ASCII today, so they are not crashing in practice — but if the rule is "every CLI program under those trees guards stdout", either the scan should recurse or these two should get the guard when their files next change.scripts/run_wine_tests.pyinNOT_YET_GUARDEDmatches the exclusion comment; the "remaining" count matches: base had exactly these eight unguarded at the scanned level.Verdict: approve-by-reading + local green — I did not click Approve (no merge-side effects from me). The eight one-liners are uniform, correct, and in the right spot.
Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-28T11:14:57Z.
Checked on Linux, CPU only: merged with current main
4a54aedcit merges cleanly, buttests/test_tool_stdout_encoding.py::test_every_main_block_reconfigures_stdoutstill fails, now listing two files this branch predates:scripts/bench_translate.pyandscripts/export_old_pr_manifest.py(both came into main with themandy/mainmerge after your base431ceba4). With those two guarded as well, the test passes on that merge (4/4 here). The other eight are covered by this PR.AI-assisted (Claude Code); I ran the test and checked the result.
Generated by Claude Code
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T13:03:05Z.
Red: tests/test_tool_stdout_encoding.py fails on main
09c153948listing the 8 programs; with the PR they leave the list. On maina997a3cit still fails on 2 newer programs outside this PR (scripts/bench_translate.py, scripts/export_old_pr_manifest.py).Targeted batch of 30 PRs (their tests, the tests importing the changed modules, the docs tests, the translator suite) on main
a997a3c: no new failure, Windows 11 / Python.AI-assisted (Claude Code, Claude Opus 5.5)