tools: set errors="replace" on stdout in exe_sha and pr_conflict_label (TEST-STDOUT-ENCODING) #605

Manually merged
github merged 1 commit from gh-pr/605/head into gh-pr/605/base 2026-11-26 09:11:16 +00:00
Owner

@⁠Mby159 on GitHub · 2026-11-24 09:48 UTC · original
Mby159:fix/stdout-encoding-guard → main · +2 −0 · 2 files · 1 commits · merged 2026-11-24 13:10 UTC

Claimed in the coordination issue as: TEST-STDOUT-ENCODING

What and why

tests/test_tool_stdout_encoding.py is red on main. That file is the repository's own guard for #1406: every CLI tool under tools/, scripts/ and viewer/ must set errors="replace" on stdout, so a redirected stdout - encoded with the console's ANSI code page - cannot die with UnicodeEncodeError when it prints a path whose characters that code page cannot represent.

EveryToolGuardsStdout.test_every_main_block_reconfigures_stdout scans those three folders and requires sys.stdout.reconfigure(errors="replace") within 400 characters of the if __name__ == "__main__": line. Two tools were added after that test existed and never got the guard:

  • tools/exe_sha.py - added in 49c81019c
  • tools/pr_conflict_label.py - added in 4f7a34777

so on main the test fails with:

AssertionError: Lists differ: ['tools/exe_sha.py', 'tools/pr_conflict_label.py'] != []

The check is a source scan, so it fails on every platform: the Windows check job, the Linux stdlib-tests-linux job and the macOS macos-python job all run it. The upstream Windows check job on #475 logged ##[error]tests/test_tool_stdout_encoding.py failed, and that pull request's macOS job failed with the same assertion.

This pull request adds the missing guard to the two __main__ blocks. Two lines; on a UTF-8 console nothing changes.

Depends on: none

What I tested

  • python -I tests/test_tool_stdout_encoding.py on main d7576d56ae2c77564c84ffae724ffe9bdd2e6701: Ran 4 tests ... FAILED (failures=1) with the assertion above. With this change: Ran 4 tests ... OK.
  • python -m compileall -q make_game.py tools tests: exit 0.
  • python -I tests/test_exe_sha.py: 11 tests, OK. python -I tests/test_pr_conflict_label.py: 12 tests, OK.
  • The mechanism, measured here: with a redirected stdout that is not UTF-8, print of a character outside the code page raises UnicodeEncodeError (charmap codec can't encode characters) on a strict stdout, and prints ??? with errors="replace". This machine's redirected stdout is gbk (ACP 936).

Hardware: Windows 11 x64 (10.0.29712), Python 3.13. No game files, no GPU, no network.

AI-assisted: yes.

**@⁠Mby159** on GitHub · 2026-11-24 09:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/605) `Mby159:fix/stdout-encoding-guard` → `main` · +2 −0 · 2 files · 1 commits · merged 2026-11-24 13:10 UTC Claimed in the coordination issue as: TEST-STDOUT-ENCODING ### What and why `tests/test_tool_stdout_encoding.py` is red on `main`. That file is the repository's own guard for #1406: every CLI tool under `tools/`, `scripts/` and `viewer/` must set `errors="replace"` on stdout, so a redirected stdout - encoded with the console's ANSI code page - cannot die with `UnicodeEncodeError` when it prints a path whose characters that code page cannot represent. `EveryToolGuardsStdout.test_every_main_block_reconfigures_stdout` scans those three folders and requires `sys.stdout.reconfigure(errors="replace")` within 400 characters of the `if __name__ == "__main__":` line. Two tools were added after that test existed and never got the guard: - `tools/exe_sha.py` - added in `49c81019c` - `tools/pr_conflict_label.py` - added in `4f7a34777` so on `main` the test fails with: ``` AssertionError: Lists differ: ['tools/exe_sha.py', 'tools/pr_conflict_label.py'] != [] ``` The check is a source scan, so it fails on every platform: the Windows `check` job, the Linux `stdlib-tests-linux` job and the macOS `macos-python` job all run it. The upstream Windows `check` job on #475 logged `##[error]tests/test_tool_stdout_encoding.py failed`, and that pull request's macOS job failed with the same assertion. This pull request adds the missing guard to the two `__main__` blocks. Two lines; on a UTF-8 console nothing changes. Depends on: none ### What I tested - `python -I tests/test_tool_stdout_encoding.py` on `main` `d7576d56ae2c77564c84ffae724ffe9bdd2e6701`: `Ran 4 tests ... FAILED (failures=1)` with the assertion above. With this change: `Ran 4 tests ... OK`. - `python -m compileall -q make_game.py tools tests`: exit 0. - `python -I tests/test_exe_sha.py`: 11 tests, OK. `python -I tests/test_pr_conflict_label.py`: 12 tests, OK. - The mechanism, measured here: with a redirected stdout that is not UTF-8, `print` of a character outside the code page raises `UnicodeEncodeError` (`charmap codec can't encode characters`) on a strict stdout, and prints `???` with `errors="replace"`. This machine's redirected stdout is `gbk` (ACP 936). Hardware: Windows 11 x64 (10.0.29712), Python 3.13. No game files, no GPU, no network. AI-assisted: yes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:11:14 +00:00
github manually merged commit ce9bf43c5b into gh-pr/605/base 2026-11-26 09:11:16 +00:00
Author
Owner

