stage_timeline: a missing or unreadable log is one error line; add unit tests (TOOL-STAGE-TIMELINE-TESTS) #2232

Closed
real-rusher wants to merge 2 commits from upstream-pr/2232 into main
real-rusher commented 2026-11-26 09:00:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T09:00:08Z.


Claimed in the coordination issue as: TOOL-STAGE-TIMELINE-TESTS (#1608)

What and why

tools/stage_timeline.py had no tests, and a wrong path or a folder ended in a FileNotFoundError or IsADirectoryError traceback. It now prints stage_timeline: error: cannot read <log>: <reason> and exits 2, like awc_names and check_no_game_data.

tests/test_stage_timeline.py covers read() and timeline() on synthetic logs (stage changes, "?" and list values, the session low dword, unknown values, press pairing, the loading screen end) and the command line (text and JSON reports, no peek lines, a missing log, a folder). Standard library only, no game data.

Tested

python -I tests/test_stage_timeline.py: 13 tests pass. On main, the two error tests fail and the other 11 pass.
Also run: python -m compileall -q make_game.py tools tests, scripts/check_no_game_data.py on both files, tests/test_ci_registration.py, tests/test_text_write_line_endings.py. All pass. Linux, Python 3.13.

GPUs tested: n/a

AI-assisted: yes (Claude Code)

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, no translator change)

