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

Merged
leonida/mandy
quietfold merged 1 commit from fix/world-archetypes-extents-and-io into main 2026-11-28 10:49:54 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 04:25:22 +00:00

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)

## 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] reviewed 2026-11-25 04:25:35 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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

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)

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 description provided.