valu_fuzz: prevent oracle leak, validate CLI options upfront, and add stdlib tests #2270

Merged
kirigayakazima merged 1 commit from upstream-pr/2270 into main 2026-11-28 11:43:53 +00:00
kirigayakazima commented 2026-11-26 11:55:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T11:55:33Z.


Claimed in the coordination issue as: VALU-FUZZ-ORACLE-LEAK-CLI-VALIDATION-AND-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191306204)

What and why

tools/valu_fuzz.py previously:

  • Defined main() with no argv parameter and opened runner.open_oracle() before validating --show, while also omitting try/finally oracle cleanup across hw_family_skip_reason, --gfx10-word3, and show().
  • Accepted --keep and --negative-control under --model-only, and accepted empty --keep "" or a regular file path for --keep.
  • Called subprocess.run(..., text=True) in translate() and run_gpu() without encoding="utf-8", errors="replace", and read index.json without "utf-8-sig".

This validates --show, --keep, and --negative-control upfront before opening the hardware oracle, wraps all post-open oracle usage in one try/finally so oracle.close() always runs, uses UTF-8 (errors="replace" / utf-8-sig) in translate() and run_gpu(), and adds stdlib unittest CLI coverage in tests/test_valu_fuzz_cli.py.

Tested

  • python -I tests/test_valu_fuzz_cli.py -v (5 passed)
  • Detached upstream/main baseline negative control: failed with tests/test_valu_fuzz_cli.py before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5509568185 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2270). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T11:55:33Z. --- Claimed in the coordination issue as: VALU-FUZZ-ORACLE-LEAK-CLI-VALIDATION-AND-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191306204) ### What and why `tools/valu_fuzz.py` previously: - Defined `main()` with no `argv` parameter and opened `runner.open_oracle()` before validating `--show`, while also omitting `try/finally` oracle cleanup across `hw_family_skip_reason`, `--gfx10-word3`, and `show()`. - Accepted `--keep` and `--negative-control` under `--model-only`, and accepted empty `--keep ""` or a regular file path for `--keep`. - Called `subprocess.run(..., text=True)` in `translate()` and `run_gpu()` without `encoding="utf-8", errors="replace"`, and read `index.json` without `"utf-8-sig"`. This validates `--show`, `--keep`, and `--negative-control` upfront before opening the hardware oracle, wraps all post-open oracle usage in one `try/finally` so `oracle.close()` always runs, uses UTF-8 (`errors="replace"` / `utf-8-sig`) in `translate()` and `run_gpu()`, and adds stdlib `unittest` CLI coverage in `tests/test_valu_fuzz_cli.py`. ### Tested - `python -I tests/test_valu_fuzz_cli.py -v` (5 passed) - Detached `upstream/main` baseline negative control: failed with `tests/test_valu_fuzz_cli.py` before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
real-rusher commented 2026-11-26 12:23:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T12:23:26Z.


Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_valu_fuzz_cli.py: 5 tests OK. The same file against main's tool: 5 errors, so it fails on main and passes with the change. compileall clean.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7191939265 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2270#issuecomment-7191939265). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T12:23:26Z. --- Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_valu_fuzz_cli.py: 5 tests OK. The same file against main's tool: 5 errors, so it fails on main and passes with the change. compileall clean. AI-assisted: yes (Claude Code)
DeadlyChirp commented 2026-11-26 12:52:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-26T12:52:12Z.


Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

  • tests/test_valu_fuzz_cli.py: 5 passed.
  • The same tests against main code: 5 failed, so they catch what this PR fixes.

