gamedata_maps: support UTF-8 BOM index.json, validate row fields, and write JSON atomically (GAMEDATA-MAPS-INDEX-AND-ATOMIC-IO) #1526

Merged
IlyassRS3 merged 1 commit from upstream-pr/1526 into main 2026-11-28 13:41:51 +00:00
IlyassRS3 commented 2026-11-25 03:26:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T03:26:38Z.


Summary

Hardens carve index loading, payload parsing, and JSON report writing in tools/gamedata_maps.py:

  • UTF-8 BOM & row validation (_read_index_rows, _read_row, _row_nonneg_int, read_payloads): opens index.json with encoding="utf-8-sig", validates that off is a non-negative non-bool integer (preserving the existing row N needs an 'off' diagnostic when missing), validates head (string or None) and size/stored (non-negative non-bool int or None), and stops continuation joins on empty missing chunks.
  • Slice-based PAMH row copy (parse_pamh): checks [offset + start, offset + start + count) against half once per non-empty row and copies max/min slices directly.
  • Atomic JSON report writing (_write_json, main): stages --json output via a sibling temp file with newline="\n", trailing LF, allow_nan=False, file_mode.published_mode, and replace_retry.replace, preserving pre-existing files on error.

Coordination

Testing

  • python3 -I tests/test_gamedata_maps.py -v — 28/28 OK (including 3 new regression tests)
  • python3 -I tests/test_gamedata_maps_bad_index.py -v — 8/8 OK
  • python3 -I tests/test_missing_input_exit_codes.py — 2/2 OK
  • python3 -I tests/test_psin_psch.py — 4/4 OK
  • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
  • python3 -I scripts/check_no_game_data.py tools/gamedata_maps.py tests/test_gamedata_maps.py — clean
  • python3 -m compileall -q tools/gamedata_maps.py tests/test_gamedata_maps.py — clean
  • Mutation check against unpatched main:tools/gamedata_maps.py: 3/3 new tests fail (FAILED (failures=5, errors=2)).

Checklist

  • AI-assisted: yes
  • GPUs tested: none required (pure standard-library CPU heightmap/CLI tests, zero game files)
  • No game data, keys, or online services included
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5484579851 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1526). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T03:26:38Z. --- ## Summary Hardens carve index loading, payload parsing, and JSON report writing in `tools/gamedata_maps.py`: - **UTF-8 BOM & row validation** (`_read_index_rows`, `_read_row`, `_row_nonneg_int`, `read_payloads`): opens `index.json` with `encoding="utf-8-sig"`, validates that `off` is a non-negative non-`bool` integer (preserving the existing `row N needs an 'off'` diagnostic when missing), validates `head` (string or `None`) and `size`/`stored` (non-negative non-`bool` int or `None`), and stops continuation joins on empty missing chunks. - **Slice-based PAMH row copy** (`parse_pamh`): checks `[offset + start, offset + start + count)` against `half` once per non-empty row and copies max/min slices directly. - **Atomic JSON report writing** (`_write_json`, `main`): stages `--json` output via a sibling temp file with `newline="\n"`, trailing LF, `allow_nan=False`, `file_mode.published_mode`, and `replace_retry.replace`, preserving pre-existing files on error. ## Coordination - Claimed in the coordination issue as: `GAMEDATA-MAPS-INDEX-AND-ATOMIC-IO` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151890540) - Depends on: none ## Testing - `python3 -I tests/test_gamedata_maps.py -v` — 28/28 OK (including 3 new regression tests) - `python3 -I tests/test_gamedata_maps_bad_index.py -v` — 8/8 OK - `python3 -I tests/test_missing_input_exit_codes.py` — 2/2 OK - `python3 -I tests/test_psin_psch.py` — 4/4 OK - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK - `python3 -I scripts/check_no_game_data.py tools/gamedata_maps.py tests/test_gamedata_maps.py` — clean - `python3 -m compileall -q tools/gamedata_maps.py tests/test_gamedata_maps.py` — clean - Mutation check against unpatched `main:tools/gamedata_maps.py`: 3/3 new tests fail (`FAILED (failures=5, errors=2)`). ## Checklist - AI-assisted: yes - GPUs tested: none required (pure standard-library CPU heightmap/CLI tests, zero game files) - No game data, keys, or online services included
copilot-pull-request-reviewer[bot] commented 2026-11-25 03:26:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T03:26:46Z.

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:6051414703 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1526#pullrequestreview-6051414703). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T03:26:46Z. **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.
ytsodacan commented 2026-11-25 03:34:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ytsodacan on 2026-11-25T03:34:15Z.


