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

Open
heditrigui wants to merge 1 commit from upstream-pr/1858 into main
heditrigui commented 2026-11-24 21:58:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by heditrigui on 2026-11-24T21:58:22Z.


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))
<!-- greyfinch-sync:ivall/xcl:issue:5481022078 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1858). Originally posted by [heditrigui](https://github.com/heditrigui) on 2026-11-24T21:58:22Z. --- ### 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))
futurepro62 commented 2026-11-24 23:08:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T22:36:58Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7146442354 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7146442354). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T22:36:58Z. --- 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.
JJAutoCompare commented 2026-11-25 02:08:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T01:27:47Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7149573376 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7149573376). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-25T01:27:47Z. --- **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.
DavidM1911 commented 2026-11-25 02:08:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T01:28:52Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7149593957 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7149593957). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T01:28:52Z. --- 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!
RavenCurseBurg commented 2026-11-26 05:05:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by RavenCurseBurg on 2026-11-26T04:31:23Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7182668263 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7182668263). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T04:31:23Z. --- 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.
luckyteagirl commented 2026-11-26 05:40:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T05:40:01Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ivall/xcl:review:6069077166 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1858#pullrequestreview-6069077166). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T05:40:01Z. **Review:** COMMENTED --- 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.
upipibi commented 2026-11-26 17:24:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T17:24:29Z.


Tested head ebf6f96c60414ca63bf22792a7ff92ad697462ac, merge-base with main 1d027e5c76c9a86a7ee2ca1cc677edf0be95d331. Windows 11 Pro 26100, CPython 3.13.0.

  • py -3.13 -B -m unittest -v scripts/test_bvhb_shaders.py: 7 passed at head (1 at merge-base).
  • py -3.13 -B -m unittest discover -s scripts -p "test_*.py": 22 passed, 0 failed at head; 16 passed, 0 failed at merge-base. pytest scripts: 22 passed.
  • The PR's test file against the merge-base script: 3 failed, 2 errors.

Not tested: retail data, GPU, Cargo.

AI-assisted (Claude Code, Claude Sonnet 5.5).

<!-- greyfinch-sync:ivall/xcl:comment:7198964112 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7198964112). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-26T17:24:29Z. --- **Tested** head `ebf6f96c60414ca63bf22792a7ff92ad697462ac`, merge-base with main `1d027e5c76c9a86a7ee2ca1cc677edf0be95d331`. Windows 11 Pro 26100, CPython 3.13.0. - `py -3.13 -B -m unittest -v scripts/test_bvhb_shaders.py`: 7 passed at head (1 at merge-base). - `py -3.13 -B -m unittest discover -s scripts -p "test_*.py"`: 22 passed, 0 failed at head; 16 passed, 0 failed at merge-base. pytest `scripts`: 22 passed. - The PR's test file against the merge-base script: 3 failed, 2 errors. **Not tested:** retail data, GPU, Cargo. AI-assisted (Claude Code, Claude Sonnet 5.5).
github-actions[bot] commented 2026-12-01 02:35:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:35:47Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298786477 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7298786477). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:35:47Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 07:00:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:00:40Z.


Triage (#1607) – head ebf6f96

#1493 (opened first) also hardens scripts/re/bvhb_shaders.py against truncated and false-positive DXBC matches, but differently: it validates the container header (version 1, total size = blob size, part offsets in range) and skips invalid matches. This PR only bounds-checks reads, so a false-positive DXBC with an in-range size is still written out as NN.dxbc and listed; it also adds -h/exit codes and extract_shaders/main.
The two conflict in extract_shaders/the top-level loop; whichever lands second needs a rebase. No test exercises the new truncation guards (the new tests cover the CLI, the import API and a shader without RTS0).
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7303539141 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1858#issuecomment-7303539141). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:00:40Z. --- **Triage (#1607)** – head ebf6f96 #1493 (opened first) also hardens `scripts/re/bvhb_shaders.py` against truncated and false-positive DXBC matches, but differently: it validates the container header (version 1, total size = blob size, part offsets in range) and skips invalid matches. This PR only bounds-checks reads, so a false-positive `DXBC` with an in-range size is still written out as `NN.dxbc` and listed; it also adds `-h`/exit codes and `extract_shaders`/`main`. The two conflict in `extract_shaders`/the top-level loop; whichever lands second needs a rebase. No test exercises the new truncation guards (the new tests cover the CLI, the import API and a shader without RTS0). Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1858:upstream-pr/1858'
git switch 'upstream-pr/1858'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1858'
git switch 'upstream-pr/1858'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1858'
git switch 'upstream-pr/1858'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1858'
git switch 'main'
git merge --squash 'upstream-pr/1858'
git switch 'main'
git merge --ff-only 'upstream-pr/1858'
git switch 'main'
git merge 'upstream-pr/1858'
git push origin 'main'
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
xcl-dev/xcl!1848
No description provided.