shader: accept argv and harden error and atomic manifest handling in extract_shaders #2320

Merged
Ammmae0x merged 2 commits from upstream-pr/2328 into main 2026-11-25 13:08:32 +00:00
Ammmae0x commented 2026-11-25 12:32:10 +00:00 (Migrated from github.com)

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


Change

Updates tools/extract_shaders.py to accept argv in main(argv=None) -> int, harden CLI error/path validation, and write manifest.json atomically, paired with a standalone pure-Python unit and CLI check suite (tests/extract_shaders_cli_check.py, registered as extract_shaders_cli in CMakeLists.txt):

  • Passes argv to parser.parse_args(argv) and returns 0 on success.
  • Validates --limit >= 1 via parser.error, validates archive existence/file type and --output-dir archive-collision/directory type inside try/except (OSError, ValueError, struct.error, zlib.error), and exits cleanly via parser.exit(1, ...) with zero raw Python tracebacks.
  • Writes manifest.json through _write_atomic() using a sibling temporary file cleaned up on any write/replace failure.
  • Covers sanitize_filename(), extract_native_rdna2_code() (positive + XDAT/XBCH/zlib/FSSM/s_endpgm negative 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 on upstream/main 8d1e0afa). Pure-Python change; no C++ or GPU binaries modified.

  • out/pe-env/Scripts/python.exe -B tests/extract_shaders_cli_check.py -> exit 0 (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 -> exit 0 (Ran 156 tests ... OK (skipped=19); 19 skips due to unset LLVM_LIB)
  • 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 (Self-test passed.)
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0 (Self-test passed.)
  • Spot-mutation verification (pre-push): temporarily disabling each of the six new guards in tools/extract_shaders.py (--limit < 1, archive exists, archive is file, output_dir == archive_path, existing non-directory --output-dir, and tmp_path.unlink(missing_ok=True)) caused tests/extract_shaders_cli_check.py to fail with exit 1 in 6/6 cases.

Evidence and follow-up

  • Uses synthetic in-memory RPF9/DXBC/XBCH/FSSM fixtures constructed in tests/extract_shaders_cli_check.py under the repository MIT license; no external binaries, dumps, or GPU/LLVM tools are required.
  • Contributors can run the suite directly with python -B tests/extract_shaders_cli_check.py or via CTest (extract_shaders_cli).
  • AI-assisted.

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. (No build requirement or user-facing capability doc change needed.)
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6604543872 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2328). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T12:32:10Z. --- ## Change Updates `tools/extract_shaders.py` to accept `argv` in `main(argv=None) -> int`, harden CLI error/path validation, and write `manifest.json` atomically, paired with a standalone pure-Python unit and CLI check suite (`tests/extract_shaders_cli_check.py`, registered as `extract_shaders_cli` in `CMakeLists.txt`): - Passes `argv` to `parser.parse_args(argv)` and returns `0` on success. - Validates `--limit >= 1` via `parser.error`, validates archive existence/file type and `--output-dir` archive-collision/directory type inside `try/except (OSError, ValueError, struct.error, zlib.error)`, and exits cleanly via `parser.exit(1, ...)` with zero raw Python tracebacks. - Writes `manifest.json` through `_write_atomic()` using a sibling temporary file cleaned up on any write/replace failure. - Covers `sanitize_filename()`, `extract_native_rdna2_code()` (positive + XDAT/XBCH/zlib/FSSM/`s_endpgm` negative 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 on `upstream/main` `8d1e0afa`). Pure-Python change; no C++ or GPU binaries modified. - `out/pe-env/Scripts/python.exe -B tests/extract_shaders_cli_check.py` -> exit `0` (`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` -> exit `0` (`Ran 156 tests ... OK (skipped=19)`; 19 skips due to unset `LLVM_LIB`) - `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` (`Self-test passed.`) - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> exit `0` (`Self-test passed.`) - Spot-mutation verification (pre-push): temporarily disabling each of the six new guards in `tools/extract_shaders.py` (`--limit < 1`, archive exists, archive is file, `output_dir == archive_path`, existing non-directory `--output-dir`, and `tmp_path.unlink(missing_ok=True)`) caused `tests/extract_shaders_cli_check.py` to fail with exit `1` in 6/6 cases. ## Evidence and follow-up - Uses synthetic in-memory RPF9/DXBC/XBCH/FSSM fixtures constructed in `tests/extract_shaders_cli_check.py` under the repository MIT license; no external binaries, dumps, or GPU/LLVM tools are required. - Contributors can run the suite directly with `python -B tests/extract_shaders_cli_check.py` or via CTest (`extract_shaders_cli`). - AI-assisted. ## 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. (No build requirement or user-facing capability doc change needed.) - [x] I did not include game files, dumps, distribution links or secrets.
tedin7 commented 2026-11-25 13:00:50 +00:00 (Migrated from github.com)

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-aware main, argument validation, atomic manifest write), new tests/extract_shaders_cli_check.py, CTest registration extract_shaders_cli in CMakeLists.txt.

