character_textures: fix None/zero/dict-param classification, unknown_slots count, and atomic I/O (CHARACTER-TEXTURES-CLASSIFICATION-AND-IO) #1553

Merged
IlyassRS3 merged 1 commit from upstream-pr/1553 into main 2026-11-28 11:10:40 +00:00
IlyassRS3 commented 2026-11-25 04:21:42 +00:00 (Migrated from github.com)

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


What

Fix four classification/summary bugs and harden --json/--csv I/O in tools/character_textures.py:

  1. Missing texture name serialized as literal "None" (_texture_name):
    • When a binding had no name/texture/key/id64 field (or a None entry), _first(...) returned None and _texture_name(None) ran str(None) -> "None" instead of "-". Return "-" when value is None.
  2. Falsy material name 0 discarded (classify_material):
    • _first() explicitly preserves 0 and False as values, not gaps, but _first(material, MATERIAL_NAME_KEYS) or f"material[{index}]" discarded 0 and renamed it to "material[0]". Check is not None before falling back.
  3. Dict-form Textures clobbered explicit lowercase param/slot/hash (texture_bindings):
    • binding.setdefault("Param", slot) inserted "Param" (which precedes "param"/"slot"/"hash" in PARAM_KEYS) even when the entry dict already carried a lowercase slot key, overwriting the entry's own slot with the outer dict key. Only set "Param" when _first(binding, PARAM_KEYS) is None.
  4. summary["unknown_slots"] missed bindings without a valid Param (build_report):
    • Counting only b["role"].startswith("unknown 0x") skipped bindings with missing/malformed Param (role == "unknown"). Count both "unknown" and "unknown 0x...".
  5. CLI empty/whitespace --json/--csv validation & atomic writes (write_json, write_csv, main):
    • Reject empty or whitespace-only --json/--csv paths via parser.error(...) instead of silently ignoring "" or creating a whitespace-named file (" ").
    • Write JSON (allow_nan=False, trailing "\n") and CSV (newline="") atomically through sibling temp files with file_mode.published_mode and replace_retry.replace, preserving existing files on failure.
    • Accept optional argv=None in main(argv=None).

Claimed in the coordination issue as

CHARACTER-TEXTURES-CLASSIFICATION-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_character_textures.py -v: 18/18 OK (including 3 new regression tests).

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

  • python3 -I scripts/check_no_game_data.py tools/character_textures.py tests/test_character_textures.py: clean.

  • python3 -m compileall -q tools/character_textures.py tests/test_character_textures.py: clean.

  • Mutation check against unpatched main:tools/character_textures.py: all 3 new tests fail on main (FAILED (failures=6, errors=1)).

  • AI-assisted: yes

  • GPUs tested: none (CPU-only JSON/CSV texture classification tests on macOS; no GPU or game files needed)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485120525 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1553). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T04:21:42Z. --- ## What Fix four classification/summary bugs and harden `--json`/`--csv` I/O in `tools/character_textures.py`: 1. **Missing texture name serialized as literal `"None"` (`_texture_name`)**: - When a binding had no name/texture/key/id64 field (or a `None` entry), `_first(...)` returned `None` and `_texture_name(None)` ran `str(None)` -> `"None"` instead of `"-"`. Return `"-"` when `value is None`. 2. **Falsy material name `0` discarded (`classify_material`)**: - `_first()` explicitly preserves `0` and `False` as values, not gaps, but `_first(material, MATERIAL_NAME_KEYS) or f"material[{index}]"` discarded `0` and renamed it to `"material[0]"`. Check `is not None` before falling back. 3. **Dict-form `Textures` clobbered explicit lowercase `param`/`slot`/`hash` (`texture_bindings`)**: - `binding.setdefault("Param", slot)` inserted `"Param"` (which precedes `"param"`/`"slot"`/`"hash"` in `PARAM_KEYS`) even when the entry dict already carried a lowercase slot key, overwriting the entry's own slot with the outer dict key. Only set `"Param"` when `_first(binding, PARAM_KEYS) is None`. 4. **`summary["unknown_slots"]` missed bindings without a valid `Param` (`build_report`)**: - Counting only `b["role"].startswith("unknown 0x")` skipped bindings with missing/malformed `Param` (`role == "unknown"`). Count both `"unknown"` and `"unknown 0x..."`. 5. **CLI empty/whitespace `--json`/`--csv` validation & atomic writes (`write_json`, `write_csv`, `main`)**: - Reject empty or whitespace-only `--json`/`--csv` paths via `parser.error(...)` instead of silently ignoring `""` or creating a whitespace-named file (`" "`). - Write JSON (`allow_nan=False`, trailing `"\n"`) and CSV (`newline=""`) atomically through sibling temp files with `file_mode.published_mode` and `replace_retry.replace`, preserving existing files on failure. - Accept optional `argv=None` in `main(argv=None)`. ## Claimed in the coordination issue as `CHARACTER-TEXTURES-CLASSIFICATION-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_character_textures.py -v`: **18/18 OK** (including 3 new regression tests). - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**. - `python3 -I scripts/check_no_game_data.py tools/character_textures.py tests/test_character_textures.py`: clean. - `python3 -m compileall -q tools/character_textures.py tests/test_character_textures.py`: clean. - Mutation check against unpatched `main:tools/character_textures.py`: all 3 new tests fail on `main` (`FAILED (failures=6, errors=1)`). - AI-assisted: yes - GPUs tested: none (CPU-only JSON/CSV texture classification tests on macOS; no GPU or game files needed)
copilot-pull-request-reviewer[bot] commented 2026-11-25 04:21:57 +00:00 (Migrated from github.com)

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

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

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T11:10:37Z.


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