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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2294
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/shader-diff-safety


📝 Commits (1)

  • fca1c1b tools/shader_diff.py: deduplicate --ops and validate generator/suite bounds

📊 Changes

2 files changed (+51 additions, -4 deletions)

View changed files

📝 tests/test_shader_diff_exit.py (+32 -0)
📝 tools/shader_diff.py (+19 -4)

📄 Description

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.

🔄 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/2294 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/shader-diff-safety` --- ### 📝 Commits (1) - [`fca1c1b`](https://github.com/ubiquitarianism/leonida/commit/fca1c1b6c034406ba6183ac441645a53310b1a7d) tools/shader_diff.py: deduplicate --ops and validate generator/suite bounds ### 📊 Changes **2 files changed** (+51 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_shader_diff_exit.py` (+32 -0) 📝 `tools/shader_diff.py` (+19 -4) </details> ### 📄 Description 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. --- <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#2297
No description provided.