Commands executed locally:

  • git diff --stat origin/main...HEAD -> 3 files, +368/-18
  • python3 -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 -> clean
  • gh 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 -- .):

  1. Replace tmp_path.replace(path) with a direct path.write_text(content) -> the new suite FAILS (leftover .tmp assertion at tests/extract_shaders_cli_check.py:182). Killed.
  2. Disable the output_dir == archive_path guard -> the suite FAILS (the case is rejected by the next guard with a different message). Killed.

Findings:

  • P1: none.
  • P2: none.
  • Nit: main() catches only OSError/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.
  • Nit: the .resolve() calls run before the exists() check; harmless, but reordering would read more clearly.
  • Nit: _write_atomic does 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057721821 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2328#pullrequestreview-6057721821). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:37:46Z. **Review:** COMMENTED --- Review of head 424374d7977d237846f58c6a0b0fe9ad570ace83 (Linux, local worktree). Scope: `tools/extract_shaders.py` (argv-aware `main`, argument validation, atomic manifest write), new `tests/extract_shaders_cli_check.py`, CTest registration `extract_shaders_cli` in `CMakeLists.txt`. Commands executed locally: - `git diff --stat origin/main...HEAD` -> 3 files, +368/-18 - `python3 -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` -> clean - `gh 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 -- .`): 1. Replace `tmp_path.replace(path)` with a direct `path.write_text(content)` -> the new suite FAILS (leftover `.tmp` assertion at `tests/extract_shaders_cli_check.py:182`). Killed. 2. Disable the `output_dir == archive_path` guard -> the suite FAILS (the case is rejected by the next guard with a different message). Killed. Findings: - P1: none. - P2: none. - Nit: `main()` catches only `OSError/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. - Nit: the `.resolve()` calls run before the `exists()` check; harmless, but reordering would read more clearly. - Nit: `_write_atomic` does 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.
upstream-sync closed this pull request 2026-11-25 14:04:44 +00:00
tedin7 commented 2026-11-25 14:04:45 +00:00 (Migrated from github.com)

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 -> clean
  • CI: Linux Python checks pass; Windows/gfx1013 jobs were still pending when I looked. Mergeable. Title neutral, no clean-room concerns (pure Python, no vendor material).

Mutations (reverted with git checkout -- .):

  1. if collision: -> if False: in ensure_separate_output: the suite fails (main([... manifest.json --output-dir ...]) did not raise SystemExit). Killed.
  2. _write_atomic cleanup unlink(missing_ok=True) -> pass: the suite fails on the leftover .tmp assertion. Killed.

Findings:

  • P1: none. P2: none.
  • nit tools/extract_shaders.py (the except PermissionError fallback in extract_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.
  • nit main(): output_dir == archive_path is subsumed by the exists() and not is_dir() check whenever the archive exists. It is harmless but redundant. The per-file samefile guard is the one that matters, and it is covered.
  • nit: _write_atomic does not fsync before replace. This is fine for a manifest, just noting it.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6058144503 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2328#pullrequestreview-6058144503). Originally posted by [tedin7](https://github.com/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` -> clean - CI: Linux Python checks pass; Windows/gfx1013 jobs were still pending when I looked. Mergeable. Title neutral, no clean-room concerns (pure Python, no vendor material). Mutations (reverted with `git checkout -- .`): 1. `if collision:` -> `if False:` in `ensure_separate_output`: the suite fails (`main([... manifest.json --output-dir ...]) did not raise SystemExit`). Killed. 2. `_write_atomic` cleanup `unlink(missing_ok=True)` -> `pass`: the suite fails on the leftover `.tmp` assertion. Killed. Findings: - P1: none. P2: none. - nit `tools/extract_shaders.py` (the `except PermissionError` fallback in `extract_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. - nit `main()`: `output_dir == archive_path` is subsumed by the `exists() and not is_dir()` check whenever the archive exists. It is harmless but redundant. The per-file `samefile` guard is the one that matters, and it is covered. - nit: `_write_atomic` does not fsync before `replace`. This is fine for a manifest, just noting it. AI-assisted; commands listed were executed locally.
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!2320
No description provided.