world_grid_atlas: harden geometry, alignment, linear_fit, DDS/MHIU bounds, manifests, and strict JSON (WORLD-GRID-ATLAS-VALIDATION-HARDENING) #1506

Merged
IlyassRS3 merged 1 commit from upstream-pr/1506 into main 2026-11-29 00:44:07 +00:00
IlyassRS3 commented 2026-11-25 02:35:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T02:35:18Z.


Claimed in the coordination issue as: WORLD-GRID-ATLAS-VALIDATION-HARDENING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7150859873)

What and why

Hardens tools/world_grid_atlas.py against malformed geometry, alignment, regression-fit, DDS, MHIU, manifest, and JSON inputs:

  • geometry(): rejects width <= 0, height <= 0, bool dimensions/values, non-3-tuple or non-finite origin, and negative or non-finite zInflation (previously width=0/-512 passed % tile and triggered ZeroDivisionError/inverted boxes, and negative zInflation produced z_min > z_max).
  • cell_box(): rejects bool / non-int cells (previously 1.5 or True silently returned a box) and non-positive grid dimensions.
  • fill_by_order(): rejects negative/bool n_tiles, duplicate cells in order, out-of-range/bool anchor tile indices, and anchor cells absent from order (raising ValueError instead of KeyError or out-of-range placement keys).
  • align(): rejects ragged score rows and non-finite/bool scores, and verifies backtrack indices are valid (previously NaN/-inf scores left arg[j] == -1, silently returning -1 and indexing order[-1]).
  • linear_fit(): checks len(xs) == len(ys) (previously my = fsum(ys) / len(xs) silently computed wrong means and regression parameters on mismatched inputs), rejects non-finite/bool points, and clamps Pearson r to [-1.0, 1.0].
  • read_image(): checks width > 0, height > 0, and len(data) >= DX10_HEADER before struct.unpack_from(..., 128) so a truncated DDS / DX10 file raises a clean ValueError instead of an unhandled struct.error traceback.
  • split_cells() / tile_step(): reject non-positive rows, columns, w, h, and p with ValueError instead of ZeroDivisionError.
  • water_fit() & run(): skip degenerate zero-span / non-finite / truncated MHIU heightmaps cleanly without divide-by-zero warnings, and run water_fit only on WaterSystemHeightMap itself rather than every grid sharing a dictionary set.
  • load_manifests() & write_json(): validate JSON manifest root/items/textures structure (clean ValueError instead of AttributeError) and pass allow_nan=False to json.dump().

Tested

  • python3 -I tests/test_world_grid_atlas.py: 42/42 (26 stdlib tests run and OK; 16 numpy/PIL tests skipped under -I).
  • python3 tests/test_world_grid_atlas.py: 42/42 OK (all stdlib + numpy/PIL forward tests pass).
  • Mutation check against unpatched main (3ff2a2adc): all 10 new regression tests fail (failures=19, errors=5 plus RuntimeWarning: divide by zero on water_fit).
  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.
  • python3 -I scripts/check_no_game_data.py tools/world_grid_atlas.py tests/test_world_grid_atlas.py: clean.
  • python3 -m compileall -q tools/world_grid_atlas.py tests/test_world_grid_atlas.py: clean.

