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

Open
opened 2026-11-26 20:21:45 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1555
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/world-archetypes-extents-and-io


📝 Commits (1)

  • 894044f world_archetypes: fix identity-quaternion/nameless-def/schema bugs, folder-input guard, and atomic I/O

📊 Changes

2 files changed (+146 additions, -13 deletions)

View changed files

📝 tests/test_world_archetypes.py (+74 -0)
📝 tools/world_archetypes.py (+72 -13)

📄 Description

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)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1555 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/world-archetypes-extents-and-io` --- ### 📝 Commits (1) - [`894044f`](https://github.com/ubiquitarianism/leonida/commit/894044f1cb68f5f3404647c22f4be9b762e9e68e) world_archetypes: fix identity-quaternion/nameless-def/schema bugs, folder-input guard, and atomic I/O ### 📊 Changes **2 files changed** (+146 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_world_archetypes.py` (+74 -0) 📝 `tools/world_archetypes.py` (+72 -13) </details> ### 📄 Description ## 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1582
No description provided.