tools/spirv_stubs.py: preflight stub targets and harden CLI parsing #2280

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/spirv-stubs-safety into main 2026-11-28 15:08:53 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 12:28:10 +00:00

Claimed in the coordination issue as: SPIRV-STUBS-CLI-RECURSION-AND-TARGET-DIR-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191999362)

What and why

  • Preflight <spirv dir>/stubs (not a non-directory file) and every planned <stub>.spv target path (not a pre-existing directory) upfront in generate_for_index() (tools/spirv_stubs.py) before creating directories or writing any stub so a partial stub set is never emitted on collision.
  • Reject unknown option flags (-*) and blank <spirv dir> arguments with clear errors in main(argv=None).
  • Catch RecursionError alongside (OSError, ValueError) when calling json.load() on deeply nested index.json inputs.
  • Add unit tests in tests/test_spirv_stubs.py covering unknown flags, blank arguments, RecursionError handling, pre-existing target directory collision aborting before writing other stubs, and non-directory stubs path rejection.

Tested

  • python -I tests/test_spirv_stubs.py -v: 19 tests (18 passed, 1 skipped on Windows: test_rebuild_preserves_existing_mode, POSIX-only). Detached upstream/main baseline with the updated test file fails with 4 failures and 3 errors.
  • 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/spirv_stubs.py tests/test_spirv_stubs.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: SPIRV-STUBS-CLI-RECURSION-AND-TARGET-DIR-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191999362) ### What and why - Preflight `<spirv dir>/stubs` (not a non-directory file) and every planned `<stub>.spv` target path (not a pre-existing directory) upfront in `generate_for_index()` (`tools/spirv_stubs.py`) before creating directories or writing any stub so a partial stub set is never emitted on collision. - Reject unknown option flags (`-*`) and blank `<spirv dir>` arguments with clear errors in `main(argv=None)`. - Catch `RecursionError` alongside `(OSError, ValueError)` when calling `json.load()` on deeply nested `index.json` inputs. - Add unit tests in `tests/test_spirv_stubs.py` covering unknown flags, blank arguments, `RecursionError` handling, pre-existing target directory collision aborting before writing other stubs, and non-directory `stubs` path rejection. ### Tested - `python -I tests/test_spirv_stubs.py -v`: 19 tests (18 passed, 1 skipped on Windows: `test_rebuild_preserves_existing_mode`, POSIX-only). Detached `upstream/main` baseline with the updated test file fails with 4 failures and 3 errors. - `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/spirv_stubs.py tests/test_spirv_stubs.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.
DeadlyChirp commented 2026-11-26 12:51:44 +00:00

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

  • tests/test_spirv_stubs.py: 18 passed, 1 skipped (POSIX file mode), 20 subtests passed (main: 14 passed).

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

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_spirv_stubs.py`: 18 passed, 1 skipped (POSIX file mode), 20 subtests passed (main: 14 passed). (AI-assisted test run; output checked by hand.)
tiguan26 approved these changes 2026-11-27 04:39:08 +00:00
tiguan26 left a comment

Approving fcedc33eb.

The stubs folder and every stub target are checked before anything is written (a directory where a stub goes is an error up front), and a leading - or blank folder argument is refused.

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_spirv_stubs.py: 18 passed, 1 skipped (main: 14). AI-assisted (Claude Code, Claude Opus 5.5).

Approving fcedc33eb. The stubs folder and every stub target are checked before anything is written (a directory where a stub goes is an error up front), and a leading `-` or blank folder argument is refused. 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_spirv_stubs.py`: 18 passed, 1 skipped (main: 14). AI-assisted (Claude Code, Claude Opus 5.5).
MoonEyes commented 2026-11-28 15:08:50 +00:00

Red/green: classified READY by oreo-lot3 (red on main b1619e0a3, green on head merged with main); head fcedc33eb082 unchanged since 2026-11-26, before that run.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: classified READY by oreo-lot3 (red on main b1619e0a3, green on head merged with main); head fcedc33eb082 unchanged since 2026-11-26, before that run. Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.