(AI-assisted test run; output checked by hand.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7192567802 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2270#issuecomment-7192567802). Originally posted by [DeadlyChirp](https://github.com/DeadlyChirp) on 2026-11-26T12:52:12Z. --- Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_valu_fuzz_cli.py`: 5 passed. - The same tests against main code: 5 failed, so they catch what this PR fixes. (AI-assisted test run; output checked by hand.)
tiguan26 commented 2026-11-27 04:37:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:37:46Z.

Review: APPROVED


Approving 2c0ed64ae.

The leak fix holds: the hardware oracle is now opened only after every argument check, including --show, and every exit after it (family skip, the GFX12 word-3 refusal, --show, --model-only, the runs) goes through the one finally that closes it; before, a bad --show returned with the oracle open. --keep/--negative-control with --model-only or without the hardware oracle are refused up front, and subprocess output is decoded as UTF-8.

Merged onto main d1dff7949 in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_valu_fuzz_cli.py: 5 passed (new). AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6083545778 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2270#pullrequestreview-6083545778). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T04:37:46Z. **Review:** APPROVED --- Approving 2c0ed64ae. The leak fix holds: the hardware oracle is now opened only after every argument check, including `--show`, and every exit after it (family skip, the GFX12 word-3 refusal, `--show`, `--model-only`, the runs) goes through the one `finally` that closes it; before, a bad `--show` returned with the oracle open. `--keep`/`--negative-control` with `--model-only` or without the hardware oracle are refused up front, and subprocess output is decoded as UTF-8. Merged onto `main` `d1dff7949` in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_valu_fuzz_cli.py`: 5 passed (new). AI-assisted (Claude Code, Claude Opus 5.5).
Tauwni commented 2026-11-27 15:37:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-27T15:37:06Z.


Tested 2c0ed64ae merged onto main ec91d695c on a Mac: Apple M3, macOS 26.5.1. No game files.

  • tests/test_valu_fuzz_cli.py: OK.
  • The fuzzer itself, --programs 40 --seed 1 --wave 32, on main and with this PR:
Driver family main this PR
MoltenVK 1.4.2 f16 39/40 39/40
MoltenVK 1.4.2 mem 40/40 40/40
KosmicKrisp (Mesa 26.3.1) f16 40/40 40/40
KosmicKrisp (Mesa 26.3.1) mem 40/40 40/40

The one MoltenVK f16 mismatch is the known -0 product on that driver, and it is the same on both sides. The GPU suite on both drivers is identical to main too.

Evidence: MEASURED, 1 run each.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7222276365 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2270#issuecomment-7222276365). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-27T15:37:06Z. --- Tested `2c0ed64ae` merged onto `main` `ec91d695c` on a Mac: Apple M3, macOS 26.5.1. No game files. - `tests/test_valu_fuzz_cli.py`: OK. - The fuzzer itself, `--programs 40 --seed 1 --wave 32`, on `main` and with this PR: | Driver | family | `main` | this PR | |---|---|---|---| | MoltenVK 1.4.2 | f16 | 39/40 | 39/40 | | MoltenVK 1.4.2 | mem | 40/40 | 40/40 | | KosmicKrisp (Mesa 26.3.1) | f16 | 40/40 | 40/40 | | KosmicKrisp (Mesa 26.3.1) | mem | 40/40 | 40/40 | The one MoltenVK f16 mismatch is the known -0 product on that driver, and it is the same on both sides. The GPU suite on both drivers is identical to `main` too. Evidence: MEASURED, 1 run each. AI-assisted (Claude Code, Claude Opus 5.5).
sodove commented 2026-11-28 11:28:15 +00:00 (Migrated from github.com)

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


#2270 | head 2c0ed64ae44d81bfab40cb9c9438fb75f12bca1a | python3 -I tests/test_valu_fuzz_cli.py -v, py -3.12 -I tests/test_valu_fuzz_cli.py -v | red: 5 run, 5 errors (Linux) / 5 run, 5 errors (Windows) | green: 5 passed (Linux) / 5 passed (Windows) | Red → green

All five tests errored on main and passed after the merge on both Linux and Windows. GPU launcher calls in this file are mocked. The model-only case exercised the actual CLI path. This reruns the earlier check against the current batch base.

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. Native Windows used Python 3.12.10. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238572466 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2270#issuecomment-7238572466). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T11:28:15Z. --- #2270 | head `2c0ed64ae44d81bfab40cb9c9438fb75f12bca1a` | `python3 -I tests/test_valu_fuzz_cli.py -v`, `py -3.12 -I tests/test_valu_fuzz_cli.py -v` | red: 5 run, 5 errors (Linux) / 5 run, 5 errors (Windows) | green: 5 passed (Linux) / 5 passed (Windows) | **Red → green** All five tests errored on main and passed after the merge on both Linux and Windows. GPU launcher calls in this file are mocked. The model-only case exercised the actual CLI path. This reruns the earlier check against the current batch base. 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. Native Windows used Python 3.12.10. 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:43:55 +00:00 (Migrated from github.com)

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


Merged, thank you @kirigayakazima! This PR (valu_fuzz: prevent oracle leak, validate CLI options upfront, and add stdlib tests) 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:7238745601 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2270#issuecomment-7238745601). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:43:55Z. --- Merged, thank you @kirigayakazima! This PR (valu_fuzz: prevent oracle leak, validate CLI options upfront, and add stdlib tests) 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!2270
No description provided.