GPUs tested: n/a (Python atlas/analysis tool only)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — no translator rule changed)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5484062570 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1506). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T02:35:18Z. --- Claimed in the coordination issue as: WORLD-GRID-ATLAS-VALIDATION-HARDENING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7150859873) ### What and why Hardens `tools/world_grid_atlas.py` against malformed geometry, alignment, regression-fit, DDS, MHIU, manifest, and JSON inputs: - **`geometry()`**: rejects `width <= 0`, `height <= 0`, `bool` dimensions/values, non-3-tuple or non-finite `origin`, and negative or non-finite `zInflation` (previously `width=0`/`-512` passed `% tile` and triggered `ZeroDivisionError`/inverted boxes, and negative `zInflation` produced `z_min > z_max`). - **`cell_box()`**: rejects `bool` / non-`int` cells (previously `1.5` or `True` silently returned a box) and non-positive grid dimensions. - **`fill_by_order()`**: rejects negative/`bool` `n_tiles`, duplicate cells in `order`, out-of-range/`bool` anchor tile indices, and anchor cells absent from `order` (raising `ValueError` instead of `KeyError` or out-of-range placement keys). - **`align()`**: rejects ragged score rows and non-finite/`bool` scores, and verifies backtrack indices are valid (previously `NaN`/`-inf` scores left `arg[j] == -1`, silently returning `-1` and indexing `order[-1]`). - **`linear_fit()`**: checks `len(xs) == len(ys)` (previously `my = fsum(ys) / len(xs)` silently computed wrong means and regression parameters on mismatched inputs), rejects non-finite/`bool` points, and clamps Pearson `r` to `[-1.0, 1.0]`. - **`read_image()`**: checks `width > 0`, `height > 0`, and `len(data) >= DX10_HEADER` before `struct.unpack_from(..., 128)` so a truncated `DDS ` / `DX10` file raises a clean `ValueError` instead of an unhandled `struct.error` traceback. - **`split_cells()` / `tile_step()`**: reject non-positive `rows`, `columns`, `w`, `h`, and `p` with `ValueError` instead of `ZeroDivisionError`. - **`water_fit()` & `run()`**: skip degenerate zero-span / non-finite / truncated MHIU heightmaps cleanly without divide-by-zero warnings, and run `water_fit` only on `WaterSystemHeightMap` itself rather than every grid sharing a dictionary set. - **`load_manifests()` & `write_json()`**: validate JSON manifest root/items/textures structure (clean `ValueError` instead of `AttributeError`) and pass `allow_nan=False` to `json.dump()`. ### Tested - `python3 -I tests/test_world_grid_atlas.py`: 42/42 (26 stdlib tests run and OK; 16 numpy/PIL tests skipped under `-I`). - `python3 tests/test_world_grid_atlas.py`: 42/42 OK (all stdlib + numpy/PIL forward tests pass). - Mutation check against unpatched `main` (`3ff2a2adc`): all 10 new regression tests fail (`failures=19, errors=5` plus `RuntimeWarning: divide by zero` on `water_fit`). - `python3 -I tests/test_text_write_line_endings.py`: 3/3 OK. - `python3 -I scripts/check_no_game_data.py tools/world_grid_atlas.py tests/test_world_grid_atlas.py`: clean. - `python3 -m compileall -q tools/world_grid_atlas.py tests/test_world_grid_atlas.py`: clean. GPUs tested: n/a (Python atlas/analysis tool only) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — no translator rule changed)
copilot-pull-request-reviewer[bot] commented 2026-11-25 02:35:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T02:35:30Z.

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:6050927084 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1506#pullrequestreview-6050927084). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T02:35:30Z. **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:36:14 +00:00 (Migrated from github.com)

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


[KEEP]

  • Hardening of tools/world_grid_atlas.py reads sensibly (input validation in geometry, cell_box, fill_by_order, align, linear_fit, read_image, manifests, allow_nan=False) and adds tests in tests/test_world_grid_atlas.py.
  • No CI checks have been reported on fix/world-grid-atlas-hardening, so nothing is verified by CI yet; mergeable state is clean.
  • Scope is broad for one PR (about ten functions, 227 additions). It also changes behavior beyond validation: water_fit now runs only for HEIGHT_GRID instead of any is_height grid, and manifest Offset/Index/Width/Height now go through _whole_number, which could reject inputs that previously loaded. A maintainer should confirm both are intended.
  • Re-triage once checks run green.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152068809 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1506#issuecomment-7152068809). Originally posted by [ytsodacan](https://github.com/ytsodacan) on 2026-11-25T03:36:14Z. --- **[KEEP]** - Hardening of `tools/world_grid_atlas.py` reads sensibly (input validation in `geometry`, `cell_box`, `fill_by_order`, `align`, `linear_fit`, `read_image`, manifests, `allow_nan=False`) and adds tests in `tests/test_world_grid_atlas.py`. - No CI checks have been reported on `fix/world-grid-atlas-hardening`, so nothing is verified by CI yet; mergeable state is clean. - Scope is broad for one PR (about ten functions, 227 additions). It also changes behavior beyond validation: `water_fit` now runs only for `HEIGHT_GRID` instead of any `is_height` grid, and manifest `Offset`/`Index`/`Width`/`Height` now go through `_whole_number`, which could reject inputs that previously loaded. A maintainer should confirm both are intended. - Re-triage once checks run green.
