d16_format_probe: harden CLI parsing, atomic JSON write, and unknown-arch exit #1664

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

@⁠IlyassRS3 on GitHub · 2026-11-25 07:34 UTC · original
IlyassRS3:fix/d16-format-probe-json-and-cli → main · +175 −13 · 2 files · 1 commits · open

Item ID: D16-FORMAT-PROBE-JSON-AND-CLI (claimed in #1608)

Summary

  • CLI validation & deduplication (tools/d16_format_probe.py):
    • Reject empty/whitespace-only --hw-arch and --json values with argparse exit code 2.
    • Strip whitespace around --formats and --waves entries, reject empty/trailing-comma tokens (unorm8,, ,64), and deduplicate repeated formats/waves while preserving order so the GPU sweep does not execute duplicate work.
  • Upfront --json validation & atomic report writing:
    • Added validate_report_path() and called it before opening the hardware oracle so a blocked parent path (e.g. a regular file ancestor) fails fast with ERROR: cannot write ... (exit 2) without running the GPU sweep, while preserving the existing ap.error directory check.
    • Upgraded write_report() to serialize strictly (allow_nan=False) with a trailing , support non-regular targets like /dev/null, preserve symlink targets and existing file mode via file_mode.published_mode(), fsync temp files, and atomically replace via replace_retry.replace().
  • Unknown architecture handling:
    • Catch ValueError from asm.family(oracle.arch) inside the try/finally block so unknown architectures close the oracle cleanly and exit 77 instead of raising an unhandled traceback.
  • Regression tests (tests/test_d16_format_probe.py):
    • Added tests covering blocked --json parent fail-fast before opening the oracle, empty/malformed CLI tokens & deduplication & unknown-arch exit 77, and atomic write behavior (symlink/mode preservation, trailing LF, /dev/null, and NaN rejection without clobbering existing output).

Checklist & Verification

  • AI-assisted: yes
  • Game data included: none (python3 -I scripts/check_no_game_data.py tools/d16_format_probe.py tests/test_d16_format_probe.py passed)
  • GPUs tested: none (hostless macOS synthetic/unit test run; AMD GPU tests skipped cleanly)
  • Tests run:
    • python3 -W error -I tests/test_d16_format_probe.py: Ran 26 tests ... OK (skipped=2)
    • Mutation test (new tests/test_d16_format_probe.py against unpatched main tools/d16_format_probe.py): Ran 26 tests ... FAILED (failures=10, errors=1, skipped=2)
    • python3 -m compileall -q make_game.py tools tests: passed
    • python3 -I tests/test_text_write_line_endings.py: Ran 3 tests ... OK
**@⁠IlyassRS3** on GitHub · 2026-11-25 07:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1664) `IlyassRS3:fix/d16-format-probe-json-and-cli` → `main` · +175 −13 · 2 files · 1 commits · open Item ID: `D16-FORMAT-PROBE-JSON-AND-CLI` (claimed in https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ## Summary - **CLI validation & deduplication (`tools/d16_format_probe.py`)**: - Reject empty/whitespace-only `--hw-arch` and `--json` values with argparse exit code `2`. - Strip whitespace around `--formats` and `--waves` entries, reject empty/trailing-comma tokens (`unorm8,`, `,64`), and deduplicate repeated formats/waves while preserving order so the GPU sweep does not execute duplicate work. - **Upfront `--json` validation & atomic report writing**: - Added `validate_report_path()` and called it before opening the hardware oracle so a blocked parent path (e.g. a regular file ancestor) fails fast with `ERROR: cannot write ...` (exit `2`) without running the GPU sweep, while preserving the existing `ap.error` directory check. - Upgraded `write_report()` to serialize strictly (`allow_nan=False`) with a trailing ` `, support non-regular targets like `/dev/null`, preserve symlink targets and existing file mode via `file_mode.published_mode()`, fsync temp files, and atomically replace via `replace_retry.replace()`. - **Unknown architecture handling**: - Catch `ValueError` from `asm.family(oracle.arch)` inside the `try/finally` block so unknown architectures close the oracle cleanly and exit `77` instead of raising an unhandled traceback. - **Regression tests (`tests/test_d16_format_probe.py`)**: - Added tests covering blocked `--json` parent fail-fast before opening the oracle, empty/malformed CLI tokens & deduplication & unknown-arch exit `77`, and atomic write behavior (symlink/mode preservation, trailing LF, `/dev/null`, and `NaN` rejection without clobbering existing output). ## Checklist & Verification - **AI-assisted**: yes - **Game data included**: none (`python3 -I scripts/check_no_game_data.py tools/d16_format_probe.py tests/test_d16_format_probe.py` passed) - **GPUs tested**: none (hostless macOS synthetic/unit test run; AMD GPU tests skipped cleanly) - **Tests run**: - `python3 -W error -I tests/test_d16_format_probe.py`: `Ran 26 tests ... OK (skipped=2)` - Mutation test (new `tests/test_d16_format_probe.py` against unpatched `main` `tools/d16_format_probe.py`): `Ran 26 tests ... FAILED (failures=10, errors=1, skipped=2)` - `python3 -m compileall -q make_game.py tools tests`: passed - `python3 -I tests/test_text_write_line_endings.py`: `Ran 3 tests ... OK`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:57 +00:00
Author
Owner

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

Merge

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