[PR #1614] d16_image_probe: validate --json upfront, write reports atomically, and harden --formats/--waves (D16-IMAGE-PROBE-JSON-AND-CLI) #1628

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

📋 Pull Request Information

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

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


📝 Commits (1)

  • 40c66fd d16_image_probe: validate --json upfront, write reports atomically, and harden --formats/--waves

📊 Changes

2 files changed (+208 additions, -13 deletions)

View changed files

📝 tests/test_d16_image_probe.py (+94 -5)
📝 tools/d16_image_probe.py (+114 -8)

📄 Description

Item ID: D16-IMAGE-PROBE-JSON-AND-CLI (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches tools/d16_image_probe.py).

What changed

  • Validate --json upfront before opening the hardware oracle (tools/d16_image_probe.py, validate_json_path): reject empty/whitespace paths (previously --json "" was silently ignored and --json " " wrote a literal whitespace file), NUL bytes, directories / trailing separators, and non-directory parent ancestors with exit code 2 before launching any GPU sweep.
  • Write --json reports atomically and handle OSError cleanly (write_json_report): create missing parent directories, resolve symlinks to update targets in place, write non-regular targets (/dev/null) directly, check O_WRONLY on existing regular files before staging, stage with file_mode.published_mode + replace_retry.replace, enforce allow_nan=False and trailing \n, clean up staging files on failure, and return exit 2 instead of an unhandled traceback.
  • Harden --formats and --waves parsing (main): reject empty comma tokens (e.g. --formats "", --formats unorm8,, --waves 32,) with the right option name (previously --formats "" reported --frac must be in (0, 1)), strip whitespace around tokens, and deduplicate repeated formats/waves so --waves 32,32 does not run wave32 twice or emit spurious self-comparison waves_differ entries.
  • Synthetic regression tests (tests/test_d16_image_probe.py): 3 new tests plus expanded test_bad_arguments_are_a_usage_error covering all of the above (no game files, no GPU).

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU-only fake oracle tests on macOS; Kernels and OnHardware skipped without AMD clang / GFX10 GPU)
  • python3 -W error -I tests/test_d16_image_probe.py -v: 14 passed, 2 skipped
  • python3 -W error -I tests/test_text_write_line_endings.py: passed
  • python3 -I scripts/check_no_game_data.py tools/d16_image_probe.py tests/test_d16_image_probe.py: clean
  • python3 -m compileall -q tools/d16_image_probe.py tests/test_d16_image_probe.py: clean
  • Mutation test (Cli suite of tests/test_d16_image_probe.py against unpatched main:tools/d16_image_probe.py): 9 failures, 2 errors across the 5 CLI tests.

🔄 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/1614 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/d16-image-probe-json-and-cli` --- ### 📝 Commits (1) - [`40c66fd`](https://github.com/ubiquitarianism/leonida/commit/40c66fdd2f21a8c2d73e6513b53fd712c0208355) d16_image_probe: validate --json upfront, write reports atomically, and harden --formats/--waves ### 📊 Changes **2 files changed** (+208 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_d16_image_probe.py` (+94 -5) 📝 `tools/d16_image_probe.py` (+114 -8) </details> ### 📄 Description Item ID: `D16-IMAGE-PROBE-JSON-AND-CLI` (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches `tools/d16_image_probe.py`). ## What changed - **Validate `--json` upfront before opening the hardware oracle (`tools/d16_image_probe.py`, `validate_json_path`)**: reject empty/whitespace paths (previously `--json ""` was silently ignored and `--json " "` wrote a literal whitespace file), NUL bytes, directories / trailing separators, and non-directory parent ancestors with exit code `2` before launching any GPU sweep. - **Write `--json` reports atomically and handle `OSError` cleanly (`write_json_report`)**: create missing parent directories, resolve symlinks to update targets in place, write non-regular targets (`/dev/null`) directly, check `O_WRONLY` on existing regular files before staging, stage with `file_mode.published_mode` + `replace_retry.replace`, enforce `allow_nan=False` and trailing `\n`, clean up staging files on failure, and return exit `2` instead of an unhandled traceback. - **Harden `--formats` and `--waves` parsing (`main`)**: reject empty comma tokens (e.g. `--formats ""`, `--formats unorm8,`, `--waves 32,`) with the right option name (previously `--formats ""` reported `--frac must be in (0, 1)`), strip whitespace around tokens, and deduplicate repeated formats/waves so `--waves 32,32` does not run wave32 twice or emit spurious self-comparison `waves_differ` entries. - **Synthetic regression tests (`tests/test_d16_image_probe.py`)**: 3 new tests plus expanded `test_bad_arguments_are_a_usage_error` covering all of the above (no game files, no GPU). ## Verification - AI-assisted: yes - GPUs tested: none (CPU-only fake oracle tests on macOS; `Kernels` and `OnHardware` skipped without AMD clang / GFX10 GPU) - `python3 -W error -I tests/test_d16_image_probe.py -v`: **14 passed, 2 skipped** - `python3 -W error -I tests/test_text_write_line_endings.py`: passed - `python3 -I scripts/check_no_game_data.py tools/d16_image_probe.py tests/test_d16_image_probe.py`: clean - `python3 -m compileall -q tools/d16_image_probe.py tests/test_d16_image_probe.py`: clean - Mutation test (`Cli` suite of `tests/test_d16_image_probe.py` against unpatched `main:tools/d16_image_probe.py`): **9 failures, 2 errors** across the 5 CLI tests. --- <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#1628
No description provided.