gamedata_index: keep UTF-8 continuations in declared XML, fix ArchiveSource cleanup, and harden carved_stream/atomic I/O (GAMEDATA-INDEX-UTF8-DECL-AND-IO) #1578

Merged
IlyassRS3 merged 1 commit from upstream-pr/1578 into main 2026-11-28 10:54:06 +00:00
IlyassRS3 commented 2026-11-25 04:56:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T04:56:47Z.


Item ID: GAMEDATA-INDEX-UTF8-DECL-AND-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/gamedata_index.py)

Summary

  • Keep UTF-8 continuation streams for declared XML (kind == "decl"): build_rows() previously applied _utf8_text(nxt) only to declarationless XML (line 318), while declared XML (<?xml ...?>, line 275) broke on any nk == "binary" chunk — splitting multi-chunk non-ASCII UTF-8 XML documents into an incomplete XML header plus a binary blob that swallowed the closing tag.
  • Close ArchiveSource file handles and temp directories on __init__ failure: if the carver subprocess fails, index.json fails to parse, or mmap() raises (e.g. empty archive), ArchiveSource now calls self.close() before re-raising instead of leaking _fh and _tmp.
  • Harden carved_stream() against case-variant names and hardlink aliases: match [0-9a-fA-F]{12}.(bin|bk2) case-insensitively and check existing output paths against carved streams in directory via same_report_path so uppercase spellings (.BIN on case-insensitive volumes) and hardlink aliases cannot overwrite carved inputs.
  • Reject empty/whitespace --json/--csv and write outputs atomically: reject "" / " " up front (previously "" was silently ignored and " " wrote a literal " " file), stage CSV/JSON via NamedTemporaryFile + file_mode.published_mode + replace_retry.replace, enforce allow_nan=False and trailing LF \n on JSON, catch RecursionError on malformed inputs, and break summarize()["types"] ties deterministically.

Testing

  • AI-assisted: yes
  • GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files)
  • python3 -W error -I tests/test_gamedata_index.py -v: 42/42 passed
  • python3 -W error -I tests/test_gamedata_index_report_paths.py -v: 8/8 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/gamedata_index.py tests/test_gamedata_index.py: passed
  • python3 -m compileall -q make_game.py tools tests: passed
  • Mutation check against unpatched main:tools/gamedata_index.py: all 5 new tests fail (FAILED (failures=8, errors=1)).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485438659 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1578). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T04:56:47Z. --- Item ID: `GAMEDATA-INDEX-UTF8-DECL-AND-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/gamedata_index.py`) ## Summary - **Keep UTF-8 continuation streams for declared XML (`kind == "decl"`)**: `build_rows()` previously applied `_utf8_text(nxt)` only to declarationless XML (`line 318`), while declared XML (`<?xml ...?>`, `line 275`) broke on any `nk == "binary"` chunk — splitting multi-chunk non-ASCII UTF-8 XML documents into an incomplete XML header plus a binary blob that swallowed the closing tag. - **Close `ArchiveSource` file handles and temp directories on `__init__` failure**: if the carver subprocess fails, `index.json` fails to parse, or `mmap()` raises (e.g. empty archive), `ArchiveSource` now calls `self.close()` before re-raising instead of leaking `_fh` and `_tmp`. - **Harden `carved_stream()` against case-variant names and hardlink aliases**: match `[0-9a-fA-F]{12}.(bin|bk2)` case-insensitively and check existing output paths against carved streams in `directory` via `same_report_path` so uppercase spellings (`.BIN` on case-insensitive volumes) and hardlink aliases cannot overwrite carved inputs. - **Reject empty/whitespace `--json`/`--csv` and write outputs atomically**: reject `""` / `" "` up front (previously `""` was silently ignored and `" "` wrote a literal `" "` file), stage CSV/JSON via `NamedTemporaryFile` + `file_mode.published_mode` + `replace_retry.replace`, enforce `allow_nan=False` and trailing LF `\n` on JSON, catch `RecursionError` on malformed inputs, and break `summarize()["types"]` ties deterministically. ## Testing - AI-assisted: yes - GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files) - `python3 -W error -I tests/test_gamedata_index.py -v`: **42/42 passed** - `python3 -W error -I tests/test_gamedata_index_report_paths.py -v`: **8/8 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/gamedata_index.py tests/test_gamedata_index.py`: passed - `python3 -m compileall -q make_game.py tools tests`: passed - Mutation check against unpatched `main:tools/gamedata_index.py`: all 5 new tests fail (`FAILED (failures=8, errors=1)`).
copilot-pull-request-reviewer[bot] commented 2026-11-25 04:56:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T04:56:55Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6052066579 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1578#pullrequestreview-6052066579). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T04:56:55Z. **Review:** COMMENTED --- 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:54:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:54:00Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238194472 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1578#issuecomment-7238194472). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:54:00Z. --- 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 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!1578
No description provided.