pk16_diff: restore globals, validate hardware oracle/shrink results and CLI options, and tighten RefError checks #1654

Merged
IlyassRS3 merged 1 commit from upstream-pr/1654 into main 2026-11-28 11:44:53 +00:00
IlyassRS3 commented 2026-11-25 07:18:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T07:18:14Z.


Item ID: PK16-DIFF-ORACLE-CLI-AND-REF
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155677593

Summary

  • Module state restoration (tools/pk16_diff.py): restore KNOWN and LITERALS in main()'s finally block (and handle --list-ops/--self-test before mutating them) so in-process runs do not leak flags.
  • Hardware oracle & shrink guards: add hw_run() validating oracle is not None and exact result-list length across both run_suite() and shrink check_fn (avoiding AttributeError / IndexError on empty or short oracle returns); validate 4-word tuples/lists in _diff(); catch transient Skip during final shrunk recheck and fall back to problem.
  • CLI validation: reject empty/whitespace --hw-arch, --build, and --work.
  • Reference validation: raise RefError instead of silent ignores or raw ValueError/IndexError/TypeError on invalid operands, non-SGPR/non-VGPR destinations, wrong source counts, mismatched op_sel/op_sel_hi lengths, op_sel_hi on non-packed OPS_16 ops, and clamp on ops without clamp support.
  • Tests (tests/test_pk16_diff.py): add 4 regression tests covering all of the above.

Verification

  • python3 -W error -I tests/test_pk16_diff.py -v: 20 passed, 0 failed (2.612s).
  • Mutation check against unpatched main: ran=20, failures=7, errors=6.
  • python3 -m compileall -q tools/pk16_diff.py tests/test_pk16_diff.py, python3 -I tests/test_text_write_line_endings.py, python3 -I scripts/check_no_game_data.py: all pass.

AI-assisted: yes
GPUs tested: none (CPU unit tests with stubbed hardware oracle and spirv_mini_interp; no game data)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5486953753 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1654). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T07:18:14Z. --- Item ID: `PK16-DIFF-ORACLE-CLI-AND-REF` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155677593 ## Summary - **Module state restoration (`tools/pk16_diff.py`)**: restore `KNOWN` and `LITERALS` in `main()`'s `finally` block (and handle `--list-ops`/`--self-test` before mutating them) so in-process runs do not leak flags. - **Hardware oracle & shrink guards**: add `hw_run()` validating `oracle is not None` and exact result-list length across both `run_suite()` and shrink `check_fn` (avoiding `AttributeError` / `IndexError` on empty or short oracle returns); validate 4-word tuples/lists in `_diff()`; catch transient `Skip` during final shrunk recheck and fall back to `problem`. - **CLI validation**: reject empty/whitespace `--hw-arch`, `--build`, and `--work`. - **Reference validation**: raise `RefError` instead of silent ignores or raw `ValueError`/`IndexError`/`TypeError` on invalid operands, non-SGPR/non-VGPR destinations, wrong source counts, mismatched `op_sel`/`op_sel_hi` lengths, `op_sel_hi` on non-packed `OPS_16` ops, and `clamp` on ops without clamp support. - **Tests (`tests/test_pk16_diff.py`)**: add 4 regression tests covering all of the above. ## Verification - `python3 -W error -I tests/test_pk16_diff.py -v`: **20 passed, 0 failed** (2.612s). - Mutation check against unpatched `main`: **ran=20, failures=7, errors=6**. - `python3 -m compileall -q tools/pk16_diff.py tests/test_pk16_diff.py`, `python3 -I tests/test_text_write_line_endings.py`, `python3 -I scripts/check_no_game_data.py`: all pass. AI-assisted: yes GPUs tested: none (CPU unit tests with stubbed hardware oracle and `spirv_mini_interp`; no game data)
copilot-pull-request-reviewer[bot] commented 2026-11-25 07:18:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T07:18:30Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6053359442 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1654#pullrequestreview-6053359442). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T07:18:30Z. **Review:** COMMENTED --- 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.
whoalin1 commented 2026-11-25 09:32:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T09:32:37Z.


Independent verification (Windows, Python 3.11.9 -I -W error): same restore-globals pattern confirmed (KNOWN/LITERALS finally-restored, mutation after oracle connect), hw_run/_diff guards, shrink Skip fallback, CLI empty-string rejection, RefError tightening incl. op_sel_hi rejected on OPS_16 and clamp-without-cl rejected. test_pk16_diff.py 20 OK (matches body); --self-test/bad-CLI(2)/hw-unavailable(77) all correct; compileall + line-endings + check_no_game_data clean. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7158471693 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1654#issuecomment-7158471693). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T09:32:37Z. --- Independent verification (Windows, Python 3.11.9 `-I -W error`): same restore-globals pattern confirmed (`KNOWN`/`LITERALS` finally-restored, mutation after oracle connect), `hw_run`/`_diff` guards, shrink Skip fallback, CLI empty-string rejection, RefError tightening incl. op_sel_hi rejected on OPS_16 and clamp-without-cl rejected. `test_pk16_diff.py` 20 OK (matches body); `--self-test`/bad-CLI(2)/hw-unavailable(77) all correct; compileall + line-endings + check_no_game_data clean. AI-assisted verification.
sodove commented 2026-11-28 11:27:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T11:27:38Z.


#1654 | head 7586cc137e10809b42af3bc601690432302298c6 | python3 -I tests/test_pk16_diff.py -v | red: 20 run, 7 failures, 6 errors | green: 20 passed | Red → green

The suite covers malformed results, CLI/reference checks and restoration of globals. The complete file passed after merging.

Copied the PR tests onto clean main 4a54aedcb6b66525e0c9f72a6ea10263337c9141 for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238565785 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1654#issuecomment-7238565785). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T11:27:38Z. --- #1654 | head `7586cc137e10809b42af3bc601690432302298c6` | `python3 -I tests/test_pk16_diff.py -v` | red: 20 run, 7 failures, 6 errors | green: 20 passed | **Red → green** The suite covers malformed results, CLI/reference checks and restoration of globals. The complete file passed after merging. Copied the PR tests onto clean main `4a54aedcb6b66525e0c9f72a6ea10263337c9141` for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238450840).
DadaCap commented 2026-11-28 11:44:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:44:55Z.


Merged, thank you @IlyassRS3! This PR (pk16_diff: restore globals, validate hardware oracle/shrink results and CLI options, and tighten RefError checks) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238756112 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1654#issuecomment-7238756112). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:44:55Z. --- Merged, thank you @IlyassRS3! This PR (pk16_diff: restore globals, validate hardware oracle/shrink results and CLI options, and tighten RefError checks) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1654
No description provided.