shader: harden spirv_address_window CLI guards and add CLI suite #2656

Merged
Ammmae0x merged 1 commit from upstream-pr/2664 into main 2026-11-26 02:51:05 +00:00
Ammmae0x commented 2026-11-26 01:32:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T01:32:25Z.


Change

Harden CLI argument and path validation in tools/spirv_address_window.py and add a pure-Python mocked-subprocess CLI test suite (tests/spirv_address_window_cli_check.py), registered in CMakeLists.txt as shader_spirv_address_window_cli_check.

  • Validate upfront in _validate_args() that source exists and is a regular file (not a directory), output is not a symlink, directory, same path/hardlink as source, or under a non-directory parent/ancestor, and --assembler / --validator are non-empty stripped strings.
  • Pass the validated, stripped tool names to subprocess.run() while preserving atomic TemporaryDirectory + Path.replace() output publishing and clean exit code 1 with zero raw tracebacks.
  • Preserve existing lowering behavior and tests/spirv_address_window_check.py.

Verification

Tested on commit 1a876e12 (based on upstream/main f06646ba) on Windows using out/pe-env/Scripts/python.exe -B:

  • out\pe-env\Scripts\python.exe -B tests\spirv_address_window_check.py -> exit 0 (spirv_address_window: unit lowering, composed passes, and CLI error handling passed).
  • out\pe-env\Scripts\python.exe -B tests\spirv_address_window_cli_check.py -> exit 0 (7/7 tests OK, 0 skips: atomic nested write/overwrite, zero leftover temp dirs, live & dangling symlink guards, missing/dir/bad-UTF8 source, output dir/file-parent/samefile/hardlink guards, empty/whitespace --assembler/--validator, mocked CalledProcessError/FileNotFoundError/TimeoutExpired/Path.replace cleanup, and Python 3.14-safe argparse checks).
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py -> exit 0 (form coverage checks passed).
  • out\pe-env\Scripts\python.exe -B tests\docs_links_check.py -> exit 0 (19 Markdown files, 510 links).
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> exit 0 (no bidirectional controls).
  • Negative-control spot mutations (3/3 killed by tests/spirv_address_window_cli_check.py): disabling args.output.is_symlink(), disabling empty --validator check, and disabling non-directory output parent check.

Evidence and follow-up

  • Pure-Python test suite uses existing public repository fixture tests/spirv_window/subtract.spvasm (MIT License) with mocked subprocess.run so it runs offline without external spirv-as / spirv-val binaries.
  • No external GPU hardware or SPIRV-Tools run was required for this CLI guard and mocked-subprocess suite.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6617465835 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2664). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T01:32:25Z. --- ## Change Harden CLI argument and path validation in `tools/spirv_address_window.py` and add a pure-Python mocked-subprocess CLI test suite (`tests/spirv_address_window_cli_check.py`), registered in `CMakeLists.txt` as `shader_spirv_address_window_cli_check`. - Validate upfront in `_validate_args()` that `source` exists and is a regular file (not a directory), `output` is not a symlink, directory, same path/hardlink as `source`, or under a non-directory parent/ancestor, and `--assembler` / `--validator` are non-empty stripped strings. - Pass the validated, stripped tool names to `subprocess.run()` while preserving atomic `TemporaryDirectory` + `Path.replace()` output publishing and clean exit code `1` with zero raw tracebacks. - Preserve existing lowering behavior and `tests/spirv_address_window_check.py`. ## Verification Tested on commit `1a876e12` (based on `upstream/main` `f06646ba`) on Windows using `out/pe-env/Scripts/python.exe -B`: - `out\pe-env\Scripts\python.exe -B tests\spirv_address_window_check.py` -> exit 0 (`spirv_address_window: unit lowering, composed passes, and CLI error handling passed`). - `out\pe-env\Scripts\python.exe -B tests\spirv_address_window_cli_check.py` -> exit 0 (7/7 tests OK, 0 skips: atomic nested write/overwrite, zero leftover temp dirs, live & dangling symlink guards, missing/dir/bad-UTF8 source, output dir/file-parent/samefile/hardlink guards, empty/whitespace `--assembler`/`--validator`, mocked `CalledProcessError`/`FileNotFoundError`/`TimeoutExpired`/`Path.replace` cleanup, and Python 3.14-safe argparse checks). - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py` -> exit 0 (`form coverage checks passed`). - `out\pe-env\Scripts\python.exe -B tests\docs_links_check.py` -> exit 0 (19 Markdown files, 510 links). - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> exit 0 (no bidirectional controls). - Negative-control spot mutations (3/3 killed by `tests/spirv_address_window_cli_check.py`): disabling `args.output.is_symlink()`, disabling empty `--validator` check, and disabling non-directory output parent check. ## Evidence and follow-up - Pure-Python test suite uses existing public repository fixture `tests/spirv_window/subtract.spvasm` (MIT License) with mocked `subprocess.run` so it runs offline without external `spirv-as` / `spirv-val` binaries. - No external GPU hardware or SPIRV-Tools run was required for this CLI guard and mocked-subprocess suite. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
tedin7 commented 2026-11-26 02:05:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T01:36:38Z.

Review: COMMENTED


Review of head 1a876e12 against origin/main. No blocking findings.

  • _validate_args moves the CLI guards into one place: same-path, directory/missing/non-regular source, symlink or directory output, non-directory output parent, blank --assembler / --validator. Stripped values are the ones passed to subprocess.run. Looks correct.
  • The new suite tests/spirv_address_window_cli_check.py (7 tests) is registered in CMake as shader_spirv_address_window_cli_check next to the sibling spirv_address_window_check.
  • No other open PR covers this slice. #2374 (merged) touched the same CLI earlier; this builds on it.

Commands run in a worktree on this head:

  • python3 -B tests/spirv_address_window_cli_check.py -> 7 tests OK
  • python3 tests/docs_links_check.py -> OK
  • python3 tests/bidi_controls_check.py -> OK
  • git diff --check origin/main...HEAD -> clean
  • Mutation: replacing the blank-assembler check with if False: -> 3 failures
  • Mutation: replacing the output-symlink check with if False: -> 2 failures

Python-only change; Windows checks are not expected to be affected.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067385284 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2664#pullrequestreview-6067385284). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T01:36:38Z. **Review:** COMMENTED --- Review of head 1a876e12 against origin/main. No blocking findings. - `_validate_args` moves the CLI guards into one place: same-path, directory/missing/non-regular source, symlink or directory output, non-directory output parent, blank `--assembler` / `--validator`. Stripped values are the ones passed to `subprocess.run`. Looks correct. - The new suite `tests/spirv_address_window_cli_check.py` (7 tests) is registered in CMake as `shader_spirv_address_window_cli_check` next to the sibling `spirv_address_window_check`. - No other open PR covers this slice. #2374 (merged) touched the same CLI earlier; this builds on it. Commands run in a worktree on this head: - `python3 -B tests/spirv_address_window_cli_check.py` -> 7 tests OK - `python3 tests/docs_links_check.py` -> OK - `python3 tests/bidi_controls_check.py` -> OK - `git diff --check origin/main...HEAD` -> clean - Mutation: replacing the blank-assembler check with `if False:` -> 3 failures - Mutation: replacing the output-symlink check with `if False:` -> 2 failures Python-only change; Windows checks are not expected to be affected. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 03:03:04 +00:00
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
R0Y00/Xbox2Windows!2656
No description provided.