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

Open
github-bot wants to merge 1 commit from github-bot/gh-2280 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-26 12:28 UTC · original
kirigayakazima:fix/spirv-stubs-safety → main · +50 −1 · 2 files · 1 commits · open

Claimed in the coordination issue as: SPIRV-STUBS-CLI-RECURSION-AND-TARGET-DIR-GUARD (#1608)

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.
**@⁠kirigayakazima** on GitHub · 2026-11-26 12:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2280) `kirigayakazima:fix/spirv-stubs-safety` → `main` · +50 −1 · 2 files · 1 commits · open Claimed in the coordination issue as: SPIRV-STUBS-CLI-RECURSION-AND-TARGET-DIR-GUARD (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:29:55 +00:00
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-26 12:51 UTC · original

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.)

**@⁠DeadlyChirp** on GitHub · 2026-11-26 12:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2280#issuecomment-7192557768) 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.)
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:39 UTC · original · approved these changes

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).

**@⁠tiguan26** on GitHub · 2026-11-27 04:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2280#pullrequestreview-6083555338) · **approved these changes** 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2280/head:github-bot/gh-2280'
git switch 'github-bot/gh-2280'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2280'
git switch 'github-bot/gh-2280'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2280'
git switch 'github-bot/gh-2280'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2280'
git switch 'main'
git merge --squash 'github-bot/gh-2280'
git switch 'main'
git merge --ff-only 'github-bot/gh-2280'
git switch 'main'
git merge 'github-bot/gh-2280'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.