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

Merged
leonida/mandy
quietfold merged 1 commit from fix/character-textures-classification-io into main 2026-11-28 11:10:40 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 04:21:42 +00:00

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)

## 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] reviewed 2026-11-25 04:21:57 +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 11:10:37 +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.