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

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

📋 Pull Request Information

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

Base: main ← Head: fix/page-index-summary-and-atomic-io


📝 Commits (1)

  • 83f4e8a page_index: handle mixed None/int versions, guard scan_rpf limit and listdir errors, and write JSON/CSV atomically

📊 Changes

2 files changed (+120 additions, -7 deletions)

View changed files

📝 tests/test_page_index.py (+75 -0)
📝 tools/page_index.py (+45 -7)

📄 Description

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)).

🔄 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/1566 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/page-index-summary-and-atomic-io` --- ### 📝 Commits (1) - [`83f4e8a`](https://github.com/ubiquitarianism/leonida/commit/83f4e8a984db75b6a5adb1999bc43bc782fe6395) page_index: handle mixed None/int versions, guard scan_rpf limit and listdir errors, and write JSON/CSV atomically ### 📊 Changes **2 files changed** (+120 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_page_index.py` (+75 -0) 📝 `tools/page_index.py` (+45 -7) </details> ### 📄 Description 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)`). --- <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#1590
No description provided.