tools/scripts: the four leftover __main__ blocks set errors=replace on stdout #2590

Merged
aegish-zagi merged 1 commit from upstream-pr/2590 into main 2026-11-29 03:37:18 +00:00
aegish-zagi commented 2026-11-28 20:12:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aegish-zagi on 2026-11-28T20:12:19Z.


Claimed in the coordination issue as: TOOL-STDOUT-GUARD-LEFTOVER-FOUR (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7244547568)

Depends on: none

What and why

PR #2531 set errors="replace" on stdout in the __main__ blocks of the eight programs it covered, but four programs still have no guard, and tests/test_tool_stdout_encoding.py fails on current main naming exactly them:

  • scripts/bench_translate.py
  • scripts/export_old_pr_manifest.py
  • tools/pc_prompt_glyphs.py
  • tools/xbox_prompt_glyphs.py

On Windows a redirected stdout is encoded with the console's ANSI code page and python -I ignores PYTHONUTF8 and PYTHONIOENCODING, so a path with a character outside that code page reaches print() as UnicodeEncodeError and ends the run (the failure #1406 fixed in make_game.py).

This adds the same single line as the first line of each of the four __main__ blocks, matching PR #2531's idiom (see the sibling tools/ps_prompt_glyphs.py, guarded there):

sys.stdout.reconfigure(errors="replace")

Nothing else changes; all four files already import sys.

Credit: the original stdout-guard finding was @Tauwni's; this PR completes the four programs left over from that finding.

Tested

Linux, Python 3.12.3. Before this change, tests/test_tool_stdout_encoding.py failed: its static check listed exactly the four files above as missing the guard. After:

  • python3 -I tests/test_tool_stdout_encoding.py — 4 tests, OK
  • python3 -I tests/test_bench_translate.py — 10 tests, OK
  • python3 -I tests/test_export_old_pr_manifest.py — 5 tests, OK
  • python3 -I tests/test_pc_prompt_glyphs.py — 13 tests, OK
  • python3 -I tests/test_xbox_prompt_glyphs.py — 18 tests, OK
  • python3 -I scripts/check_no_game_data.py on the four changed files — clean

GPUs tested: n/a — no GPU involved; CPU-only standard-library unit tests (Profile Z: no free GPU).

