pr_conflict_label: guard stdout against the console code page (TEST-WIN-SWEEP) #367

Closed
leonida/mandy
ItsMrDubey wants to merge 0 commits from win-stdout-pr-conflict-label into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

ItsMrDubey commented 2026-11-24 03:56:54 +00:00

Claimed in the coordination issue as: TEST-WIN-SWEEP (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121328982)

What and why

python -I tests/test_tool_stdout_encoding.py fails on main: test_every_main_block_reconfigures_stdout lists tools/pr_conflict_label.py, added in 4f7a347 (PR-CONFLICT-LABEL) without the sys.stdout.reconfigure(errors="replace") guard every other program's __main__ block has. Under -I a redirected stdout on Windows is strict cp1252, so a character outside the code page would end the run with UnicodeEncodeError. The check itself is not Windows-specific, so the test fails on every OS; the sweep found it on Windows.

The __main__ block now sets the same guard, in the same words, as scripts/ci_expected_failures.py and the tools.

Tested

Windows 11, Python 3.11.9 and 3.12.9:

  • python -I tests/test_tool_stdout_encoding.py: before FAIL ... ['tools/pr_conflict_label.py'] != [] (exit 1); after OK.
  • python -I tests/test_pr_conflict_label.py: OK.
  • python -I scripts/check_no_game_data.py tools/pr_conflict_label.py: clean.
  • Linux (the conflict-label workflow runs python3 -I tools/pr_conflict_label.py): reconfigure is a no-op there for a UTF-8 stdout and the guard swallows the errors it could raise.

AI-assisted: yes

Checklist

  • 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
Claimed in the coordination issue as: TEST-WIN-SWEEP (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121328982) ### What and why `python -I tests/test_tool_stdout_encoding.py` fails on main: `test_every_main_block_reconfigures_stdout` lists `tools/pr_conflict_label.py`, added in 4f7a347 (PR-CONFLICT-LABEL) without the `sys.stdout.reconfigure(errors="replace")` guard every other program's `__main__` block has. Under `-I` a redirected stdout on Windows is strict cp1252, so a character outside the code page would end the run with `UnicodeEncodeError`. The check itself is not Windows-specific, so the test fails on every OS; the sweep found it on Windows. The `__main__` block now sets the same guard, in the same words, as `scripts/ci_expected_failures.py` and the tools. ### Tested Windows 11, Python 3.11.9 and 3.12.9: - `python -I tests/test_tool_stdout_encoding.py`: before `FAIL ... ['tools/pr_conflict_label.py'] != []` (exit 1); after OK. - `python -I tests/test_pr_conflict_label.py`: OK. - `python -I scripts/check_no_game_data.py tools/pr_conflict_label.py`: clean. - Linux (the conflict-label workflow runs `python3 -I tools/pr_conflict_label.py`): `reconfigure` is a no-op there for a UTF-8 stdout and the guard swallows the errors it could raise. AI-assisted: yes ### Checklist - [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
quartz-heron-58 commented 2026-11-24 08:28:20 +00:00

Tested 9683501d (cherry-picked onto main 1c93c869) on native Windows 11 Home (build 26300), Python 3.12.10: pass.

On main 1c93c869, python -I tests/test_tool_stdout_encoding.py fails test_every_main_block_reconfigures_stdout here, naming tools/pr_conflict_label.py as the one program without the guard. With this commit the file ends in OK. python -m compileall -q make_game.py tools tests: exit 0. No game files.

Not run: pr_conflict_label.py itself against a console code page.

AI-assisted (Claude Code ran the tests and wrote this comment).

Tested 9683501d (cherry-picked onto main 1c93c869) on native Windows 11 Home (build 26300), Python 3.12.10: pass. On main 1c93c869, `python -I tests/test_tool_stdout_encoding.py` fails `test_every_main_block_reconfigures_stdout` here, naming `tools/pr_conflict_label.py` as the one program without the guard. With this commit the file ends in OK. `python -m compileall -q make_game.py tools tests`: exit 0. No game files. Not run: `pr_conflict_label.py` itself against a console code page. AI-assisted (Claude Code ran the tests and wrote this comment).
Headache3318 commented 2026-11-24 09:52:51 +00:00

