shader: extract main(argv), bounds checks, and struct/zlib guards in shader_census with CLI suite #2429
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2437"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T16:43:17Z.
Change
Extract a testable
main(argv=None) -> intentrypoint, upfront directory and--code-basebounds validation, clean 0-byte mapping, andstruct.error/zlib.errorguards intools/shader_census.py, together with a standalone pure-Python CLI test suite registered inCMakeLists.txt(shader_census_cli_check).tools/shader_census.py:argv: list[str] | None = Noneinmain, forwardargvtoparser.parse_args(argv), return0on success, and invokeraise SystemExit(main())under__main__._map_input(stack, path)to reject directory paths cleanly (ValueError) and returnb""on 0-byte files without hittingmmapValueError.--code-baseviaparser.error("--code-base must be non-negative")(exit 2) alongside the paired--cache-blob/--code-basecheck.(OSError, ValueError, struct.error, zlib.error)viaparser.exit(1, f"Shader census: {error}\n"), preserving the exact'Shader census:'stderr prefix and exit codes expected bytests/shader_census_check.pywith zero raw tracebacks.tests/shader_census_cli_check.py: standalone unittest suite using synthetic archive and PS/9--cache-blobfixtures coveringargvforwarding, decimal and hex--code-base, exact JSON schema, 0-byte archive and--cache-blobhandling, and negative/mutation controls (directory/missing archive or--cache-blob, mismatched or negative--code-baseexit 2, malformed/truncated caches, corrupt deflate payloads, and directstruct.error/zlib.errorguards).CMakeLists.txt: registershader_census_cli_checkimmediately aftershader_metadata_census(tests/shader_census_check.pyleft untouched).Verification
Verified on commit
3ce3d413(based onupstream/mainb442b57f) usingout/pe-env/Scripts/python.exe -B:out/pe-env/Scripts/python.exe -B tests/shader_census_cli_check.py -v->Ran 5 tests in 0.318s,OK(exit 0).out/pe-env/Scripts/python.exe -B tests/shader_census_check.py -v->Ran 9 tests in 0.857s,OK(exit 0).out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py->form coverage checks passed(exit 0).out/pe-env/Scripts/python.exe -B tests/docs_links_check.py->Self-test passed. Checked 19 Markdown files and 465 links.(exit 0).out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 1726 tracked source, script and build/CI files: no bidirectional controls.(exit 0).tools/shader_census.py: 8/8 mutations killed (argvforwarding,is_dir(), 0-byte mmap guard, paired--cache-blob/--code-basecheck,--code-base < 0,struct.errorguard,zlib.errorguard, integer0return).Evidence and follow-up
All fixtures in
tests/shader_census_cli_check.pyare synthetic non-executable framing byte arrays generated in-memory under the repository MIT license; no external binaries or game files are used. Contributors can run the suite directly viaout/pe-env/Scripts/python.exe -B tests/shader_census_cli_check.pyor through CTest (shader_census_cli_check).Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:24:07Z.
Review: COMMENTED
Review of head
3ce3d413(Linux-only checks; I did not run any Windows tests, and the PR shows no author Windows results).Findings
tests/shader_census_cli_check.py:208-212: the--code-base -0x10(two separate arguments) case asserts the stderr fragmentexpected one argument. That text comes from argparse treating-0x10as an option flag, which depends on the Python version. On 3.11, 3.12 and 3.13 the test passes. On 3.14.8 argparse accepts-0x10as the value, so the run reaches the new--code-base must be non-negativeerror. The test then fails withAssertionError: 'expected one argument' not found. The behavior under test is fine (exit 2 either way). Suggested fix: accept either message, or assert only exit code 2 for that case. As written, the new CTestshader_census_cli_checkwill fail on any runner using Python 3.14.--code-base < 0. Not a blocker.What I checked
tools/shader_census.py(_map_inputhelper,main(argv) -> int, catchingstruct.errorandzlib.error), one new CTest entry inCMakeLists.txt, and a new CLI test.shader_census.tests/shader_census_check.pypasses on 3.14.8. The new CLI test passes on 3.13, 3.12 and 3.11 and fails on 3.14.8 (see P2).struct.error, zlib.errorfrom theexceptmakes the CLI test fail (1 failure, 1 error). The test guards that guard.code_base < 0check makes 2 CLI tests fail. The test guards that check too.git checkout -- ..git diff --check origin/main...HEAD,tests/docs_links_check.pyandtests/bidi_controls_check.pyare clean.Commands run:
python3 tests/shader_census_cli_check.py(on python3 3.14.8, 3.13, 3.12 and 3.11),python3 tests/shader_census_check.py,python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD, twosedmutations,git checkout -- ..AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:07:40Z.
Review: COMMENTED
Review of head
a5679cee(tooling only:tools/shader_census.py, new CLI suite, CTest registration). One finding to fix before merge; the rest looks sound.Finding (test is tied to the argparse version):
tests/shader_census_cli_check.py:208-212runs--code-base -0x10(two separate arguments) and expects exit 2 with the textexpected one argument. That message is standard-library behavior, and it differs by Python version. On Python 3.12 (the version CI pins in.github/workflows/windows.yml) it matches. On Python 3.14.8 argparse accepts-0x10as the value, so the new check--code-base must be non-negativefires instead, andtest_mismatched_and_negative_code_base_exit_2fails on an unmodified head.--code-base=-0x10and-1cases just above already guard the real behavior (negative value -> exit 2 withnon-negative). Or accept either fragment.What else I checked:
main(argv)returns an int and is wrapped inSystemExit(main()).struct.errorandzlib.errornow become exit 1 withShader census:and no traceback. The directory guard is shared for both inputs in_map_input. Negative--code-baseexits 2.shader_census_cli_checkis registered next toshader_metadata_censusinCMakeLists.txt.struct.error, zlib.errorfrom the except clause makes the suite fail (1 failure, 1 error). Changing the error exit code from 1 to 0 makes it fail (4 failures). So the suite guards the new behavior.shader_census).Commands run locally on the exact head:
python3 -B tests/shader_census_cli_check.py-> 1 failure on 3.14.8 (the finding above)python3 tests/shader_census_check.py-> OKpython3 tests/docs_links_check.py-> OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleangit checkout -- .I did not merge. I will not run Win2025 until the test no longer depends on the Python version.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T20:10:45Z.
Addressed in
671d1981:_assert_main_failsandtest_mismatched_and_negative_code_base_exit_2intests/shader_census_cli_check.pyso--code-base -0x10(two separate args) still asserts exit2with no traceback while accepting either"expected one argument"(Python <= 3.13) or"non-negative"(Python 3.14+ argparse accepting-0x10as a value).Verified on
671d1981(Python 3.12.8):out/pe-env/Scripts/python.exe -B tests/shader_census_cli_check.py: 5/5 passed (plus simulated Python 3.14--code-base=-0x10path verified, andcode_base < 0spot-mutation caught).out/pe-env/Scripts/python.exe -B tests/shader_census_check.py: 9/9 passed.ctest --preset dev -R "^shader_(census_cli_check|metadata_census)$" --output-on-failure: 2/2 passed (2.34 s).ctest --preset release -R "^shader_(census_cli_check|metadata_census)$" --output-on-failure: 2/2 passed (2.58 s).tests/docs_links_check.pyandtests/bidi_controls_check.py: both passed.AI-assisted.