AI-assisted: yes — the change was written by a coding agent (Muse) working for the account owner, who reviewed the scope and approved opening this pull request.

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 in this change.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5544151896 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2590). Originally posted by [aegish-zagi](https://github.com/aegish-zagi) on 2026-11-28T20:12:19Z. --- Claimed in the coordination issue as: TOOL-STDOUT-GUARD-LEFTOVER-FOUR (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7244547568) Depends on: none ### What and why PR #2531 set `errors="replace"` on stdout in the `__main__` blocks of the eight programs it covered, but four programs still have no guard, and `tests/test_tool_stdout_encoding.py` fails on current `main` naming exactly them: - `scripts/bench_translate.py` - `scripts/export_old_pr_manifest.py` - `tools/pc_prompt_glyphs.py` - `tools/xbox_prompt_glyphs.py` On Windows a redirected stdout is encoded with the console's ANSI code page and `python -I` ignores PYTHONUTF8 and PYTHONIOENCODING, so a path with a character outside that code page reaches `print()` as UnicodeEncodeError and ends the run (the failure #1406 fixed in make_game.py). This adds the same single line as the first line of each of the four `__main__` blocks, matching PR #2531's idiom (see the sibling `tools/ps_prompt_glyphs.py`, guarded there): sys.stdout.reconfigure(errors="replace") Nothing else changes; all four files already import `sys`. Credit: the original stdout-guard finding was @Tauwni's; this PR completes the four programs left over from that finding. ### Tested Linux, Python 3.12.3. Before this change, `tests/test_tool_stdout_encoding.py` failed: its static check listed exactly the four files above as missing the guard. After: - `python3 -I tests/test_tool_stdout_encoding.py` — 4 tests, OK - `python3 -I tests/test_bench_translate.py` — 10 tests, OK - `python3 -I tests/test_export_old_pr_manifest.py` — 5 tests, OK - `python3 -I tests/test_pc_prompt_glyphs.py` — 13 tests, OK - `python3 -I tests/test_xbox_prompt_glyphs.py` — 18 tests, OK - `python3 -I scripts/check_no_game_data.py` on the four changed files — clean GPUs tested: n/a — no GPU involved; CPU-only standard-library unit tests (Profile Z: no free GPU). AI-assisted: yes — the change was written by a coding agent (Muse) working for the account owner, who reviewed the scope and approved opening this pull request. ### 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. — n/a: no translator rule in this change.
zmasi commented 2026-11-28 20:31:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T20:31:09Z.


#2590 | head fa3847b075 (merged cleanly with main 1bc055e6c2) | python -I tests/test_tool_stdout_encoding.py | red on main: FAILED (failures=1) (EveryToolGuardsStdout.test_every_main_block_reconfigures_stdout fails on main for tools/pc_prompt_glyphs.py, tools/xbox_prompt_glyphs.py, scripts/bench_translate.py, and scripts/export_old_pr_manifest.py) | green on PR+main: 4 tests OK | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited all four __main__ blocks (scripts/bench_translate.py, scripts/export_old_pr_manifest.py, tools/pc_prompt_glyphs.py, and tools/xbox_prompt_glyphs.py) on Windows 11, confirming this PR resolves the live main CI failure in tests/test_tool_stdout_encoding.py (4/4 OK, including non-code-page path tests under Windows code pages). Also verified tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245344506 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2590#issuecomment-7245344506). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T20:31:09Z. --- #2590 | head fa3847b07524de66932b1a9075f21515300438f3 (merged cleanly with main 1bc055e6c2) | `python -I tests/test_tool_stdout_encoding.py` | red on main: `FAILED (failures=1)` (`EveryToolGuardsStdout.test_every_main_block_reconfigures_stdout` fails on `main` for `tools/pc_prompt_glyphs.py`, `tools/xbox_prompt_glyphs.py`, `scripts/bench_translate.py`, and `scripts/export_old_pr_manifest.py`) | green on PR+main: `4 tests OK` | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited all four `__main__` blocks (`scripts/bench_translate.py`, `scripts/export_old_pr_manifest.py`, `tools/pc_prompt_glyphs.py`, and `tools/xbox_prompt_glyphs.py`) on Windows 11, confirming this PR resolves the live `main` CI failure in `tests/test_tool_stdout_encoding.py` (`4/4 OK`, including non-code-page path tests under Windows code pages). Also verified `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
lixonik commented 2026-11-28 21:15:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T21:15:20Z.

Review: APPROVED


Reviewed fa3847b07 merged locally with main aa918e5d9 on Windows 10 22H2. python -I -B tests/test_tool_stdout_encoding.py identified these four entry points on bare main and passed all 4 tests with the PR.

I also exercised each real __main__ with --help in an isolated Python process, using a synthetic non-ASCII script basename and strict ASCII stdout. The four copies on main each raised UnicodeEncodeError. The patched copies all completed with exit 0 and a replacement character in the program name. No input assets were used. The changed-files no-game-data check passed.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6100116434 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2590#pullrequestreview-6100116434). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T21:15:20Z. **Review:** APPROVED --- Reviewed `fa3847b07` merged locally with `main` `aa918e5d9` on Windows 10 22H2. `python -I -B tests/test_tool_stdout_encoding.py` identified these four entry points on bare main and passed all 4 tests with the PR. I also exercised each real `__main__` with `--help` in an isolated Python process, using a synthetic non-ASCII script basename and strict ASCII stdout. The four copies on main each raised UnicodeEncodeError. The patched copies all completed with exit 0 and a replacement character in the program name. No input assets were used. The changed-files no-game-data check passed. AI-assisted.
Maticcm commented 2026-11-28 21:27:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Maticcm on 2026-11-28T21:27:33Z.


I exercised the real bench_translate.py --compare CLI at fa3847b07524de66932b1a9075f21515300438f3 and its parent 5cb45921e3963d71d3b931d9660b8c1e1a3145f1. Windows 11 build 26340, CPython 3.12.10, python -I, redirected stdout confirmed as CP1252. Both runs used the same tools directory with an unrepresentable character in its name, the same checkout fixtures, and --rounds 1 --runs 1 --size 20.

  • Parent: exit 1 at the print of the reference/candidate directories, with UnicodeEncodeError. The final summary was absent.
  • PR head: exit 0, both printed paths used ? for the unrepresentable character, and the final summary printed.
  • test_bench_translate.py passed 10/10 on both. test_tool_stdout_encoding.py changed from one expected guard failure on the parent to 4/4 on the head.

CLI completion test only. Synthetic fixtures. AI-assisted (Codex).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246033261 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2590#issuecomment-7246033261). Originally posted by [Maticcm](https://github.com/Maticcm) on 2026-11-28T21:27:33Z. --- I exercised the real `bench_translate.py --compare` CLI at `fa3847b07524de66932b1a9075f21515300438f3` and its parent `5cb45921e3963d71d3b931d9660b8c1e1a3145f1`. Windows 11 build 26340, CPython 3.12.10, `python -I`, redirected stdout confirmed as CP1252. Both runs used the same tools directory with an unrepresentable character in its name, the same checkout fixtures, and `--rounds 1 --runs 1 --size 20`. - Parent: exit 1 at the print of the reference/candidate directories, with `UnicodeEncodeError`. The final summary was absent. - PR head: exit 0, both printed paths used `?` for the unrepresentable character, and the final summary printed. - `test_bench_translate.py` passed 10/10 on both. `test_tool_stdout_encoding.py` changed from one expected guard failure on the parent to 4/4 on the head. CLI completion test only. Synthetic fixtures. AI-assisted (Codex).
Tauwni commented 2026-11-28 23:02:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-28T23:02:27Z.


macOS complement to the Windows checks above (Apple M3, CPython 3.13, python -I), MEASURED, 3 runs each:

  • main at adfb3821a: tests/test_tool_stdout_encoding.py fails 3/3 on the same four programs.
  • main + fa3847b07 (merges cleanly): passes 3/3.
  • The four programs still start (--help, exit 0), and pc_prompt_glyphs.py --selftest gives the same output before and after.

READ IN CODE: each guard is the first line of its __main__ block, the same idiom as #2531, and nothing else changes.

One thing to note for a maintainer: the three workflows on this head (CI, Runtime, No Game Data) are action_required, so they have not run yet and the PR shows no checks. They wait for approval because this is the author's first pull request here.

Thanks for picking up the two scripts from my earlier finding (I had the same lines on fix/stdout-replace-two-new-scripts); a mention would be welcome if you update the description, nothing more needed. I will drop my branch once this lands.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247156827 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2590#issuecomment-7247156827). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-28T23:02:27Z. --- macOS complement to the Windows checks above (Apple M3, CPython 3.13, `python -I`), MEASURED, 3 runs each: - `main` at `adfb3821a`: `tests/test_tool_stdout_encoding.py` fails 3/3 on the same four programs. - `main` + `fa3847b07` (merges cleanly): passes 3/3. - The four programs still start (`--help`, exit 0), and `pc_prompt_glyphs.py --selftest` gives the same output before and after. READ IN CODE: each guard is the first line of its `__main__` block, the same idiom as #2531, and nothing else changes. One thing to note for a maintainer: the three workflows on this head (CI, Runtime, No Game Data) are `action_required`, so they have not run yet and the PR shows no checks. They wait for approval because this is the author's first pull request here. Thanks for picking up the two scripts from my earlier finding (I had the same lines on [`fix/stdout-replace-two-new-scripts`](https://github.com/Tauwni/leonida/tree/fix/stdout-replace-two-new-scripts)); a mention would be welcome if you update the description, nothing more needed. I will drop my branch once this lands.
TheGeogeo commented 2026-11-29 01:12:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T01:12:35Z.


Checked fa3847b07 merged (no commit) with main 87a39df94: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • This PR adds no test, so there is no red/green to show.
  • No regression: the four tools' own tests give the same result on main and on the merge (test_bench_translate.py 10 OK, test_export_old_pr_manifest.py 5 OK, test_pc_prompt_glyphs.py 13 OK, test_xbox_prompt_glyphs.py 18 OK).

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248632899 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2590#issuecomment-7248632899). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T01:12:35Z. --- Checked `fa3847b07` merged (no commit) with `main` `87a39df94`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - This PR adds no test, so there is no red/green to show. - No regression: the four tools' own tests give the same result on `main` and on the merge (`test_bench_translate.py` 10 OK, `test_export_old_pr_manifest.py` 5 OK, `test_pc_prompt_glyphs.py` 13 OK, `test_xbox_prompt_glyphs.py` 18 OK). No blocker from my side. AI-assisted (Claude Code).
OreoFR commented 2026-11-29 03:09:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T03:09:12Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main c8bf0e7b6, PR head fa3847b07 : red 1 failure / green 4 OK

No test in the PR; it is covered by tests/test_tool_stdout_encoding.py:

  • Merge: clean (git merge-tree).
  • Red (main): 4 tests, 1 failure: test_every_main_block_reconfigures_stdout, which lists exactly this PR's 4 files.
  • Green (main + git merge --no-ff): 4/4 OK.
  • Behaviour (MEASURED): with PYTHONIOENCODING=ascii and stdout redirected, a probe running each file's real __main__ block with a stub main printing a non-ASCII path gives UnicodeEncodeError on main for all 4, and ? replacement without error on the merge for all 4.
  • Script tests, OK on main and merge, nothing skipped: test_bench_translate (10), test_export_old_pr_manifest (5), test_pc_prompt_glyphs (13), test_xbox_prompt_glyphs (18). test_tool_startup fails on both (psin_dialogue → ModuleNotFoundError: psin_data, already on main, MEASURED n=3), unrelated.
  • Diff: one sys.stdout.reconfigure(errors="replace") line at the top of each of the 4 __main__ blocks, same as the other tools. No game data.

Verdict: READY

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249873488 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2590#issuecomment-7249873488). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T03:09:12Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main c8bf0e7b6, PR head fa3847b07 : red 1 failure / green 4 OK No test in the PR; it is covered by `tests/test_tool_stdout_encoding.py`: - Merge: clean (`git merge-tree`). - **Red** (main): 4 tests, 1 failure: `test_every_main_block_reconfigures_stdout`, which lists exactly this PR's 4 files. - **Green** (main + `git merge --no-ff`): 4/4 OK. - Behaviour (MEASURED): with `PYTHONIOENCODING=ascii` and stdout redirected, a probe running each file's real `__main__` block with a stub `main` printing a non-ASCII path gives `UnicodeEncodeError` on main for all 4, and `?` replacement without error on the merge for all 4. - Script tests, OK on main and merge, nothing skipped: `test_bench_translate` (10), `test_export_old_pr_manifest` (5), `test_pc_prompt_glyphs` (13), `test_xbox_prompt_glyphs` (18). `test_tool_startup` fails on both (`psin_dialogue` → `ModuleNotFoundError: psin_data`, already on main, MEASURED n=3), unrelated. - Diff: one `sys.stdout.reconfigure(errors="replace")` line at the top of each of the 4 `__main__` blocks, same as the other tools. No game data. **Verdict: READY** AI-assisted: Claude Code
DadaCap commented 2026-11-29 03:37:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-29T03:37:14Z.


Merging, thank you @aegish-zagi! OreoFR's agent verified this head merged with current main: the test fails on main and passes with the PR (https://github.com/ProjectLeonida/mandy/pull/2590#issuecomment-7249873488), and it still merges cleanly.

AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7250158300 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2590#issuecomment-7250158300). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-29T03:37:14Z. --- Merging, thank you @aegish-zagi! OreoFR's agent verified this head merged with current main: the test fails on main and passes with the PR (https://github.com/ProjectLeonida/mandy/pull/2590#issuecomment-7249873488), and it still merges cleanly. AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.
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!2590
No description provided.