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

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

📋 Pull Request Information

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

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


📝 Commits (1)

  • 7330209 d16_format_probe: harden CLI parsing, atomic JSON write, and unknown-arch exit

📊 Changes

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

View changed files

📝 tests/test_d16_format_probe.py (+87 -0)
📝 tools/d16_format_probe.py (+88 -13)

📄 Description

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

🔄 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/1664 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/d16-format-probe-json-and-cli` --- ### 📝 Commits (1) - [`7330209`](https://github.com/ubiquitarianism/leonida/commit/733020975bee187f6822c0e5cf9fa6b2a3678124) d16_format_probe: harden CLI parsing, atomic JSON write, and unknown-arch exit ### 📊 Changes **2 files changed** (+175 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_d16_format_probe.py` (+87 -0) 📝 `tools/d16_format_probe.py` (+88 -13) </details> ### 📄 Description 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` --- <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#1678
No description provided.