shader: accept argv and harden error and atomic manifest handling in extract_shaders #2320
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2328"
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-25T12:32:10Z.
Change
Updates
tools/extract_shaders.pyto acceptargvinmain(argv=None) -> int, harden CLI error/path validation, and writemanifest.jsonatomically, paired with a standalone pure-Python unit and CLI check suite (tests/extract_shaders_cli_check.py, registered asextract_shaders_cliinCMakeLists.txt):argvtoparser.parse_args(argv)and returns0on success.--limit >= 1viaparser.error, validates archive existence/file type and--output-dirarchive-collision/directory type insidetry/except (OSError, ValueError, struct.error, zlib.error), and exits cleanly viaparser.exit(1, ...)with zero raw Python tracebacks.manifest.jsonthrough_write_atomic()using a sibling temporary file cleaned up on any write/replace failure.sanitize_filename(),extract_native_rdna2_code()(positive + XDAT/XBCH/zlib/FSSM/s_endpgmnegative controls),main(argv)across--format native|dxbc|both,--stage,--limit,--length-prefixed-names, and CLI negative controls (missing/dir archive, path collision including..alias, regular file as--output-dir,--limit < 1,struct.error/zlib.error, write-failure temp cleanup).Verification
Commit:
424374d7(based onupstream/main8d1e0afa). Pure-Python change; no C++ or GPU binaries modified.out/pe-env/Scripts/python.exe -B tests/extract_shaders_cli_check.py-> exit0(extract_shaders_cli: helpers, CLI formats/stages/limits, atomic manifest, and error checks passed)out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py-> exit0(Ran 156 tests ... OK (skipped=19); 19 skips due to unsetLLVM_LIB)out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py-> exit0(form coverage checks passed)out/pe-env/Scripts/python.exe -B tests/docs_links_check.py-> exit0(Self-test passed.)out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py-> exit0(Self-test passed.)tools/extract_shaders.py(--limit < 1, archive exists, archive is file,output_dir == archive_path, existing non-directory--output-dir, andtmp_path.unlink(missing_ok=True)) causedtests/extract_shaders_cli_check.pyto fail with exit1in 6/6 cases.Evidence and follow-up
tests/extract_shaders_cli_check.pyunder the repository MIT license; no external binaries, dumps, or GPU/LLVM tools are required.python -B tests/extract_shaders_cli_check.pyor via CTest (extract_shaders_cli).Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:37:46Z.
Review: COMMENTED
Review of head
424374d797(Linux, local worktree).Scope:
tools/extract_shaders.py(argv-awaremain, argument validation, atomic manifest write), newtests/extract_shaders_cli_check.py, CTest registrationextract_shaders_cliinCMakeLists.txt.Commands executed locally:
git diff --stat origin/main...HEAD-> 3 files, +368/-18python3 -B tests/extract_shaders_cli_check.py-> PASS ("helpers, CLI formats/stages/limits, atomic manifest, and error checks passed")python3 tests/docs_links_check.py-> PASS (18 files, 451 links)python3 tests/bidi_controls_check.py-> PASS (1623 files)git diff --check origin/main...HEAD-> cleangh pr checks 2328-> Linux checks, gfx1013 fixtures and Windows build/test all pass; PR is mergeable; title is neutral.Mutations (each reverted with
git checkout -- .):tmp_path.replace(path)with a directpath.write_text(content)-> the new suite FAILS (leftover.tmpassertion attests/extract_shaders_cli_check.py:182). Killed.output_dir == archive_pathguard -> the suite FAILS (the case is rejected by the next guard with a different message). Killed.Findings:
main()catches onlyOSError/ValueError/struct.error/zlib.error. A malformed archive that raises another exception type (e.g.IndexError) still yields a traceback instead of the clean[-] Error:exit. Optional..resolve()calls run before theexists()check; harmless, but reordering would read more clearly._write_atomicdoes not fsync before replace. Fine for a manifest, just noting it.No Windows run needed: pure Python tooling, no shader/C++ lowering touched.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:05:53Z.
Review: COMMENTED
Review of head
51704e3214ac7b3ab22ae19062c5179074e51095(2 commits:424374d7,51704e32). Scope:tools/extract_shaders.py,tests/extract_shaders_cli_check.py,CMakeLists.txt(+396/-19).Verdict: no P1, no P2. Logic reads correct; tests kill the mutations I tried.
Checks (Linux, in a clean worktree of the PR head):
python3 -B tests/extract_shaders_cli_check.py-> exit 0 ("helpers, CLI formats/stages/limits, atomic manifest, and error checks passed")python3 tests/docs_links_check.py-> pass (18 files, 451 links)python3 tests/bidi_controls_check.py-> pass (1623 files)git diff --check origin/main...HEAD-> cleanMutations (reverted with
git checkout -- .):if collision:->if False:inensure_separate_output: the suite fails (main([... manifest.json --output-dir ...]) did not raise SystemExit). Killed._write_atomiccleanupunlink(missing_ok=True)->pass: the suite fails on the leftover.tmpassertion. Killed.Findings:
tools/extract_shaders.py(theexcept PermissionErrorfallback inextract_shaders): when the output dir is not writable, the tool silently redirects to the temp dir. This is pre-existing and warns on stderr, but now sits next to the new strict validation. Consider noting it in the docstring or failing instead. Not blocking.main():output_dir == archive_pathis subsumed by theexists() and not is_dir()check whenever the archive exists. It is harmless but redundant. The per-filesamefileguard is the one that matters, and it is covered._write_atomicdoes not fsync beforereplace. This is fine for a manifest, just noting it.AI-assisted; commands listed were executed locally.