tools: harden stage_timeline.py parsing, OSError handling and stdout guard #1789

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

@⁠kirigayakazima on GitHub · 2026-11-25 12:11 UTC · original
kirigayakazima:fix/stage-timeline-safety → main · +150 −8 · 2 files · 1 commits · open

Claimed in the coordination issue as: STAGE-TIMELINE-STDOUT-GUARD-AND-PARSER-SAFETY (#1608)

What and why

  • Add the standard sys.stdout.reconfigure(errors="replace") guard in tools/stage_timeline.py's __main__ block so redirected Windows python -I runs do not fail tests/test_tool_stdout_encoding.py (tools/stage_timeline.py is removed from missing).
  • Tighten PRESS timestamp regex ([0-9]+(?:\.[0-9]+)?) and make first_value() return None safely for empty strings, leading commas (e.g. ,1234), partial ? hex tokens, or non-hex values instead of raising ValueError.
  • Read logs with encoding="utf-8-sig", errors="replace" and catch OSError in main() to print a concise error line to stderr and return exit code 2 instead of a traceback.
  • Require p["game"] == 3 before reporting "story load (loading screen ended)" in timeline().
  • Add synthetic standard-library unit tests in tests/test_stage_timeline.py.

Tested

  • python -I tests/test_stage_timeline.py -v -> Ran 7 tests in 0.146s, OK (verified in a detached upstream/main worktree that the new test file fails before the fix: FAILED (failures=4, errors=2)).
  • python -I tests/test_tool_stdout_encoding.py -> tools/stage_timeline.py is no longer in missing (only pre-existing ['tools/compute_heap_layout_census.py'] fails).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 4.545s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 12.772s, OK.
  • python -I scripts/check_no_game_data.py tools/stage_timeline.py tests/test_stage_timeline.py -> exit 0.
  • python -I -m compileall -q tools/stage_timeline.py tests/test_stage_timeline.py and git diff --check -> clean.

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:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1789) `kirigayakazima:fix/stage-timeline-safety` → `main` · +150 −8 · 2 files · 1 commits · open Claimed in the coordination issue as: STAGE-TIMELINE-STDOUT-GUARD-AND-PARSER-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Add the standard `sys.stdout.reconfigure(errors="replace")` guard in `tools/stage_timeline.py`'s `__main__` block so redirected Windows `python -I` runs do not fail `tests/test_tool_stdout_encoding.py` (`tools/stage_timeline.py` is removed from `missing`). - Tighten `PRESS` timestamp regex (`[0-9]+(?:\.[0-9]+)?`) and make `first_value()` return `None` safely for empty strings, leading commas (e.g. `,1234`), partial `?` hex tokens, or non-hex values instead of raising `ValueError`. - Read logs with `encoding="utf-8-sig", errors="replace"` and catch `OSError` in `main()` to print a concise error line to stderr and return exit code `2` instead of a traceback. - Require `p["game"] == 3` before reporting `"story load (loading screen ended)"` in `timeline()`. - Add synthetic standard-library unit tests in `tests/test_stage_timeline.py`. ### Tested - `python -I tests/test_stage_timeline.py -v` -> `Ran 7 tests in 0.146s`, `OK` (verified in a detached `upstream/main` worktree that the new test file fails before the fix: `FAILED (failures=4, errors=2)`). - `python -I tests/test_tool_stdout_encoding.py` -> `tools/stage_timeline.py` is no longer in `missing` (only pre-existing `['tools/compute_heap_layout_census.py']` fails). - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 4.545s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 12.772s`, `OK`. - `python -I scripts/check_no_game_data.py tools/stage_timeline.py tests/test_stage_timeline.py` -> exit `0`. - `python -I -m compileall -q tools/stage_timeline.py tests/test_stage_timeline.py` and `git diff --check` -> clean. 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:05:22 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 19:16 UTC · original

Reviewed dacbc165: python -I tests/test_stage_timeline.py passes on the PR tree (7/7); on main 6/7 fail (first_value crash on empty/mid-? hex, float('.') press stamps, traceback on an unreadable log), so the tests pin the fix. A probe on both trees reproduced the main-side crashes the PR removes and found no input the PR handles worse; the tightened PRESS regex only stops accepting a trailing-dot timestamp the emitter (%.1f) never writes. The game==3 "ended" gate matches the documented state table but needs a real boot log to confirm.

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 19:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1789#issuecomment-7172077741) Reviewed dacbc165: `python -I tests/test_stage_timeline.py` passes on the PR tree (7/7); on main 6/7 fail (first_value crash on empty/mid-? hex, float('.') press stamps, traceback on an unreadable log), so the tests pin the fix. A probe on both trees reproduced the main-side crashes the PR removes and found no input the PR handles worse; the tightened PRESS regex only stops accepting a trailing-dot timestamp the emitter (%.1f) never writes. The game==3 "ended" gate matches the documented state table but needs a real boot log to confirm. AI-assisted review. **Recommendation:** Merge
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/1789/head:github-bot/gh-1789'
git switch 'github-bot/gh-1789'

Merge

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