@⁠madvillain91 on GitHub · 2026-11-24 10:33 UTC · original · reviewed

Tested locally on Windows 11 — all 27 tests across \ est_tool_stdout_encoding.py, \ est_exe_sha.py, and \ est_pr_conflict_label.py\ pass (2.821s). Clean 2-line fix. LGTM.

**@⁠madvillain91** on GitHub · 2026-11-24 10:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/605#pullrequestreview-6037624904) · **reviewed** Tested locally on Windows 11 — all 27 tests across \ est_tool_stdout_encoding.py\, \ est_exe_sha.py\, and \ est_pr_conflict_label.py\ pass (2.821s). Clean 2-line fix. LGTM.
Author
Owner

@⁠trigger337 on GitHub · 2026-11-24 11:30 UTC · original

Verification on Linux (CachyOS x86_64, Python 3.14.4):

  • python3 -I tests/test_tool_stdout_encoding.py: 4/4 passed (resolves the failure on main 21625bca8).
  • python3 -I tests/test_exe_sha.py: 11/11 passed.
  • python3 -I tests/test_pr_conflict_label.py: 12/12 passed.
  • Clean-room check: python3 -I scripts/check_no_game_data.py passed on all changed files.

LGTM!

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 11:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/605#issuecomment-7130184197) Verification on Linux (CachyOS x86_64, Python 3.14.4): * `python3 -I tests/test_tool_stdout_encoding.py`: 4/4 passed (resolves the failure on `main` `21625bca8`). * `python3 -I tests/test_exe_sha.py`: 11/11 passed. * `python3 -I tests/test_pr_conflict_label.py`: 12/12 passed. * Clean-room check: `python3 -I scripts/check_no_game_data.py` passed on all changed files. LGTM! agent: yes AI-assisted: yes
Author
Owner

@⁠Mby159 on GitHub · 2026-11-24 13:26 UTC · original

@⁠ubiquitarianism thank you - merged.

This was the two-line guard the repository's own test asked for, and it clears a red that was on main itself. tests/test_tool_stdout_encoding.py fails there with Lists differ: ['tools/exe_sha.py', 'tools/pr_conflict_label.py'] != []: the check is a source scan of tools/, scripts/ and viewer/, so the Windows check job, the Linux stdlib-tests-linux job and the macOS macos-python job all reported it, and every pull request that inherited that base inherited the failure too. The two tools are the ones added after the test existed (tools/exe_sha.py in 49c81019c, tools/pr_conflict_label.py in 4f7a34777); the guard is the one every other tool under those three folders already has, so on a UTF-8 console nothing changes.

The checks behind it, on Linux (@⁠trigger337) and on Windows (CPython 3.14): tests/test_tool_stdout_encoding.py 4/4, tests/test_exe_sha.py 11/11, tests/test_pr_conflict_label.py 12/12, python -m compileall -q make_game.py tools tests exit 0, and python -I scripts/check_no_game_data.py clean on both changed files. The measured mechanism: with a redirected stdout that is not UTF-8, printing a character outside the code page raises UnicodeEncodeError on a strict stdout and prints ??? with errors="replace".

AI-assisted: yes.

**@⁠Mby159** on GitHub · 2026-11-24 13:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/605#issuecomment-7132835771) @⁠ubiquitarianism thank you - merged. This was the two-line guard the repository's own test asked for, and it clears a red that was on `main` itself. `tests/test_tool_stdout_encoding.py` fails there with `Lists differ: ['tools/exe_sha.py', 'tools/pr_conflict_label.py'] != []`: the check is a source scan of `tools/`, `scripts/` and `viewer/`, so the Windows `check` job, the Linux `stdlib-tests-linux` job and the macOS `macos-python` job all reported it, and every pull request that inherited that base inherited the failure too. The two tools are the ones added after the test existed (`tools/exe_sha.py` in `49c81019c`, `tools/pr_conflict_label.py` in `4f7a34777`); the guard is the one every other tool under those three folders already has, so on a UTF-8 console nothing changes. The checks behind it, on Linux (@⁠trigger337) and on Windows (CPython 3.14): `tests/test_tool_stdout_encoding.py` 4/4, `tests/test_exe_sha.py` 11/11, `tests/test_pr_conflict_label.py` 12/12, `python -m compileall -q make_game.py tools tests` exit 0, and `python -I scripts/check_no_game_data.py` clean on both changed files. The measured mechanism: with a redirected stdout that is not UTF-8, printing a character outside the code page raises `UnicodeEncodeError` on a strict stdout and prints `???` with `errors="replace"`. AI-assisted: yes.
This discussion has been locked. Commenting is limited to contributors.
No description provided.