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

Open
github-bot wants to merge 1 commit from github-bot/gh-1555 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 04:25 UTC · original
IlyassRS3:fix/world-archetypes-extents-and-io → main · +146 −13 · 2 files · 1 commits · open

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)

**@⁠IlyassRS3** on GitHub · 2026-11-25 04:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1555) `IlyassRS3:fix/world-archetypes-extents-and-io` → `main` · +146 −13 · 2 files · 1 commits · open ## 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:24 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 04:25 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 04:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1555#pullrequestreview-6051844746) · **reviewed** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1555/head:github-bot/gh-1555'
git switch 'github-bot/gh-1555'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1555'
git switch 'github-bot/gh-1555'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1555'
git switch 'github-bot/gh-1555'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1555'
git switch 'main'
git merge --squash 'github-bot/gh-1555'
git switch 'main'
git merge --ff-only 'github-bot/gh-1555'
git switch 'main'
git merge 'github-bot/gh-1555'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.