world_archetypes: fix identity-quaternion/nameless-def/schema bugs, folder-input guard, and atomic I/O (WORLD-ARCHETYPES-EXTENTS-AND-IO) #1555

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

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


What

Fix four extents/schema/indexing bugs and harden CLI guards and JSON output in tools/world_archetypes.py:

  1. Identity quaternions (0, 0, 0, -1) / unnormalized (0, 0, 0, k) / zero counted as rotated (check_extents):
    • _rotation(q, ...) normalizes q and maps both q and -q (and (0, 0, 0, 0)) to the 3×3 identity matrix, yet line 210 checked [round(c, 6) for c in e["rotation"]] != [0, 0, 0, 1], misclassifying identity entities with w = -1 as rotated and skewing rotation["maps"] and match counts.
    • Add _is_rotated(q) normalizing q and checking max(abs(x/n), abs(y/n), abs(z/n)) > 1e-6.
  2. Nameless archetypes polluted defs[None] and matched nameless entities (run, check_extents):
    • When an archetype omitted name, defs[None] = d inflated summary["names"], compared unrelated nameless boxes for names_with_differing_boxes, and allowed an entity with archetype: None to match defs[None] in check_extents().
    • Skip defs indexing when d.get("name") is None and reject e.get("archetype") is None in check_extents().
  3. Truncated struct/block tables emitted zero-padded dummy entries (schema):
    • Guard len(b) < 0x50 and stop struct/block iteration when o + 32 > n or o + 16 > n instead of reading out-of-range 0s from WI._u32/_u64.
  4. CLI window validation, carved-folder overwrite guard, clean error handling, and atomic JSON write (main):
    • Reject --start < 0, --limit < 1, and empty/whitespace --out via ap.error(...).
    • When path is a folder of carved files, check --out against every input file inside path (WI._directory_files(a.path) + same_report_path) so --out <folder>/a.bin cannot overwrite a carved input.
    • Catch (OSError, ValueError) from run() cleanly via ap.error(...) (exit 2, no traceback).
    • Write --out atomically through a sibling temp file (newline="\n", trailing "\n", file_mode.published_mode, replace_retry.replace).

Claimed in the coordination issue as

WORLD-ARCHETYPES-EXTENTS-AND-IO — verified 0 open PRs and 0 prior claims; unable to post a comment on #14 because GitHub disabled commenting once #14 reached its 2,500-comment cap (and no successor "Coordinating who works on what" issue is open yet).

Testing

  • python3 -I -W error tests/test_world_archetypes.py -v: 23/23 OK (including 4 new regression tests).

  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.

  • python3 -I scripts/check_no_game_data.py tools/world_archetypes.py tests/test_world_archetypes.py: clean.

  • python3 -m compileall -q tools/world_archetypes.py tests/test_world_archetypes.py: clean.

  • Mutation check against unpatched main:tools/world_archetypes.py: all 4 new tests (13 assertions/subtests) fail on main (FAILED (failures=13)).

  • AI-assisted: yes

  • GPUs tested: none (CPU-only 0x7a archetype/extents tests on macOS; no GPU or game files needed)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485154267 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1555). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T04:25:22Z. --- ## What Fix four extents/schema/indexing bugs and harden CLI guards and JSON output in `tools/world_archetypes.py`: 1. **Identity quaternions `(0, 0, 0, -1)` / unnormalized `(0, 0, 0, k)` / zero counted as rotated (`check_extents`)**: - `_rotation(q, ...)` normalizes `q` and maps both `q` and `-q` (and `(0, 0, 0, 0)`) to the 3×3 identity matrix, yet line 210 checked `[round(c, 6) for c in e["rotation"]] != [0, 0, 0, 1]`, misclassifying identity entities with `w = -1` as rotated and skewing `rotation["maps"]` and match counts. - Add `_is_rotated(q)` normalizing `q` and checking `max(abs(x/n), abs(y/n), abs(z/n)) > 1e-6`. 2. **Nameless archetypes polluted `defs[None]` and matched nameless entities (`run`, `check_extents`)**: - When an archetype omitted `name`, `defs[None] = d` inflated `summary["names"]`, compared unrelated nameless boxes for `names_with_differing_boxes`, and allowed an entity with `archetype: None` to match `defs[None]` in `check_extents()`. - Skip `defs` indexing when `d.get("name") is None` and reject `e.get("archetype") is None` in `check_extents()`. 3. **Truncated struct/block tables emitted zero-padded dummy entries (`schema`)**: - Guard `len(b) < 0x50` and stop struct/block iteration when `o + 32 > n` or `o + 16 > n` instead of reading out-of-range `0`s from `WI._u32`/`_u64`. 4. **CLI window validation, carved-folder overwrite guard, clean error handling, and atomic JSON write (`main`)**: - Reject `--start < 0`, `--limit < 1`, and empty/whitespace `--out` via `ap.error(...)`. - When `path` is a folder of carved files, check `--out` against every input file inside `path` (`WI._directory_files(a.path)` + `same_report_path`) so `--out <folder>/a.bin` cannot overwrite a carved input. - Catch `(OSError, ValueError)` from `run()` cleanly via `ap.error(...)` (exit 2, no traceback). - Write `--out` atomically through a sibling temp file (`newline="\n"`, trailing `"\n"`, `file_mode.published_mode`, `replace_retry.replace`). ## Claimed in the coordination issue as `WORLD-ARCHETYPES-EXTENTS-AND-IO` — verified 0 open PRs and 0 prior claims; unable to post a comment on `#14` because GitHub disabled commenting once `#14` reached its 2,500-comment cap (and no successor `"Coordinating who works on what"` issue is open yet). ## Testing - `python3 -I -W error tests/test_world_archetypes.py -v`: **23/23 OK** (including 4 new regression tests). - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**. - `python3 -I scripts/check_no_game_data.py tools/world_archetypes.py tests/test_world_archetypes.py`: clean. - `python3 -m compileall -q tools/world_archetypes.py tests/test_world_archetypes.py`: clean. - Mutation check against unpatched `main:tools/world_archetypes.py`: all 4 new tests (13 assertions/subtests) fail on `main` (`FAILED (failures=13)`). - AI-assisted: yes - GPUs tested: none (CPU-only 0x7a archetype/extents tests on macOS; no GPU or game files needed)
copilot-pull-request-reviewer[bot] commented 2026-11-25 04:25:35 +00:00 (Migrated from github.com)

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

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

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


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