zmasi commented 2026-11-28 20:43:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T20:43:27Z.


#1506 | head 6b984f2882 (merged cleanly with main 1bc055e6c2) | python -I tests/test_world_grid_atlas.py + numpy 2.5.1 direct verification of read_image, water_fit, split_cells, and tile_step | red on main: FAILED (failures=19, errors=3, skipped=17) (IndexError on ragged align rows, ZeroDivisionError on 0-column cell_box, AttributeError on non-dict manifest.json, struct.error on truncated DX10 R16_UNORM DDS header, and unguarded bool/non-finite inputs) | green on PR+main: 42 ran, OK (skipped=17) (25/25 PlainLogicTest + ValidationHardeningTest + WriteJsonTest OK, plus 3/3 numpy read_image/water_fit/split_cells/tile_step guards OK) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited tools/world_grid_atlas.py and tests/test_world_grid_atlas.py on Windows 11, verifying finite/non-bool validation across geometry, cell_box, fill_by_order, align, linear_fit, and load_manifests, [-1.0, 1.0] Pearson r clamping, truncated DX10 R16_UNORM DDS header ValueError check, warning-free skipping of zero-span MHIU water heightmaps, allow_nan=False atomic write_json cleanup, tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245493461 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1506#issuecomment-7245493461). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T20:43:27Z. --- #1506 | head 6b984f2882d0ee4eadaa4737c159030dc10e5c78 (merged cleanly with main 1bc055e6c2) | `python -I tests/test_world_grid_atlas.py` + `numpy` 2.5.1 direct verification of `read_image`, `water_fit`, `split_cells`, and `tile_step` | red on main: `FAILED (failures=19, errors=3, skipped=17)` (`IndexError` on ragged `align` rows, `ZeroDivisionError` on 0-column `cell_box`, `AttributeError` on non-dict `manifest.json`, `struct.error` on truncated DX10 `R16_UNORM` DDS header, and unguarded bool/non-finite inputs) | green on PR+main: `42 ran, OK (skipped=17)` (`25/25` `PlainLogicTest` + `ValidationHardeningTest` + `WriteJsonTest` `OK`, plus `3/3` `numpy` `read_image`/`water_fit`/`split_cells`/`tile_step` guards `OK`) | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `tools/world_grid_atlas.py` and `tests/test_world_grid_atlas.py` on Windows 11, verifying finite/non-bool validation across `geometry`, `cell_box`, `fill_by_order`, `align`, `linear_fit`, and `load_manifests`, `[-1.0, 1.0]` Pearson `r` clamping, truncated DX10 `R16_UNORM` DDS header `ValueError` check, warning-free skipping of zero-span `MHIU` water heightmaps, `allow_nan=False` atomic `write_json` cleanup, `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
TheGeogeo commented 2026-11-29 00:17:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T00:17:20Z.


Tested 6b984f288 merged (no commit) with main 829530dbd: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Green: tests/test_world_grid_atlas.py, 42 tests pass (1 skipped).
  • Red: with tools/world_grid_atlas.py back to main, 19 failures and 6 errors (ValueError not raised).

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248008024 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1506#issuecomment-7248008024). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T00:17:20Z. --- Tested `6b984f288` merged (no commit) with `main` `829530dbd`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - Green: `tests/test_world_grid_atlas.py`, 42 tests pass (1 skipped). - Red: with `tools/world_grid_atlas.py` back to `main`, 19 failures and 6 errors (`ValueError not raised`). No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 00:44:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T00:44:09Z.


Merged after TheGeogeo's red/green check (check) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto main 173fa8284 without conflict, and its test file(s) (tests/test_world_grid_atlas.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:7248315660 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1506#issuecomment-7248315660). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T00:44:09Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/1506#issuecomment-7248008024)) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto `main` 173fa8284 without conflict, and its test file(s) (`tests/test_world_grid_atlas.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!1506
No description provided.