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

Merged
IlyassRS3 merged 1 commit from upstream-pr/1614 into main 2026-11-28 10:39:51 +00:00
IlyassRS3 commented 2026-11-25 06:02:49 +00:00 (Migrated from github.com)

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


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5486090109 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1614). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T06:02:49Z. --- 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.
copilot-pull-request-reviewer[bot] commented 2026-11-25 06:03:03 +00:00 (Migrated from github.com)

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

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:6052605554 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1614#pullrequestreview-6052605554). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T06:03:03Z. **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.
MoonEyes commented 2026-11-28 10:39:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:39:43Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 18 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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238039614 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1614#issuecomment-7238039614). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:39:43Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 18 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 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!1614
No description provided.