[PR #1837] tools/game_run_summary: guard stdout encoding, BOM ints, OSError and RecursionError #1849

Open
opened 2026-11-26 21:19:10 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1837
Author: @kirigayakazima
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/game-run-summary-safety


📝 Commits (1)

  • e76cabc tools/game_run_summary: guard stdout encoding, BOM ints, OSError and RecursionError

📊 Changes

2 files changed (+69 additions, -5 deletions)

View changed files

📝 tests/test_game_run_summary.py (+56 -1)
📝 tools/game_run_summary.py (+13 -4)

📄 Description

Claimed in the coordination issue as: GAME-RUN-SUMMARY-STDOUT-BOM-AND-VALIDATION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163012307)

What and why

  • Add the standard sys.stdout.reconfigure(errors="replace") guard in tools/game_run_summary.py's __main__ block so redirected Windows python -I runs do not raise UnicodeEncodeError when reporting method names outside the ANSI/OEM code page.
  • Decode exit_code and seconds in _read_int() with encoding="utf-8-sig" so UTF-8 BOM-prefixed files parse cleanly instead of reading as None.
  • Guard the second open() in _lines() against OSError and catch (ValueError, RecursionError) on boot.jsonl json.loads() lines so deeply nested corrupt entries increment startup_bad_lines cleanly.
  • Reject non-positive --limit-seconds values (< 1) in main() via parser.error(...) (exit 2).
  • Add regression tests in tests/test_game_run_summary.py.

Tested

  • python -I tests/test_game_run_summary.py -v -> Ran 12 tests in 0.156s, OK.
  • Detached upstream/main (98c2f777) baseline worktree with updated tests/test_game_run_summary.py -> Ran 12 tests in 0.176s, FAILED (failures=4, errors=2) (all new regression checks fail before the fix).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 5.198s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 12.859s, OK.
  • python -I scripts/check_no_game_data.py tools/game_run_summary.py tests/test_game_run_summary.py -> exit 0.
  • python -I -m compileall -q tools/game_run_summary.py tests/test_game_run_summary.py and git diff --check -> exit 0.

GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)

AI-assisted: yes

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)

🔄 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/1837 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/game-run-summary-safety` --- ### 📝 Commits (1) - [`e76cabc`](https://github.com/ubiquitarianism/leonida/commit/e76cabc17a7400d6ab73da0e2689554b182df52a) tools/game_run_summary: guard stdout encoding, BOM ints, OSError and RecursionError ### 📊 Changes **2 files changed** (+69 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_game_run_summary.py` (+56 -1) 📝 `tools/game_run_summary.py` (+13 -4) </details> ### 📄 Description Claimed in the coordination issue as: GAME-RUN-SUMMARY-STDOUT-BOM-AND-VALIDATION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163012307) ### What and why - Add the standard `sys.stdout.reconfigure(errors="replace")` guard in `tools/game_run_summary.py`'s `__main__` block so redirected Windows `python -I` runs do not raise `UnicodeEncodeError` when reporting method names outside the ANSI/OEM code page. - Decode `exit_code` and `seconds` in `_read_int()` with `encoding="utf-8-sig"` so UTF-8 BOM-prefixed files parse cleanly instead of reading as `None`. - Guard the second `open()` in `_lines()` against `OSError` and catch `(ValueError, RecursionError)` on `boot.jsonl` `json.loads()` lines so deeply nested corrupt entries increment `startup_bad_lines` cleanly. - Reject non-positive `--limit-seconds` values (`< 1`) in `main()` via `parser.error(...)` (exit `2`). - Add regression tests in `tests/test_game_run_summary.py`. ### Tested - `python -I tests/test_game_run_summary.py -v` -> `Ran 12 tests in 0.156s`, `OK`. - Detached `upstream/main` (`98c2f777`) baseline worktree with updated `tests/test_game_run_summary.py` -> `Ran 12 tests in 0.176s`, `FAILED (failures=4, errors=2)` (all new regression checks fail before the fix). - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 5.198s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 12.859s`, `OK`. - `python -I scripts/check_no_game_data.py tools/game_run_summary.py tests/test_game_run_summary.py` -> exit `0`. - `python -I -m compileall -q tools/game_run_summary.py tests/test_game_run_summary.py` and `git diff --check` -> exit `0`. GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64) AI-assisted: yes ### 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#1849
No description provided.