tools/game_run_summary: guard stdout encoding, BOM ints, OSError and RecursionError #1837

Open
github-bot wants to merge 1 commit from github-bot/gh-1837 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-25 12:57 UTC · original
kirigayakazima:fix/game-run-summary-safety → main · +69 −5 · 2 files · 1 commits · open

Claimed in the coordination issue as: GAME-RUN-SUMMARY-STDOUT-BOM-AND-VALIDATION (#1608)

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)
**@⁠kirigayakazima** on GitHub · 2026-11-25 12:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1837) `kirigayakazima:fix/game-run-summary-safety` → `main` · +69 −5 · 2 files · 1 commits · open Claimed in the coordination issue as: GAME-RUN-SUMMARY-STDOUT-BOM-AND-VALIDATION (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:07:46 +00:00
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:50 UTC · original

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

python -m pytest -q tests/test_game_run_summary.py:

  • PR: 12 passed. main: 8 passed. The new tests pass on Windows.
  • Also: with this PR, tools/game_run_summary.py should no longer appear in tests/test_tool_stdout_encoding.py's list (it is one of the two tools still listed after #1673).

(AI-assisted test run; output checked by hand.)

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1837#issuecomment-7167357574) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_game_run_summary.py`: - PR: 12 passed. main: 8 passed. The new tests pass on Windows. - Also: with this PR, `tools/game_run_summary.py` should no longer appear in `tests/test_tool_stdout_encoding.py`'s list (it is one of the two tools still listed after #1673). (AI-assisted test run; output checked by hand.)
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1837/head:github-bot/gh-1837'
git switch 'github-bot/gh-1837'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1837'
git switch 'github-bot/gh-1837'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1837'
git switch 'github-bot/gh-1837'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1837'
git switch 'main'
git merge --squash 'github-bot/gh-1837'
git switch 'main'
git merge --ff-only 'github-bot/gh-1837'
git switch 'main'
git merge 'github-bot/gh-1837'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.