image_d16_probe: harden --dims/--formats, atomic JSON writes, and result count/length guards #1645

Merged
IlyassRS3 merged 1 commit from upstream-pr/1645 into main 2026-11-28 11:43:35 +00:00
IlyassRS3 commented 2026-11-25 06:55:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T06:55:32Z.


Item ID: IMAGE-D16-PROBE-JSON-AND-CLI
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155269092

Summary

Harden CLI parsing, JSON report writing, and harness result validation in tools/image_d16_probe.py:

  • --dims / --formats / --hw-arch guards: reject empty/trailing comma tokens (1d,, ,1d, 1d,,2d), trim whitespace and deduplicate repeated dims/formats in first-seen order so duplicate GPU kernels aren't launched, and reject empty/whitespace --hw-arch.
  • Upfront validate_json_path() & atomic write_json_report():
    • Resolve symlinks so symlinked directories/blockers are caught upfront and symlink targets are updated in place without replacing the symlink.
    • Check existing targets for writeability upfront (O_WRONLY), serialize with allow_nan=False and a trailing LF , write non-regular targets like /dev/null directly, and publish regular files atomically via tempfile.mkstemp + file_mode.published_mode + replace_retry.replace.
  • Harness guards:
    • Flag len(raw_results) != len(cases) and per-case word-count mismatches (len(got) != count * 4) as harness errors (exit 2) instead of silently truncating via zip() or crashing inside classify().
    • Catch ValueError from asm.family(oracle.arch) cleanly (exit 77).
  • Tests (tests/test_image_d16_probe.py): added 3 test methods covering malformed/duplicate --dims/--formats, empty --hw-arch, atomic/trailing-LF/NaN/symlink//dev/null writes, result count & word-length mismatches, and unknown arch family.

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU synthetic unit tests + FakeOracle on macOS; no GPU, AMD clang, or game data present)
  • python3 -W error -I tests/test_image_d16_probe.py -v: 23 passed, 2 skipped (AMD clang / GFX10 hardware absent)
  • Mutation check against unpatched main: ran=25 failures=2 errors=8 (skipped=2)
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/image_d16_probe.py tests/test_image_d16_probe.py: passed
  • python3 -m compileall -q tools/image_d16_probe.py tests/test_image_d16_probe.py: passed
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5486689436 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1645). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T06:55:32Z. --- Item ID: `IMAGE-D16-PROBE-JSON-AND-CLI` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155269092 ### Summary Harden CLI parsing, JSON report writing, and harness result validation in `tools/image_d16_probe.py`: - **`--dims` / `--formats` / `--hw-arch` guards**: reject empty/trailing comma tokens (`1d,`, `,1d`, `1d,,2d`), trim whitespace and deduplicate repeated dims/formats in first-seen order so duplicate GPU kernels aren't launched, and reject empty/whitespace `--hw-arch`. - **Upfront `validate_json_path()` & atomic `write_json_report()`**: - Resolve symlinks so symlinked directories/blockers are caught upfront and symlink targets are updated in place without replacing the symlink. - Check existing targets for writeability upfront (`O_WRONLY`), serialize with `allow_nan=False` and a trailing LF ` `, write non-regular targets like `/dev/null` directly, and publish regular files atomically via `tempfile.mkstemp` + `file_mode.published_mode` + `replace_retry.replace`. - **Harness guards**: - Flag `len(raw_results) != len(cases)` and per-case word-count mismatches (`len(got) != count * 4`) as harness errors (exit `2`) instead of silently truncating via `zip()` or crashing inside `classify()`. - Catch `ValueError` from `asm.family(oracle.arch)` cleanly (exit `77`). - **Tests (`tests/test_image_d16_probe.py`)**: added 3 test methods covering malformed/duplicate `--dims`/`--formats`, empty `--hw-arch`, atomic/trailing-LF/NaN/symlink/`/dev/null` writes, result count & word-length mismatches, and unknown arch family. ### Verification - AI-assisted: yes - GPUs tested: none (CPU synthetic unit tests + FakeOracle on macOS; no GPU, AMD clang, or game data present) - `python3 -W error -I tests/test_image_d16_probe.py -v`: 23 passed, 2 skipped (AMD clang / GFX10 hardware absent) - Mutation check against unpatched `main`: `ran=25 failures=2 errors=8 (skipped=2)` - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed - `python3 -I scripts/check_no_game_data.py tools/image_d16_probe.py tests/test_image_d16_probe.py`: passed - `python3 -m compileall -q tools/image_d16_probe.py tests/test_image_d16_probe.py`: passed
copilot-pull-request-reviewer[bot] commented 2026-11-25 06:55:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T06:55:46Z.

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:6053128845 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1645#pullrequestreview-6053128845). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T06:55:46Z. **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.
whoalin1 commented 2026-11-25 08:16:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T08:16:27Z.


