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

Closed
opened 2026-11-26 20:18:35 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/605
Author: @Mby159
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: fix/stdout-encoding-guard


📝 Commits (1)

  • ce9bf43 tools: replace stdout encoding errors in the two remaining tools

📊 Changes

2 files changed (+2 additions, -0 deletions)

View changed files

📝 tools/exe_sha.py (+1 -0)
📝 tools/pr_conflict_label.py (+1 -0)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/605 **Author:** [@Mby159](https://github.com/Mby159) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `fix/stdout-encoding-guard` --- ### 📝 Commits (1) - [`ce9bf43`](https://github.com/ubiquitarianism/leonida/commit/ce9bf43c5b0915e90eb89134a228efe33897a3ee) tools: replace stdout encoding errors in the two remaining tools ### 📊 Changes **2 files changed** (+2 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tools/exe_sha.py` (+1 -0) 📝 `tools/pr_conflict_label.py` (+1 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:35 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#647
No description provided.