tools/scripts: set errors=replace on stdout in the eight remaining programs (TOOL-STDOUT-GUARD-REMAINING) #2531

Manually merged
github merged 1 commit from github-bot/gh-2531 into main 2026-11-28 13:03:42 +00:00 AGit
Owner

@⁠cweohme on GitHub · 2026-11-28 00:50 UTC · original
cweohme:stdout-guard-remaining → main · +8 −0 · 8 files · 1 commits · merged 2026-11-28 13:03 UTC

Claimed in the coordination issue as: TOOL-STDOUT-GUARD-REMAINING (#1608)

What and why

tests/test_tool_stdout_encoding.py fails on current main: eight programs under tools/ and scripts/ still start their __main__ block without sys.stdout.reconfigure(errors="replace"). With stdout redirected on a Windows ANSI code page (python -I ignores PYTHONUTF8), a path outside the code page — a Cyrillic user name, for example — ends the run with UnicodeEncodeError, the same crash #1406 fixed in make_game.py.

This adds the one-line guard to the eight remaining programs, following the existing pattern (exe_sha.py, #605):

  • tools/leonida_launcher.py
  • tools/ps_prompt_glyphs.py
  • tools/victory_saves.py
  • tools/volume_stats.py
  • tools/world_hotspots.py
  • scripts/fetch_vkd3d_proton.py
  • scripts/port_ctl.py
  • scripts/sync_victory.py

No 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.py stays in NOT_YET_GUARDED as before.

Tested

  • python -I tests/test_tool_stdout_encoding.py — fails on main (8 programs missing the guard), passes with this change (4 tests, OK)
  • python -I tests/test_tool_startup.py — OK
  • python -I tests/test_victory_saves.py — OK
  • python -m compileall -q make_game.py tools tests — clean
  • python -I scripts/run_semantic_tests.py tests/semantic — 505 files, 6397 tests, 0 failed (198 s, 16 jobs)
  • Windows 11, Python 3.15.2, Ryzen 7 5700X. The other five failures in a full stdlib sweep (test_docs_cli_flags, test_docs_python_deps, test_docs_repo_paths, test_make_game_preflight, test_progress_dashboard) are pre-existing on main and untouched here.

GPUs tested: n/a (no GPU code touched)

AI-assisted: yes (Qwen Code agent, reviewed by the submitter)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — no translator rule)
**@⁠cweohme** on GitHub · 2026-11-28 00:50 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2531) `cweohme:stdout-guard-remaining` → `main` · +8 −0 · 8 files · 1 commits · merged 2026-11-28 13:03 UTC Claimed in the coordination issue as: TOOL-STDOUT-GUARD-REMAINING (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `tests/test_tool_stdout_encoding.py` fails on current `main`: eight programs under `tools/` and `scripts/` still start their `__main__` block without `sys.stdout.reconfigure(errors="replace")`. With stdout redirected on a Windows ANSI code page (`python -I` ignores `PYTHONUTF8`), a path outside the code page — a Cyrillic user name, for example — ends the run with `UnicodeEncodeError`, the same crash #1406 fixed in `make_game.py`. This adds the one-line guard to the eight remaining programs, following the existing pattern (`exe_sha.py`, #605): - `tools/leonida_launcher.py` - `tools/ps_prompt_glyphs.py` - `tools/victory_saves.py` - `tools/volume_stats.py` - `tools/world_hotspots.py` - `scripts/fetch_vkd3d_proton.py` - `scripts/port_ctl.py` - `scripts/sync_victory.py` No 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.py` stays in `NOT_YET_GUARDED` as before. ### Tested - `python -I tests/test_tool_stdout_encoding.py` — fails on `main` (8 programs missing the guard), passes with this change (4 tests, OK) - `python -I tests/test_tool_startup.py` — OK - `python -I tests/test_victory_saves.py` — OK - `python -m compileall -q make_game.py tools tests` — clean - `python -I scripts/run_semantic_tests.py tests/semantic` — 505 files, 6397 tests, 0 failed (198 s, 16 jobs) - Windows 11, Python 3.15.2, Ryzen 7 5700X. The other five failures in a full stdlib sweep (`test_docs_cli_flags`, `test_docs_python_deps`, `test_docs_repo_paths`, `test_make_game_preflight`, `test_progress_dashboard`) are pre-existing on `main` and untouched here. GPUs tested: n/a (no GPU code touched) AI-assisted: yes (Qwen Code agent, reviewed by the submitter) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — no translator rule)
test_tool_stdout_encoding fails on main: leonida_launcher, ps_prompt_glyphs,
victory_saves, volume_stats, world_hotspots, fetch_vkd3d_proton, port_ctl and
sync_victory still print paths a Windows ANSI code page cannot encode, and die
with UnicodeEncodeError when stdout is redirected under python -I. Add the
same one-line guard the other programs already have (exe_sha.py, #605).

Tested: test_tool_stdout_encoding (4 tests), test_tool_startup,
test_victory_saves, compileall, run_semantic_tests (6397 tests, 0 failed).
AI-assisted: yes (Qwen Code).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 00:51:38 +00:00
Author
Owner

@⁠zmasi on GitHub · 2026-11-28 03:02 UTC · original

#2531 | head 635bab171f (merged cleanly with main 02f71ccfe) | 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: yes

Diff reviewed line-by-line across all 8 files (each adds only sys.stdout.reconfigure(errors="replace") in if __name__ == "__main__":). Also verified on merged PR+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, and scripts/check_no_game_data.py on all 8 touched files (clean).

**@⁠zmasi** on GitHub · 2026-11-28 03:02 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2531#issuecomment-7232754422) #2531 | head 635bab171f309c23525c834f578de41ab46f8e77 (merged cleanly with main 02f71ccfe) | `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: yes Diff reviewed line-by-line across all 8 files (each adds only `sys.stdout.reconfigure(errors="replace")` in `if __name__ == "__main__":`). Also verified on merged `PR+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`, and `scripts/check_no_game_data.py` on all 8 touched files (clean).
Author
Owner

@⁠GrahamboJangles on GitHub · 2026-11-28 08:07 UTC · original

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 everything main() prints. All eight already call sys.exit(main())/sys.argv in that same block, so sys is imported: no new import needed. None of the eight reassigns sys.stdout or wraps it (no colorama-style re-wrapping anywhere in them), so the errors="replace" setting survives to the actual writes — grep for sys.stdout = / colorama in all eight: zero hits.

Delta, tested both sides. tests/test_tool_stdout_encoding.py is 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 show blobs, 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 -v runs 4 tests, all OK in 3.6s, including the two measured-crash tools (analyze_4240_full.py, meshlet_page.py) and scripts/audit_shader4_regs.py + viewer/serve.py cases — 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.listdir of tools/, 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.py
  • tools/hw_oracle/runner.py

Both are invoked in CI (.github/workflows/runtime.yml runs 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.py in NOT_YET_GUARDED matches 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.

**@⁠GrahamboJangles** on GitHub · 2026-11-28 08:07 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2531#issuecomment-7236376522) 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 everything `main()` prints. All eight already call `sys.exit(main())`/`sys.argv` in that same block, so `sys` is imported: no new import needed. None of the eight reassigns `sys.stdout` or wraps it (no colorama-style re-wrapping anywhere in them), so the `errors="replace"` setting survives to the actual writes — grep for `sys.stdout =` / `colorama` in all eight: zero hits. **Delta, tested both sides.** `tests/test_tool_stdout_encoding.py` is 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 show` blobs, 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 -v` runs **4 tests, all OK** in 3.6s, including the two measured-crash tools (`analyze_4240_full.py`, `meshlet_page.py`) and `scripts/audit_shader4_regs.py` + `viewer/serve.py` cases — 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.listdir` of `tools/`, `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.py` - `tools/hw_oracle/runner.py` Both are invoked in CI (`.github/workflows/runtime.yml` runs 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.py` in `NOT_YET_GUARDED` matches 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.
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-28 11:14 UTC · original

Checked on Linux, CPU only: merged with current main 4a54aedc it merges cleanly, but tests/test_tool_stdout_encoding.py::test_every_main_block_reconfigures_stdout still fails, now listing two files this branch predates: scripts/bench_translate.py and scripts/export_old_pr_manifest.py (both came into main with the mandy/main merge after your base 431ceba4). 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

**@⁠kawaii-shakal** on GitHub · 2026-11-28 11:14 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2531#issuecomment-7238425282) Checked on Linux, CPU only: merged with current main 4a54aedc it merges cleanly, but `tests/test_tool_stdout_encoding.py::test_every_main_block_reconfigures_stdout` still fails, now listing two files this branch predates: `scripts/bench_translate.py` and `scripts/export_old_pr_manifest.py` (both came into main with the `mandy/main` merge after your base 431ceba4). 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](https://claude.ai/code)_
github manually merged commit e9bf75408a into main 2026-11-28 13:03:42 +00:00
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-28 13:03 UTC · original

Red: tests/test_tool_stdout_encoding.py fails on main 09c153948 listing the 8 programs; with the PR they leave the list. On main a997a3c it 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)

**@⁠MoonEyes** on GitHub · 2026-11-28 13:03 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2531#issuecomment-7239653363) Red: tests/test_tool_stdout_encoding.py fails on main 09c153948 listing the 8 programs; with the PR they leave the list. On main a997a3c it 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)
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!2531
No description provided.