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

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

@⁠IlyassRS3 on GitHub · 2026-11-25 04:42 UTC · original
IlyassRS3:fix/page-index-summary-and-atomic-io → main · +120 −7 · 2 files · 1 commits · open

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)).
**@⁠IlyassRS3** on GitHub · 2026-11-25 04:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1566) `IlyassRS3:fix/page-index-summary-and-atomic-io` → `main` · +120 −7 · 2 files · 1 commits · open 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)`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:51 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 04:42 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 04:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1566#pullrequestreview-6051964754) · **reviewed** 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.
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/1566/head:github-bot/gh-1566'
git switch 'github-bot/gh-1566'

Merge

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