[KEEP]

  • Looks correct and well scoped to tools/gamedata_maps.py and tests/test_gamedata_maps.py: utf-8-sig index loading, _row_nonneg_int validation of off/stored/size (rejecting bools and negatives), head type check, and an atomic _write_json (temp file + replace_retry.replace, allow_nan=False) with tests for each.
  • CI is still pending (no-game-data, change-scope); the PR is mergeable. Hold for green before merging.
  • The parse_pamh change to slice copies rather than per-cell loops is a behavior-preserving rewrite bundled into a "validation/IO" PR; the bounds check is equivalent, but it is an unrelated optimisation that a reviewer should confirm.
  • Likely a MERGE once CI passes.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152037572 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1526#issuecomment-7152037572). Originally posted by [ytsodacan](https://github.com/ytsodacan) on 2026-11-25T03:34:15Z. --- **[KEEP]** - Looks correct and well scoped to `tools/gamedata_maps.py` and `tests/test_gamedata_maps.py`: `utf-8-sig` index loading, `_row_nonneg_int` validation of `off`/`stored`/`size` (rejecting bools and negatives), `head` type check, and an atomic `_write_json` (temp file + `replace_retry.replace`, `allow_nan=False`) with tests for each. - CI is still pending (`no-game-data`, `change-scope`); the PR is mergeable. Hold for green before merging. - The `parse_pamh` change to slice copies rather than per-cell loops is a behavior-preserving rewrite bundled into a "validation/IO" PR; the bounds check is equivalent, but it is an unrelated optimisation that a reviewer should confirm. - Likely a MERGE once CI passes.
whoalin1 commented 2026-11-25 07:45:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T07:45:19Z.


Independent verification (native Windows, Python 3.11.9): diff vs merge-base reviewed; utf-8-sig index.json, non-neg/non-bool off/head/size/stored validation preserving the row diagnostic, single-bounds parse_pamh slice (indexing equivalence verified), atomic _write_json via NamedTemporaryFile+replace_retry with newline="\n"/allow_nan=False, empty-chunk join guard — all present. Tests reproduce claimed counts exactly: test_gamedata_maps.py 28/28, test_gamedata_maps_bad_index.py 8/8, test_missing_input_exit_codes.py 2/2, test_psin_psch.py 4/4, line-endings 3/3; compileall + check_no_game_data.py clean. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156215179 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1526#issuecomment-7156215179). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T07:45:19Z. --- Independent verification (native Windows, Python 3.11.9): diff vs merge-base reviewed; `utf-8-sig` index.json, non-neg/non-bool `off`/`head`/`size`/`stored` validation preserving the row diagnostic, single-bounds `parse_pamh` slice (indexing equivalence verified), atomic `_write_json` via NamedTemporaryFile+replace_retry with `newline="\n"`/`allow_nan=False`, empty-chunk join guard — all present. Tests reproduce claimed counts exactly: `test_gamedata_maps.py` 28/28, `test_gamedata_maps_bad_index.py` 8/8, `test_missing_input_exit_codes.py` 2/2, `test_psin_psch.py` 4/4, line-endings 3/3; compileall + `check_no_game_data.py` clean. AI-assisted verification.
MoonEyes commented 2026-11-28 13:41:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T13:41:55Z.


Merged after local re-verification: this PR merged onto main ddcf9ac03 without conflict, and its test file(s) (tests/test_gamedata_maps.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7240120777 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1526#issuecomment-7240120777). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T13:41:55Z. --- Merged after local re-verification: this PR merged onto `main` ddcf9ac03 without conflict, and its test file(s) (`tests/test_gamedata_maps.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
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!1526
No description provided.