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

Merged
cweohme merged 1 commit from upstream-pr/2531 into main 2026-11-28 13:03:09 +00:00
cweohme commented 2026-11-28 00:50:48 +00:00 (Migrated from github.com)

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.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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5535095399 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2531). Originally posted by [cweohme](https://github.com/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.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)
zmasi commented 2026-11-28 03:02:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T03:02:26Z.


#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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232754422 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2531#issuecomment-7232754422). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T03:02:26Z. --- #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).
GrahamboJangles commented 2026-11-28 08:07:18 +00:00 (Migrated from github.com)

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 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7236376522 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2531#issuecomment-7236376522). Originally posted by [GrahamboJangles](https://github.com/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 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.
kawaii-shakal commented 2026-11-28 11:14:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-28T11:14:57Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238425282 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2531#issuecomment-7238425282). Originally posted by [kawaii-shakal](https://github.com/kawaii-shakal) on 2026-11-28T11:14:57Z. --- 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)_
MoonEyes commented 2026-11-28 13:03:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T13:03:05Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239653363 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2531#issuecomment-7239653363). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T13:03:05Z. --- 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)
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
ProjectLeonida/mandy!2531
No description provided.