page_index: handle mixed None/int versions, guard scan_rpf limit/listdir errors, and write JSON/CSV atomically (PAGE-INDEX-SUMMARY-AND-ATOMIC-IO) #1566

Merged
leonida/mandy
quietfold merged 1 commit from fix/page-index-summary-and-atomic-io into main 2026-11-28 10:52:15 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 04:42:24 +00:00

Item ID: PAGE-INDEX-SUMMARY-AND-ATOMIC-IO (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch tools/page_index.py)

Summary

  • Fix TypeError in summarise() on mixed None and int versions: sorted({p["version"] for p in pages}) crashed whenever pages contained both None and integer versions; count in one pass with Counter and sort with (v is None, 0 if v is None else v).
  • Reject non-positive limit in scan_rpf(): previously limit=0 was falsy and scanned the whole archive, and negative limit silently scanned nothing; now limit is not None and limit < 1 raises ValueError("limit must be at least 1") matching the CLI validator.
  • Catch OSError on os.listdir(a.source) during overwrite checking in main(): an unreadable carve directory with an existing output file previously raised an uncaught PermissionError traceback instead of exiting 2 cleanly.
  • Write JSON and CSV atomically: stage output through NamedTemporaryFile + file_mode.published_mode + replace_retry.replace, enforce allow_nan=False and trailing LF \n on JSON, and clean up temporary files on failure so existing outputs are never truncated.

Testing

  • AI-assisted: yes
  • GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files)
  • python3 -W error -I tests/test_page_index.py -v: 25/25 passed
  • python3 -W error -I tests/test_text_write_line_endings.py -v: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/page_index.py tests/test_page_index.py: passed
  • python3 -m compileall -q make_game.py tools tests: passed
  • Mutation check against unpatched main:tools/page_index.py: all 4 new tests fail (FAILED (failures=3, errors=2)).
Item ID: `PAGE-INDEX-SUMMARY-AND-ATOMIC-IO` (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch `tools/page_index.py`) ## Summary - **Fix `TypeError` in `summarise()` on mixed `None` and `int` versions**: `sorted({p["version"] for p in pages})` crashed whenever pages contained both `None` and integer versions; count in one pass with `Counter` and sort with `(v is None, 0 if v is None else v)`. - **Reject non-positive `limit` in `scan_rpf()`**: previously `limit=0` was falsy and scanned the whole archive, and negative `limit` silently scanned nothing; now `limit is not None and limit < 1` raises `ValueError("limit must be at least 1")` matching the CLI validator. - **Catch `OSError` on `os.listdir(a.source)` during overwrite checking in `main()`**: an unreadable carve directory with an existing output file previously raised an uncaught `PermissionError` traceback instead of exiting 2 cleanly. - **Write JSON and CSV atomically**: stage output through `NamedTemporaryFile` + `file_mode.published_mode` + `replace_retry.replace`, enforce `allow_nan=False` and trailing LF `\n` on JSON, and clean up temporary files on failure so existing outputs are never truncated. ## Testing - AI-assisted: yes - GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files) - `python3 -W error -I tests/test_page_index.py -v`: **25/25 passed** - `python3 -W error -I tests/test_text_write_line_endings.py -v`: **3/3 passed** - `python3 -I scripts/check_no_game_data.py tools/page_index.py tests/test_page_index.py`: passed - `python3 -m compileall -q make_game.py tools tests`: passed - Mutation check against unpatched `main:tools/page_index.py`: all 4 new tests fail (`FAILED (failures=3, errors=2)`).
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 04:42:32 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:52:10 +00:00

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.