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

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

@⁠IlyassRS3 on GitHub · 2026-11-25 06:55 UTC · original
IlyassRS3:fix/image-d16-probe-json-and-cli → main · +182 −33 · 2 files · 1 commits · open

Item ID: IMAGE-D16-PROBE-JSON-AND-CLI
Claim: #1608

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
**@⁠IlyassRS3** on GitHub · 2026-11-25 06:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1645) `IlyassRS3:fix/image-d16-probe-json-and-cli` → `main` · +182 −33 · 2 files · 1 commits · open Item ID: `IMAGE-D16-PROBE-JSON-AND-CLI` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:18 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 06:55 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 06:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1645#pullrequestreview-6053128845) · **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.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 08:16 UTC · original

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.

**@⁠whoalin1** on GitHub · 2026-11-25 08:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1645#issuecomment-7156823665) 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.
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/1645/head:github-bot/gh-1645'
git switch 'github-bot/gh-1645'

Merge

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