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

Merged
leonida/mandy
quietfold merged 1 commit from fix/d16-format-probe-json-and-cli into main 2026-11-28 14:48:06 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 07:34:34 +00:00

Item ID: D16-FORMAT-PROBE-JSON-AND-CLI (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155954875)

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
Item ID: `D16-FORMAT-PROBE-JSON-AND-CLI` (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155954875) ## 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`
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 07:34:43 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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.
zmasi commented 2026-11-28 10:47:22 +00:00

#1664 | head 733020975bee187f6822c0e5cf9fa6b2a3678124 (merged cleanly with main 95b2e6c67) | python -I tests/test_d16_format_probe.py | red on main: FAILED (failures=10, errors=1, skipped=2) (malformed --formats/--waves/--hw-arch/--json inputs not rejected, open_oracle called before blocked --json parent check, uncaught ValueError on unknown arch gfx900, and NaN JSON written) | green on PR+main: 27 tests OK (skipped=2) | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited validate_report_path, write_report (allow_nan=False, non-regular/device direct write, mkstemp + fsync + published_mode + replace_retry), --formats/--waves deduplication, and asm.family ValueError -> exit 77 in tools/d16_format_probe.py. Also passed tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), tests/test_runner_calls_all_tests.py (3 OK), and scripts/check_no_game_data.py.

#1664 | head 733020975bee187f6822c0e5cf9fa6b2a3678124 (merged cleanly with main 95b2e6c67) | `python -I tests/test_d16_format_probe.py` | red on main: `FAILED (failures=10, errors=1, skipped=2)` (malformed `--formats`/`--waves`/`--hw-arch`/`--json` inputs not rejected, `open_oracle` called before blocked `--json` parent check, uncaught `ValueError` on unknown arch `gfx900`, and `NaN` JSON written) | green on PR+main: `27 tests OK (skipped=2)` | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `validate_report_path`, `write_report` (`allow_nan=False`, non-regular/device direct write, `mkstemp` + `fsync` + `published_mode` + `replace_retry`), `--formats`/`--waves` deduplication, and `asm.family` `ValueError -> exit 77` in `tools/d16_format_probe.py`. Also passed `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), `tests/test_runner_calls_all_tests.py` (`3 OK`), and `scripts/check_no_game_data.py`.
MoonEyes commented 2026-11-28 14:48:03 +00:00

Red/green: pytest tests/test_d16_format_probe.py fails on main (11 failed, 22 passed, 2 skipped, 2 subtests passed) and passes on head 733020975bee merged with main (26 passed, 2 skipped, 10 subtests passed).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: `pytest tests/test_d16_format_probe.py` fails on main (11 failed, 22 passed, 2 skipped, 2 subtests passed) and passes on head 733020975bee merged with main (26 passed, 2 skipped, 10 subtests passed). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.