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

Merged
Mby159 merged 1 commit from upstream-pr/605 into main 2026-11-24 13:10:02 +00:00
Mby159 commented 2026-11-24 09:48:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Mby159 on 2026-11-24T09:48:20Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5469811576 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/605). Originally posted by [Mby159](https://github.com/Mby159) on 2026-11-24T09:48:20Z. --- 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.
madvillain91 commented 2026-11-24 10:33:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madvillain91 on 2026-11-24T10:33:56Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6037624904 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/605#pullrequestreview-6037624904). Originally posted by [madvillain91](https://github.com/madvillain91) on 2026-11-24T10:33:56Z. **Review:** COMMENTED --- 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.
trigger337 commented 2026-11-24 11:30:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T11:30:22Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7130184197 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/605#issuecomment-7130184197). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T11:30:22Z. --- 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
Mby159 commented 2026-11-24 13:26:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Mby159 on 2026-11-24T13:26:36Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7132835771 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/605#issuecomment-7132835771). Originally posted by [Mby159](https://github.com/Mby159) on 2026-11-24T13:26:36Z. --- @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.
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!605
No description provided.