Scripts: harden bvhb_shaders CLI argument handling, validation, and test coverage #1858

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

@⁠heditrigui on GitHub · 2026-11-24 21:58 UTC · original
heditrigui:scripts/bvhb-shaders-cli-hardening → main · +175 −27 · 2 files · 1 commits · open

Summary

Hardens CLI argument handling and validation in scripts/re/bvhb_shaders.py and expands unit test coverage in scripts/test_bvhb_shaders.py:

  • Adds -h and --help CLI option support with usage docstrings and clean exit code 0.
  • Rejects missing arguments with usage instructions and exit code 2.
  • Handles missing or unreadable files cleanly (reports error: file not found: '<dll_path>' on stderr and exits code 1) instead of crashing with unhandled Python exceptions.
  • Guards against truncated DXBC headers and invalid chunk offsets during parsing.
  • Modularizes shader extraction into reusable extract_shaders(dll_bytes, out_dir=None) and main(argv=None, out=None) functions so the module can be cleanly imported without executing top-level logic.
  • Expands scripts/test_bvhb_shaders.py from 1 to 7 tests covering CLI argument flags, exit codes, missing files, shaders without RTS0 root signatures, and direct Python API extraction.

Tested

  • python -m unittest scripts/test_bvhb_shaders.py (7 passed in 0.37s).
  • python -m pytest scripts/ (22 passed in 0.74s).
  • Validated with scripts/pr_check.py --local.

Not tested

  • Retail game smoke execution (scripts/ tools are non-runtime code).

AI use

  • Antigravity (Gemini 3.8 Flash (High))