Tested here, not only read. At 7430f59b2 python3 -I tests/test_tool_stdout_encoding.py is still red and names exactly one program, tools/pr_conflict_label.py, merged without the guard in 4f7a34777 - the same class as d083a2cc3's note "the 15 programs merged without the stdout guard got the same block as the others", so the resolution is the block, never the test's expectation.
Your 4-line guard turns it green at your head 9683501d0 (Ran 4 tests ... OK) and is behaviour-neutral: tests/test_pr_conflict_label.py gives 12 OK with and without it. Everything else I ran at your head and on the rebased copy is OK: test_text_write_line_endings (3), test_bad_input_errors (11), test_docs_encoding, test_text_encoding; python3 -m compileall -q make_game.py tools tests scripts viewer exit 0; git diff --check clean; python3 -I scripts/check_no_game_data.py tools/pr_conflict_label.py exit 0.
Your base is about 30 commits behind, so here is the identical guard applied cleanly to d42773d07 / 7430f59b2 - 483 bytes, 1 file changed, 4 insertions - for whoever rebases:

--- a/tools/pr_conflict_label.py
+++ b/tools/pr_conflict_label.py
@@ if __name__ == "__main__":
+    try:  # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode
+        sys.stdout.reconfigure(errors="replace")
+    except (AttributeError, ValueError, OSError):
+        pass
     sys.exit(main())

AI-assisted (Hermes agent on behalf of @Headache3318); Arch Linux, 8-core x86-64, python 3.14.9, no game files, no GPU run. The Windows code-page failure itself is not measured on this box - the -X utf8=0 runs reproduce the convention the test enforces, not the console behaviour.

Tested here, not only read. At `7430f59b2` `python3 -I tests/test_tool_stdout_encoding.py` is still red and names exactly one program, `tools/pr_conflict_label.py`, merged without the guard in `4f7a34777` - the same class as `d083a2cc3`'s note "the 15 programs merged without the stdout guard got the same block as the others", so the resolution is the block, never the test's expectation. Your 4-line guard turns it green at your head `9683501d0` (`Ran 4 tests ... OK`) and is behaviour-neutral: `tests/test_pr_conflict_label.py` gives 12 OK with and without it. Everything else I ran at your head and on the rebased copy is OK: `test_text_write_line_endings` (3), `test_bad_input_errors` (11), `test_docs_encoding`, `test_text_encoding`; `python3 -m compileall -q make_game.py tools tests scripts viewer` exit 0; `git diff --check` clean; `python3 -I scripts/check_no_game_data.py tools/pr_conflict_label.py` exit 0. Your base is about 30 commits behind, so here is the identical guard applied cleanly to `d42773d07` / `7430f59b2` - 483 bytes, 1 file changed, 4 insertions - for whoever rebases: ```diff --- a/tools/pr_conflict_label.py +++ b/tools/pr_conflict_label.py @@ if __name__ == "__main__": + try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode + sys.stdout.reconfigure(errors="replace") + except (AttributeError, ValueError, OSError): + pass sys.exit(main()) ``` **AI-assisted** (Hermes agent on behalf of @Headache3318); Arch Linux, 8-core x86-64, python 3.14.9, no game files, no GPU run. The Windows code-page failure itself is not measured on this box - the `-X utf8=0` runs reproduce the convention the test enforces, not the console behaviour.
MoonEyes commented 2026-11-27 23:36:39 +00:00

Thanks for the Windows sweep, @ItsMrDubey. The test this pull request targets, test_every_main_block_reconfigures_stdout, no longer lists tools/pr_conflict_label.py on main: it got sys.stdout.reconfigure(errors="replace") in its __main__ block in ce9bf43c5. What is left here is wrapping that call in the try/except the other tools use, which no test needs, so I am closing this one.

If you have a case where the unguarded call fails for this script, please reopen it with that case.

AI-assisted (Claude Code, Claude Opus 5.5)

Thanks for the Windows sweep, @ItsMrDubey. The test this pull request targets, `test_every_main_block_reconfigures_stdout`, no longer lists `tools/pr_conflict_label.py` on `main`: it got `sys.stdout.reconfigure(errors="replace")` in its `__main__` block in ce9bf43c5. What is left here is wrapping that call in the `try/except` the other tools use, which no test needs, so I am closing this one. If you have a case where the unguarded call fails for this script, please reopen it with that case. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.