[PR #1789] tools: harden stage_timeline.py parsing, OSError handling and stdout guard #1801

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

📋 Pull Request Information

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

Base: main ← Head: fix/stage-timeline-safety


📝 Commits (1)

  • dacbc16 tools: harden stage_timeline.py parsing, error handling and stdout guard

📊 Changes

2 files changed (+150 additions, -8 deletions)

View changed files

➕ tests/test_stage_timeline.py (+128 -0)
📝 tools/stage_timeline.py (+22 -8)

📄 Description

Claimed in the coordination issue as: STAGE-TIMELINE-STDOUT-GUARD-AND-PARSER-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162011238)

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)

🔄 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/1789 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/stage-timeline-safety` --- ### 📝 Commits (1) - [`dacbc16`](https://github.com/ubiquitarianism/leonida/commit/dacbc16566dd0ff165d9a60f5c70581982872b5f) tools: harden stage_timeline.py parsing, error handling and stdout guard ### 📊 Changes **2 files changed** (+150 additions, -8 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_stage_timeline.py` (+128 -0) 📝 `tools/stage_timeline.py` (+22 -8) </details> ### 📄 Description Claimed in the coordination issue as: STAGE-TIMELINE-STDOUT-GUARD-AND-PARSER-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162011238) ### 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) --- <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#1801
No description provided.