**@⁠heditrigui** on GitHub · 2026-11-24 21:58 UTC · [original](https://github.com/xcl-dev/xcl/pull/1858) `heditrigui:scripts/bvhb-shaders-cli-hardening` → `main` · +175 −27 · 2 files · 1 commits · open ### Summary Hardens CLI argument handling and validation in `scripts/re/bvhb_shaders.py` and expands unit test coverage in `scripts/test_bvhb_shaders.py`: - Adds `-h` and `--help` CLI option support with usage docstrings and clean exit code 0. - Rejects missing arguments with usage instructions and exit code 2. - Handles missing or unreadable files cleanly (reports `error: file not found: '<dll_path>'` on stderr and exits code 1) instead of crashing with unhandled Python exceptions. - Guards against truncated DXBC headers and invalid chunk offsets during parsing. - Modularizes shader extraction into reusable `extract_shaders(dll_bytes, out_dir=None)` and `main(argv=None, out=None)` functions so the module can be cleanly imported without executing top-level logic. - Expands `scripts/test_bvhb_shaders.py` from 1 to 7 tests covering CLI argument flags, exit codes, missing files, shaders without RTS0 root signatures, and direct Python API extraction. **Tested** - `python -m unittest scripts/test_bvhb_shaders.py` (7 passed in 0.37s). - `python -m pytest scripts/` (22 passed in 0.74s). - Validated with `scripts/pr_check.py --local`. **Not tested** - Retail game smoke execution (`scripts/` tools are non-runtime code). **AI use** - Antigravity (Gemini 3.8 Flash (High))
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:28 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 22:36 UTC · original

Tested exact head ebf6f96, script tests only, since this PR has no test report yet.

Tested

  • Windows 11 Home 26300, Python 3.14.3 with pytest 9.0.3, Windows PowerShell 5.1.26100.9818 (no PowerShell 7 here).
  • python -m pytest scripts/test_bvhb_shaders.py at the head: 7 passed, 2 subtests passed.
  • The PR's test file against current main's script (689f2db): does not get to run: collection fails with FileNotFoundError: ... '-q', because main's bvhb_shaders.py reads sys.argv at import time (which this PR changes).
  • This PR and #1759 (also open, also bvhb_shaders) conflict: git merge-tree of the two heads reports conflicts in scripts/re/bvhb_shaders.py and scripts/test_bvhb_shaders.py, so whichever lands second needs a rebase.

Not tested

  • PowerShell 7, the CI workflow itself, a game (no runtime code changed).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 22:36 UTC · [original](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7146442354) Tested exact head `ebf6f96`, script tests only, since this PR has no test report yet. **Tested** - Windows 11 Home 26300, Python 3.14.3 with pytest 9.0.3, Windows PowerShell 5.1.26100.9818 (no PowerShell 7 here). - `python -m pytest scripts/test_bvhb_shaders.py` at the head: 7 passed, 2 subtests passed. - The PR's test file against current main's script (`689f2db`): does not get to run: collection fails with `FileNotFoundError: ... '-q'`, because main's `bvhb_shaders.py` reads `sys.argv` at import time (which this PR changes). - This PR and #1759 (also open, also `bvhb_shaders`) conflict: `git merge-tree` of the two heads reports conflicts in `scripts/re/bvhb_shaders.py` and `scripts/test_bvhb_shaders.py`, so whichever lands second needs a rebase. **Not tested** - PowerShell 7, the CI workflow itself, a game (no runtime code changed). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 01:27 UTC · original

Tested

Clean checkout of ebf6f96c60414ca63bf22792a7ff92ad697462ac on Windows 11 Enterprise Evaluation 25H2 (build 26200.9974), AMD Ryzen 7 3800X, portable CPython 3.13.7 x64. This adds native Windows path and byte-for-byte extraction coverage to the earlier Python 3.14.3 pytest report.

I compiled a one-function synthetic pixel shader with the Windows SDK 10.0.26100.0 x64 fxc.exe /nologo /T ps_5_0 /E main /Fo fixture.dxbc fixture.hlsl and embedded the resulting 452-byte DXBC after a 16-byte prefix in a scratch wrapper. The working directory, wrapper path, and explicit output path contained spaces and Unicode (é, 日).

From the scratch working directory, with $python pointing to the portable executable and $script to the checkout’s scripts/re/bvhb_shaders.py, I ran these seven checks with stdout and stderr captured through pipes.

  • & $python -B $script -h and & $python -B $script --help each exited 0 and printed usage to stdout.
  • & $python -B $script exited 2 and printed usage to stdout.
  • & $python -B $script 'absent café shader.dll' and & $python -B $script $missingAbsolute each exited 1 with a file-not-found diagnostic on stderr and empty stdout. Redirected cp1252 stderr preserved é and escaped 日 in the absolute path as literal \u65e5.
  • & $python -B $script $source $output and & $python -B $script $source each exited 0 and reported one container at 0x10 with RS: -. Both the explicit Unicode directory and the default bvhb_shaders directory contained exactly one 00.dxbc, byte-identical to the 452-byte compiler output.

7 passed, 0 failed, 0 ignored, 0 skipped.

Not tested

Coverage was limited to the Python CLI with a valid synthetic shader and missing-path diagnostics. Cargo, GPU execution, and retail assets were outside this run.

AI use

Codex (gpt-6.2-sol) ran the checks and wrote this report.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 01:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7149573376) **Tested** Clean checkout of `ebf6f96c60414ca63bf22792a7ff92ad697462ac` on Windows 11 Enterprise Evaluation 25H2 (build 26200.9974), AMD Ryzen 7 3800X, portable CPython 3.13.7 x64. This adds native Windows path and byte-for-byte extraction coverage to the earlier Python 3.14.3 pytest report. I compiled a one-function synthetic pixel shader with the Windows SDK 10.0.26100.0 x64 `fxc.exe /nologo /T ps_5_0 /E main /Fo fixture.dxbc fixture.hlsl` and embedded the resulting 452-byte DXBC after a 16-byte prefix in a scratch wrapper. The working directory, wrapper path, and explicit output path contained spaces and Unicode (`é`, `日`). From the scratch working directory, with `$python` pointing to the portable executable and `$script` to the checkout’s `scripts/re/bvhb_shaders.py`, I ran these seven checks with stdout and stderr captured through pipes. - `& $python -B $script -h` and `& $python -B $script --help` each exited 0 and printed usage to stdout. - `& $python -B $script` exited 2 and printed usage to stdout. - `& $python -B $script 'absent café shader.dll'` and `& $python -B $script $missingAbsolute` each exited 1 with a file-not-found diagnostic on stderr and empty stdout. Redirected cp1252 stderr preserved `é` and escaped `日` in the absolute path as literal `\u65e5`. - `& $python -B $script $source $output` and `& $python -B $script $source` each exited 0 and reported one container at `0x10` with `RS: -`. Both the explicit Unicode directory and the default `bvhb_shaders` directory contained exactly one `00.dxbc`, byte-identical to the 452-byte compiler output. **7 passed, 0 failed, 0 ignored, 0 skipped.** **Not tested** Coverage was limited to the Python CLI with a valid synthetic shader and missing-path diagnostics. Cargo, GPU execution, and retail assets were outside this run. **AI use** Codex (`gpt-6.2-sol`) ran the checks and wrote this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 01:28 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 01:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7149593957) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-26 04:31 UTC · original · edited 2026-11-26 04:38 UTC

