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

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

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

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.
**@⁠IlyassRS3** on GitHub · 2026-11-25 06:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1614) `IlyassRS3:fix/d16-image-probe-json-and-cli` → `main` · +208 −13 · 2 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:58:11 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 06:03 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:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1614#pullrequestreview-6052605554) · **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.
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/1614/head:github-bot/gh-1614'
git switch 'github-bot/gh-1614'

Merge

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