Independent verification (Windows, Python 3.11.9 -I): diff reviewed — --dims/--formats token guards + dedup, empty --hw-arch, atomic JSON hardening, len(raw_results) != len(cases) and per-case want_words = count*4 harness guards, asm.family ValueError -> exit 77 — all present. test_image_d16_probe.py 25 tests OK (2 skips, matches body), --self-test ok, CLI probes reject malformed --dims/--formats/empty --hw-arch, compileall + line-endings + check_no_game_data clean. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156823665 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1645#issuecomment-7156823665). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T08:16:27Z. --- Independent verification (Windows, Python 3.11.9 `-I`): diff reviewed — `--dims/--formats` token guards + dedup, empty `--hw-arch`, atomic JSON hardening, `len(raw_results) != len(cases)` and per-case `want_words = count*4` harness guards, `asm.family` ValueError -> exit 77 — all present. `test_image_d16_probe.py` 25 tests OK (2 skips, matches body), `--self-test` ok, CLI probes reject malformed `--dims`/`--formats`/empty `--hw-arch`, compileall + line-endings + `check_no_game_data` clean. AI-assisted verification.
sodove commented 2026-11-28 11:27:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T11:27:24Z.


#1645 | head 6e90622f9c586695d0580352d156e9f55f516957 | python3 -I tests/test_image_d16_probe.py -v, py -3.12 -I tests/test_image_d16_probe.py -v | red: 25 run, 2 failures, 8 errors, 1 class skipped (Linux) / 26 run, 2 failures, 8 errors (Windows) | green: 25 passed, 1 class skipped (Linux) / 26 passed (Windows) | Red → green. Live Radeon case passed on both trees

The full file covers format/dimension handling, report guards and malformed results. The optional gfx1036 hardware control for every dimension ran and passed on both trees with the same Windows HIP device. The baseline failures were in other tests.

Copied the PR tests onto clean main 4a54aedcb6b66525e0c9f72a6ea10263337c9141 for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native Windows used Python 3.12.10. Windows HIP used AMD Radeon(TM) Graphics, gfx1036, driver 32.0.21045.29003. The WSL run skipped the optional native-hardware case. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238563203 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1645#issuecomment-7238563203). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T11:27:24Z. --- #1645 | head `6e90622f9c586695d0580352d156e9f55f516957` | `python3 -I tests/test_image_d16_probe.py -v`, `py -3.12 -I tests/test_image_d16_probe.py -v` | red: 25 run, 2 failures, 8 errors, 1 class skipped (Linux) / 26 run, 2 failures, 8 errors (Windows) | green: 25 passed, 1 class skipped (Linux) / 26 passed (Windows) | **Red → green. Live Radeon case passed on both trees** The full file covers format/dimension handling, report guards and malformed results. The optional gfx1036 hardware control for every dimension ran and passed on both trees with the same Windows HIP device. The baseline failures were in other tests. Copied the PR tests onto clean main `4a54aedcb6b66525e0c9f72a6ea10263337c9141` for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native Windows used Python 3.12.10. Windows HIP used AMD Radeon(TM) Graphics, gfx1036, driver 32.0.21045.29003. The WSL run skipped the optional native-hardware case. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238450840).
DadaCap commented 2026-11-28 11:43:37 +00:00 (Migrated from github.com)

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


Merged, thank you @IlyassRS3! This PR (image_d16_probe: harden --dims/--formats, atomic JSON writes, and result count/length guards) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238742212 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1645#issuecomment-7238742212). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:43:37Z. --- Merged, thank you @IlyassRS3! This PR (image_d16_probe: harden --dims/--formats, atomic JSON writes, and result count/length guards) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
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!1645
No description provided.