Tested ebf6f96c60414ca63bf22792a7ff92ad697462ac. The original #1759 patch does not apply directly to either scripts/re/bvhb_shaders.py or its test file here. Candidate on this PR's head carries over the register-space formatting and the ASCII spelling for unbounded ranges. It keeps this PR's extraction API and CLI tests.

I compiled two root signatures with Windows d3dcompiler_47.dll (rootsig_1_0 and rootsig_1_1). Each used constants at b1/space2, a CBV at b2/space3 and a table with both finite and unbounded SRV ranges. I put the two DXBC containers in both orders and ran python -B scripts/re/bvhb_shaders.py <input> <out-dir> with redirected UTF-8 and strict CP1252 output.

On this PR, UTF-8 extracted both files but omitted the spaces. Under CP1252 each order stopped after writing the first file. On the candidate all four runs exited 0, both output files were byte-identical to the compiler output, and all summaries showed the expected spaces and counts.

The seven focused tests passed on the original head. On the candidate, python -B -m unittest discover -s scripts -p "test_*.py" passed all 24 tests with no skips. Windows build 26100, i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) ported the formatting and ran the tests. No game files, GPU execution or Rust build.

**@⁠RavenCurseBurg** on GitHub · 2026-11-26 04:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7182668263) · edited 2026-11-26 04:38 UTC Tested `ebf6f96c60414ca63bf22792a7ff92ad697462ac`. The original #1759 patch does not apply directly to either `scripts/re/bvhb_shaders.py` or its test file here. [Candidate on this PR's head](https://github.com/RavenCurseBurg/xcl/commit/35e823bc2d55624786f1a71f332ea2e9b84cf634) carries over the register-space formatting and the ASCII spelling for unbounded ranges. It keeps this PR's extraction API and CLI tests. I compiled two root signatures with Windows `d3dcompiler_47.dll` (`rootsig_1_0` and `rootsig_1_1`). Each used constants at b1/space2, a CBV at b2/space3 and a table with both finite and unbounded SRV ranges. I put the two DXBC containers in both orders and ran `python -B scripts/re/bvhb_shaders.py <input> <out-dir>` with redirected UTF-8 and strict CP1252 output. On this PR, UTF-8 extracted both files but omitted the spaces. Under CP1252 each order stopped after writing the first file. On the candidate all four runs exited 0, both output files were byte-identical to the compiler output, and all summaries showed the expected spaces and counts. The seven focused tests passed on the original head. On the candidate, `python -B -m unittest discover -s scripts -p "test_*.py"` passed all 24 tests with no skips. Windows build 26100, i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) ported the formatting and ran the tests. No game files, GPU execution or Rust build.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 05:40 UTC · original · reviewed

Could candidate extraction distinguish an invalid part table from a valid DXBC container without RTS0? Here parts() skips an out-of-range chunk offset, but extract_shaders() still writes the candidate. With a synthetic 44-byte DXBC whose sole part offset is 0x1000, followed by a valid-structure SHEX container, the CLI exits 0, writes the malformed bytes as 00.dxbc, and shifts the valid container to 01.dxbc. Rejecting that candidate while preserving the no-RTS0 case, plus a malformed-then-valid fixture, would make extraction and numbering reliable. Reproduced at exact head ebf6f96c60414ca63bf22792a7ff92ad697462ac with synthetic bytes only; no DLL or GPU test. AI-assisted review with Codex.

**@⁠luckyteagirl** on GitHub · 2026-11-26 05:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1858#pullrequestreview-6069077166) · **reviewed** Could candidate extraction distinguish an invalid part table from a valid DXBC container without `RTS0`? Here `parts()` skips an out-of-range chunk offset, but `extract_shaders()` still writes the candidate. With a synthetic 44-byte DXBC whose sole part offset is `0x1000`, followed by a valid-structure `SHEX` container, the CLI exits 0, writes the malformed bytes as `00.dxbc`, and shifts the valid container to `01.dxbc`. Rejecting that candidate while preserving the no-`RTS0` case, plus a malformed-then-valid fixture, would make extraction and numbering reliable. Reproduced at exact head `ebf6f96c60414ca63bf22792a7ff92ad697462ac` with synthetic bytes only; no DLL or GPU test. AI-assisted review with Codex.
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/1858/head:github-bot/gh-1858'
git switch 'github-bot/gh-1858'

Merge

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