🤖 Assisted by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5507006542 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2232). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T09:00:08Z. --- Claimed in the coordination issue as: TOOL-STAGE-TIMELINE-TESTS (#1608) ### What and why tools/stage_timeline.py had no tests, and a wrong path or a folder ended in a FileNotFoundError or IsADirectoryError traceback. It now prints `stage_timeline: error: cannot read <log>: <reason>` and exits 2, like awc_names and check_no_game_data. tests/test_stage_timeline.py covers read() and timeline() on synthetic logs (stage changes, "?" and list values, the session low dword, unknown values, press pairing, the loading screen end) and the command line (text and JSON reports, no peek lines, a missing log, a folder). Standard library only, no game data. ### Tested python -I tests/test_stage_timeline.py: 13 tests pass. On main, the two error tests fail and the other 11 pass. Also run: python -m compileall -q make_game.py tools tests, scripts/check_no_game_data.py on both files, tests/test_ci_registration.py, tests/test_text_write_line_endings.py. All pass. Linux, Python 3.13. GPUs tested: n/a AI-assisted: yes (Claude Code) ### 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a, no translator change) 🤖 Assisted by [Claude Code](https://claude.com/claude-code)
ecox982745 commented 2026-11-26 09:16:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-26T09:16:45Z.


All 13 tests passed on Windows with Python 3.13.18 at afeee543b, including the directory and missing-file cases. I also checked the overlap with #2186 (132b131b8) and #1789 (dacbc1656) using synthetic logs. Those branches independently passed 5 and 7 tests, respectively.

There are two merge conflicts worth coordinating. #2186 changes the arguments to read() on the same line this PR wraps with try/except OSError. #1789 implements the same file-error behavior and introduces a different suite at the same path, tests/test_stage_timeline.py.

I tested a local resolution against main a73a57e13. Combining this PR's error handler with #2186's configured reader and running this PR's tests unadapted gave 2/13 passing. The fixtures call the old reader or CLI and expect the old no-peek diagnostic. The error tests also need configured addresses so they reach the file open.

All 25 tests passed together after retaining the separate parser cases from #1789 and making these fixture changes:

  • Pass the three synthetic field addresses to read() and to the CLI helper. Dummy hex values 1a, 2b, and 3c worked throughout.
  • In the empty-log case, check for LEONIDA_PEEK in the diagnostic. The configured reader no longer prints a literal LEONIDA_PEEK= command.
  • Keep both test modules under distinct names and use one file-error handler around the configured read() call. This preserves this PR's single-line diagnostic, #1789's malformed-input cases, and #2186's configurable-field behavior.

This was a local CPU integration check.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7187708454 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2232#issuecomment-7187708454). Originally posted by [ecox982745](https://github.com/ecox982745) on 2026-11-26T09:16:45Z. --- All 13 tests passed on Windows with Python 3.13.18 at `afeee543b`, including the directory and missing-file cases. I also checked the overlap with #2186 (`132b131b8`) and #1789 (`dacbc1656`) using synthetic logs. Those branches independently passed 5 and 7 tests, respectively. There are two merge conflicts worth coordinating. #2186 changes the arguments to `read()` on the same line this PR wraps with `try/except OSError`. #1789 implements the same file-error behavior and introduces a different suite at the same path, `tests/test_stage_timeline.py`. I tested a local resolution against main `a73a57e13`. Combining this PR's error handler with #2186's configured reader and running this PR's tests unadapted gave **2/13 passing**. The fixtures call the old reader or CLI and expect the old no-peek diagnostic. The error tests also need configured addresses so they reach the file open. **All 25 tests passed together** after retaining the separate parser cases from #1789 and making these fixture changes: - Pass the three synthetic field addresses to `read()` and to the CLI helper. Dummy hex values `1a`, `2b`, and `3c` worked throughout. - In the empty-log case, check for `LEONIDA_PEEK` in the diagnostic. The configured reader no longer prints a literal `LEONIDA_PEEK=` command. - Keep both test modules under distinct names and use one file-error handler around the configured `read()` call. This preserves this PR's single-line diagnostic, #1789's malformed-input cases, and #2186's configurable-field behavior. This was a local CPU integration check.
GrahamboJangles commented 2026-11-26 09:18:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by GrahamboJangles on 2026-11-26T09:18:56Z.


Review pass on Windows (this box has no cmake/clang-cl, so no C++ build was run; this PR is pure Python tooling, so that is all the verification needed here).

Head afeee543b fetched into the local clone as branch pr2232; diff against base a73a57e13 is exactly one hunk in tools/stage_timeline.py — the peeks, presses = read(a.log) line moves into a try/except OSError that prints one stderr line (stage_timeline: error: cannot read <log>: <reason>) and return 2 — plus the new tests/test_stage_timeline.py (166 lines, 13 tests). No other files touched.

What I ran on this machine (Windows 11, CPython 3.14.9, all via python -I):

  • At head: python -I tests/test_stage_timeline.py -v → Ran 13 tests, OK.
  • Same test file against the tool at base main a73a57e13 (the test file copied into a scratch tree so it locates the base tool via its own relative path): Ran 13 tests, FAILED (failures=2) — the two error-line tests (missing log, folder). Pass count moved 11 → 13, so the new tests genuinely exercise the change rather than replacing old ones.
  • python -m compileall -q make_game.py tools tests exit 0; scripts/check_no_game_data.py on both files exit 0; python -I tests/test_ci_registration.py OK (16 tests), all at head.

From reading the hunk: IsADirectoryError and PermissionError are OSError subclasses, so folders and unreadable paths take the one-line path; undecodable bytes were already absorbed by errors="replace" in read(). Exit code 2 flows from sys.exit(main()) with return 2, matching the awc_names / check_no_game_data convention as described.

The author's numbers (Linux, 3.13) reproduce identically on Windows/3.14. Nothing blocking.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7187771162 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2232#issuecomment-7187771162). Originally posted by [GrahamboJangles](https://github.com/GrahamboJangles) on 2026-11-26T09:18:56Z. --- Review pass on Windows (this box has no cmake/clang-cl, so no C++ build was run; this PR is pure Python tooling, so that is all the verification needed here). Head `afeee543b` fetched into the local clone as branch `pr2232`; diff against base `a73a57e13` is exactly one hunk in `tools/stage_timeline.py` — the `peeks, presses = read(a.log)` line moves into a `try/except OSError` that prints one stderr line (`stage_timeline: error: cannot read <log>: <reason>`) and `return 2` — plus the new `tests/test_stage_timeline.py` (166 lines, 13 tests). No other files touched. What I ran on this machine (Windows 11, CPython 3.14.9, all via `python -I`): - At head: `python -I tests/test_stage_timeline.py -v` → Ran 13 tests, OK. - Same test file against the tool at base `main` `a73a57e13` (the test file copied into a scratch tree so it locates the base tool via its own relative path): Ran 13 tests, FAILED (failures=2) — the two error-line tests (missing log, folder). Pass count moved 11 → 13, so the new tests genuinely exercise the change rather than replacing old ones. - `python -m compileall -q make_game.py tools tests` exit 0; `scripts/check_no_game_data.py` on both files exit 0; `python -I tests/test_ci_registration.py` OK (16 tests), all at head. From reading the hunk: `IsADirectoryError` and `PermissionError` are `OSError` subclasses, so folders and unreadable paths take the one-line path; undecodable bytes were already absorbed by `errors="replace"` in `read()`. Exit code 2 flows from `sys.exit(main())` with `return 2`, matching the `awc_names` / `check_no_game_data` convention as described. The author's numbers (Linux, 3.13) reproduce identically on Windows/3.14. Nothing blocking.
DeadlyChirp commented 2026-11-26 10:02:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-26T10:02:01Z.


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

  • tests/test_stage_timeline.py: 13 passed.
  • The new tests against main code: 2 failed (the open(path, ...) call in assert_one_error_line), so they catch the bug this PR fixes.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7188817057 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2232#issuecomment-7188817057). Originally posted by [DeadlyChirp](https://github.com/DeadlyChirp) on 2026-11-26T10:02:01Z. --- Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_stage_timeline.py`: 13 passed. - The new tests against main code: 2 failed (the `open(path, ...)` call in `assert_one_error_line`), so they catch the bug this PR fixes. (AI-assisted test run; output checked by hand.)
real-rusher commented 2026-11-26 10:12:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T10:12:59Z.


Conflicts with: #2186 (tools: read boot timeline states from the configured RVAs). Both change main() in tools/stage_timeline.py, and #2186 makes read() and the CLI take the state RVAs, which this PR's tests do not pass yet. If #2186 lands first, I will rebase this PR onto it and update tests/test_stage_timeline.py to the RVA arguments; if this one lands first, #2186 only needs to keep the OSError guard around its read() call.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7189064059 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2232#issuecomment-7189064059). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T10:12:59Z. --- Conflicts with: #2186 (tools: read boot timeline states from the configured RVAs). Both change main() in tools/stage_timeline.py, and #2186 makes read() and the CLI take the state RVAs, which this PR's tests do not pass yet. If #2186 lands first, I will rebase this PR onto it and update tests/test_stage_timeline.py to the RVA arguments; if this one lands first, #2186 only needs to keep the OSError guard around its read() call.
lixonik commented 2026-11-26 11:12:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T11:12:34Z.

Review: COMMENTED


Windows 11: 13/13 stage timeline tests passed, including the CLI's missing/unreadable-input diagnostics. No findings.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6073135610 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2232#pullrequestreview-6073135610). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T11:12:34Z. **Review:** COMMENTED --- Windows 11: 13/13 stage timeline tests passed, including the CLI's missing/unreadable-input diagnostics. No findings. AI-assisted.
real-rusher commented 2026-11-26 13:41:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T13:41:56Z.


Closing as a duplicate of #1789 (STAGE-TIMELINE-STDOUT-GUARD-AND-PARSER-SAFETY), which is older, makes the same OSError change and adds tests/test_stage_timeline.py at the same path. I missed it when I claimed this. Thanks to everyone who verified this one, and to @ecox982745 for pointing out the overlap. If the timeline and CLI cases here are wanted on top of #1789, they can follow as a separate test file once #1789 and #2186 have landed.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7193713639 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2232#issuecomment-7193713639). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T13:41:56Z. --- Closing as a duplicate of #1789 (STAGE-TIMELINE-STDOUT-GUARD-AND-PARSER-SAFETY), which is older, makes the same OSError change and adds tests/test_stage_timeline.py at the same path. I missed it when I claimed this. Thanks to everyone who verified this one, and to @ecox982745 for pointing out the overlap. If the timeline and CLI cases here are wanted on top of #1789, they can follow as a separate test file once #1789 and #2186 have landed.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2232
No description provided.