[PR #1675] pknorm_probe: harden CLI parsing, hw oracle validation, and error lifecycle #1688

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

📋 Pull Request Information

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

Base: main ← Head: fix/pknorm-probe-cli-and-oracle


📝 Commits (1)

  • 64e7a1b pknorm_probe: harden CLI parsing, hw oracle validation, and error lifecycle

📊 Changes

2 files changed (+127 additions, -3 deletions)

View changed files

📝 tests/test_pknorm_probe.py (+100 -0)
📝 tools/pknorm_probe.py (+27 -3)

📄 Description

Item ID: PKNORM-PROBE-CLI-AND-ORACLE (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156255931)

Summary

  • Hardware oracle result validation (tools/pknorm_probe.py):
    • In run_hw(), validate that oracle.run() returns a list/tuple matching len(case_list) and that every non-string entry is a non-empty list/tuple whose first element is an int (not bool), preventing false passes on empty/short sweep outputs (zip() truncation) and uncaught IndexError/TypeError on malformed payloads.
  • Oracle exception handling & CLI validation:
    • Catch runner.Unavailable (exit 77) and RuntimeError (exit 2) raised during oracle.run() inside try ... finally: oracle.close().
    • Check string kernel errors before diffing.
    • Reject empty/whitespace --hw-arch and empty/trailing-comma --oracle tokens ("", "hw,", ",translator") with argparse exit code 2.
  • Regression tests (tests/test_pknorm_probe.py):
    • Added CliAndOracleTests covering malformed/empty CLI flags, empty/short/long/malformed oracle payloads, string rejection entries, runner.Unavailable -> exit 77, and RuntimeError -> exit 2, verifying oracle.close() on every path.

Checklist & Verification

  • AI-assisted: yes
  • Game data included: none (python3 -I scripts/check_no_game_data.py tools/pknorm_probe.py tests/test_pknorm_probe.py passed)
  • GPUs tested: none (hostless macOS synthetic/unit test run)
  • Tests run:
    • python3 -W error -I tests/test_pknorm_probe.py -v: Ran 6 tests ... OK
    • Mutation test (new tests/test_pknorm_probe.py against unpatched main tools/pknorm_probe.py): Ran 6 tests ... FAILED (failures=10, errors=4)
    • 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/1675 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/pknorm-probe-cli-and-oracle` --- ### 📝 Commits (1) - [`64e7a1b`](https://github.com/ubiquitarianism/leonida/commit/64e7a1ba2e72e62ea26a4344013f99bdd660aa2a) pknorm_probe: harden CLI parsing, hw oracle validation, and error lifecycle ### 📊 Changes **2 files changed** (+127 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_pknorm_probe.py` (+100 -0) 📝 `tools/pknorm_probe.py` (+27 -3) </details> ### 📄 Description Item ID: `PKNORM-PROBE-CLI-AND-ORACLE` (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156255931) ## Summary - **Hardware oracle result validation (`tools/pknorm_probe.py`)**: - In `run_hw()`, validate that `oracle.run()` returns a `list`/`tuple` matching `len(case_list)` and that every non-string entry is a non-empty `list`/`tuple` whose first element is an `int` (not `bool`), preventing false passes on empty/short sweep outputs (`zip()` truncation) and uncaught `IndexError`/`TypeError` on malformed payloads. - **Oracle exception handling & CLI validation**: - Catch `runner.Unavailable` (exit `77`) and `RuntimeError` (exit `2`) raised during `oracle.run()` inside `try ... finally: oracle.close()`. - Check string kernel errors before diffing. - Reject empty/whitespace `--hw-arch` and empty/trailing-comma `--oracle` tokens (`""`, `"hw,"`, `",translator"`) with argparse exit code `2`. - **Regression tests (`tests/test_pknorm_probe.py`)**: - Added `CliAndOracleTests` covering malformed/empty CLI flags, empty/short/long/malformed oracle payloads, string rejection entries, `runner.Unavailable` -> exit `77`, and `RuntimeError` -> exit `2`, verifying `oracle.close()` on every path. ## Checklist & Verification - **AI-assisted**: yes - **Game data included**: none (`python3 -I scripts/check_no_game_data.py tools/pknorm_probe.py tests/test_pknorm_probe.py` passed) - **GPUs tested**: none (hostless macOS synthetic/unit test run) - **Tests run**: - `python3 -W error -I tests/test_pknorm_probe.py -v`: `Ran 6 tests ... OK` - Mutation test (new `tests/test_pknorm_probe.py` against unpatched `main` `tools/pknorm_probe.py`): `Ran 6 tests ... FAILED (failures=10, errors=4)` - `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#1688
No description provided.