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

Open
opened 2026-11-26 20:22:00 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1645
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/image-d16-probe-json-and-cli


📝 Commits (1)

  • 6e90622 image_d16_probe: harden --dims/--formats, atomic JSON writes, and result count/length guards

📊 Changes

2 files changed (+182 additions, -33 deletions)

View changed files

📝 tests/test_image_d16_probe.py (+70 -0)
📝 tools/image_d16_probe.py (+112 -33)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1645 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/image-d16-probe-json-and-cli` --- ### 📝 Commits (1) - [`6e90622`](https://github.com/ubiquitarianism/leonida/commit/6e90622f9c586695d0580352d156e9f55f516957) image_d16_probe: harden --dims/--formats, atomic JSON writes, and result count/length guards ### 📊 Changes **2 files changed** (+182 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_image_d16_probe.py` (+70 -0) 📝 `tools/image_d16_probe.py` (+112 -33) </details> ### 📄 Description 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1659
No description provided.