tools/shader_diff.py: deduplicate --ops and guard generate_program/run_suite bounds #2294

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/shader-diff-safety into main 2026-11-28 10:46:39 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 12:55:41 +00:00

Claimed in the coordination issue as: SHADER-DIFF-DEDUP-OPS-AND-EMPTY-INPUT-GUARDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192589921)

What and why

  • Deduplicate --ops preserving first-seen order in main() and run_suite() (tools/shader_diff.py) so duplicate op names do not alter generation weights or replay strings.
  • Validate n_ops >= 0 and non-empty matching templates upfront in generate_program(), raising ValueError.
  • Validate programs >= 1, max_ops >= 1, start >= 0, and limit >= 1 (when set) upfront in run_suite(), raising ValueError.
  • Add standard-library unit tests in tests/test_shader_diff_exit.py.

Tested

  • python -I tests/test_shader_diff_exit.py -v: 20 passed, 0 failed (detached upstream/main baseline with only the updated test file fails with 2 failures).
  • python -I tools/shader_diff.py --self-test: passed (canaries: match ok, mismatch detected, skip counted).
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tools/shader_diff.py tests/test_shader_diff_exit.py, and git diff --cached --check: passed.

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.
Claimed in the coordination issue as: SHADER-DIFF-DEDUP-OPS-AND-EMPTY-INPUT-GUARDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192589921) ### What and why - Deduplicate `--ops` preserving first-seen order in `main()` and `run_suite()` (`tools/shader_diff.py`) so duplicate op names do not alter generation weights or replay strings. - Validate `n_ops >= 0` and non-empty matching `templates` upfront in `generate_program()`, raising `ValueError`. - Validate `programs >= 1`, `max_ops >= 1`, `start >= 0`, and `limit >= 1` (when set) upfront in `run_suite()`, raising `ValueError`. - Add standard-library unit tests in `tests/test_shader_diff_exit.py`. ### Tested - `python -I tests/test_shader_diff_exit.py -v`: 20 passed, 0 failed (detached `upstream/main` baseline with only the updated test file fails with 2 failures). - `python -I tools/shader_diff.py --self-test`: passed (`canaries: match ok, mismatch detected, skip counted`). - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tools/shader_diff.py tests/test_shader_diff_exit.py`, and `git diff --cached --check`: passed. 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.
tiguan26 approved these changes 2026-11-27 04:41:02 +00:00
tiguan26 left a comment

Approving fca1c1b6c.

generate_program and run_suite validate their counts, an op list that matches no template is an error instead of an empty program, and duplicate --ops entries are dropped in order. Building the template list earlier does not touch the RNG, so seeded programs are unchanged.

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

Approving fca1c1b6c. `generate_program` and `run_suite` validate their counts, an op list that matches no template is an error instead of an empty program, and duplicate `--ops` entries are dropped in order. Building the template list earlier does not touch the RNG, so seeded programs are unchanged. Merged onto `main` `d1dff7949` in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_shader_diff_exit.py`: 20 passed (main: 18). AI-assisted (Claude Code, Claude Opus 5.5).
MSedgeMC reviewed 2026-11-27 15:25:56 +00:00
MSedgeMC left a comment
No description provided.
Verified on the PR branch: python3 -m unittest tests.test_shader_diff_exit -v -> 20 tests OK (the module is test_shader_diff_exit.py, not test_shader_diff.py), including the new --ops deduplication and generate_program/run_suite guards. Not approving yet: the branch is 446 commits behind current main, so a rebase is needed before the final diff can be reviewed.
sodove commented 2026-11-28 10:12:42 +00:00

#2294 | head fca1c1b6c034406ba6183ac441645a53310b1a7d | python3 -I tests/test_shader_diff_exit.py -v | red: 20 run, 2 failures | green: 20 passed | Red → green

The baseline retained duplicate operations and mishandled invalid generation bounds.

Pinned main 33db04a7010e81c40a7a6a15624525aa0c4a3a58, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

#2294 | head `fca1c1b6c034406ba6183ac441645a53310b1a7d` | `python3 -I tests/test_shader_diff_exit.py -v` | red: 20 run, 2 failures | green: 20 passed | **Red → green** The baseline retained duplicate operations and mishandled invalid generation bounds. Pinned main `33db04a7010e81c40a7a6a15624525aa0c4a3a58`, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7237628300).
DadaCap commented 2026-11-28 10:46:41 +00:00

Merged, thank you @kirigayakazima!

What it does: tools/shader_diff.py: deduplicate --ops and guard generate_program/run_suite bounds

How it was checked: sodove tested this PR at head fca1c1b6c on main 33db04a70: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (2 failures); with the PR, green (20 OK).

CI: the red jobs on this PR fail the same way on main, or on the older main it was built on (the cs_dpp_cmp.asm translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change.

Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head.

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

Merged, thank you @kirigayakazima! **What it does:** tools/shader_diff.py: deduplicate --ops and guard generate_program/run_suite bounds **How it was checked:** sodove tested this PR at head `fca1c1b6c` on main `33db04a70`: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (2 failures); with the PR, green (20 OK). **CI:** the red jobs on this PR fail the same way on main, or on the older main it was built on (the `cs_dpp_cmp.asm` translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change. Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No description provided.