runtime: extract main(argv), bounds validation, and struct.error guards in resource_root with CLI suite #2535

Merged
Ammmae0x merged 2 commits from upstream-pr/2543 into main 2026-11-25 20:46:31 +00:00
Ammmae0x commented 2026-11-25 20:24:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T20:24:24Z.


Change

Harden the tools/resource_root.py CLI entrypoint and argument/error validation, and add a standalone pure-Python CLI/mutation test suite (tests/resource_root_cli_check.py, registered as runtime_resource_root_cli_check in CMakeLists.txt):

  • Update main(argv: Sequence[str] | None = None) -> int to forward argv to parser.parse_args(argv) and return 0, invoking raise SystemExit(main()) under if __name__ == "__main__".
  • Validate upfront that --offset >= 0, --stored > 0, --decoded > 0, and archive is not a directory before opening the file.
  • Include struct.error in the caught exception set (OSError, ValueError, struct.error, zlib.error) so malformed/truncated resource errors exit cleanly via parser.exit(1, f"{args.archive}: {error}\n") with zero raw tracebacks while preserving the exact JSON stdout (root_type_hash, root_bytes) contract.

AI-assisted.

Verification

Verified on commit 83362d09f08561202c4b5753135bed6e0340d84d (rebased onto upstream/main 5a219a3c) using out\pe-env\Scripts\python.exe -B:

  • out\pe-env\Scripts\python.exe -B tests/resource_root_cli_check.py -v -> exit 0 (Ran 10 tests in 3.494s, OK)
  • out\pe-env\Scripts\python.exe -B tests/resource_root_check.py -v -> exit 0 (Ran 5 tests in 0.442s, OK)
  • 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. Checked 19 Markdown files and 479 links.)
  • out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py -> exit 0 (Self-test passed. Checked 1778 tracked source, script and build/CI files: no bidirectional controls.)
  • Spot mutation check: 9/9 targeted mutations in tools/resource_root.py (parse_args(argv) forwarding, --offset < 0, --stored <= 0 -> < 0, --decoded <= 0 -> < 0, archive.is_dir(), struct.error guard, zlib.error guard, return 0, exact 2 MiB budget boundary) caused tests/resource_root_cli_check.py to fail (exit 1).

Evidence and follow-up

  • New fixtures in tests/resource_root_cli_check.py are synthetic in-memory relocated PRD0 v0x7a zlib streams generated in Python with synthetic type hashes (0x1234abcd, 0x00008888) under the repository MIT License.
  • Positive controls cover zero and non-zero decimal/hex --offset/--stored/--decoded, exact 2 MiB decoded boundary, main(None) sys.argv forwarding, runpy __main__ entrypoint, and exact JSON schema.
  • Negative controls cover missing/directory archives, negative --offset, zero/negative --stored/--decoded, > 2 MiB stored/decoded budget, corrupt zlib and zlib.error guard, truncated/malformed PRD0 and struct.error guard, and Python 3.14 argparse-compatible usage errors.

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.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6613046484 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2543). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T20:24:24Z. --- ## Change Harden the `tools/resource_root.py` CLI entrypoint and argument/error validation, and add a standalone pure-Python CLI/mutation test suite (`tests/resource_root_cli_check.py`, registered as `runtime_resource_root_cli_check` in `CMakeLists.txt`): - Update `main(argv: Sequence[str] | None = None) -> int` to forward `argv` to `parser.parse_args(argv)` and return `0`, invoking `raise SystemExit(main())` under `if __name__ == "__main__"`. - Validate upfront that `--offset >= 0`, `--stored > 0`, `--decoded > 0`, and `archive` is not a directory before opening the file. - Include `struct.error` in the caught exception set `(OSError, ValueError, struct.error, zlib.error)` so malformed/truncated resource errors exit cleanly via `parser.exit(1, f"{args.archive}: {error}\n")` with zero raw tracebacks while preserving the exact JSON stdout (`root_type_hash`, `root_bytes`) contract. AI-assisted. ## Verification Verified on commit `83362d09f08561202c4b5753135bed6e0340d84d` (rebased onto `upstream/main` `5a219a3c`) using `out\pe-env\Scripts\python.exe -B`: - `out\pe-env\Scripts\python.exe -B tests/resource_root_cli_check.py -v` -> exit 0 (`Ran 10 tests in 3.494s`, `OK`) - `out\pe-env\Scripts\python.exe -B tests/resource_root_check.py -v` -> exit 0 (`Ran 5 tests in 0.442s`, `OK`) - `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. Checked 19 Markdown files and 479 links.`) - `out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py` -> exit 0 (`Self-test passed. Checked 1778 tracked source, script and build/CI files: no bidirectional controls.`) - Spot mutation check: 9/9 targeted mutations in `tools/resource_root.py` (`parse_args(argv)` forwarding, `--offset < 0`, `--stored <= 0` -> `< 0`, `--decoded <= 0` -> `< 0`, `archive.is_dir()`, `struct.error` guard, `zlib.error` guard, `return 0`, exact 2 MiB budget boundary) caused `tests/resource_root_cli_check.py` to fail (exit 1). ## Evidence and follow-up - New fixtures in `tests/resource_root_cli_check.py` are synthetic in-memory relocated PRD0 v0x7a zlib streams generated in Python with synthetic type hashes (`0x1234abcd`, `0x00008888`) under the repository MIT License. - Positive controls cover zero and non-zero decimal/hex `--offset`/`--stored`/`--decoded`, exact 2 MiB decoded boundary, `main(None)` `sys.argv` forwarding, `runpy` `__main__` entrypoint, and exact JSON schema. - Negative controls cover missing/directory archives, negative `--offset`, zero/negative `--stored`/`--decoded`, `> 2 MiB` stored/decoded budget, corrupt zlib and `zlib.error` guard, truncated/malformed PRD0 and `struct.error` guard, and Python 3.14 `argparse`-compatible usage errors. ## 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. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-25 21:01:22 +00:00
tedin7 commented 2026-11-25 21:01:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:38:49Z.

Review: COMMENTED


Review of head 83362d09 (comment only, no approval).

No blocking findings. Checked:

  • tools/resource_root.py: main(argv) forwards to parse_args, returns 0 and is wrapped in raise SystemExit(main()). Upfront checks for negative --offset, non-positive --stored / --decoded, and directory archive. struct.error joins the caught set, so malformed input exits 1 through parser.exit instead of a traceback. JSON stdout contract is unchanged.
  • tests/resource_root_cli_check.py (10 tests) guards these behaviors through the CLI. Registered as runtime_resource_root_cli_check.
  • No other open or merged PR touches resource_root.
  • Not a startup-path or shader change, so no game or WARP-readback claim applies.

Commands run locally (Linux, pefile venv, 10 commits behind main):

  • python3 -B tests/resource_root_cli_check.py -> OK
  • python3 -B tests/resource_root_check.py -> OK
  • python3 tests/docs_links_check.py -> passed
  • python3 tests/bidi_controls_check.py -> passed
  • git diff --check origin/main...HEAD -> clean
  • Mutations, each makes the new suite fail, then reverted: drop struct.error (1 error); --stored check <= 0 to < 0 (3 failures); disable the directory check (1 failure).

A Windows Server 2025 run on the current head follows separately.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6064651790 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2543#pullrequestreview-6064651790). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:38:49Z. **Review:** COMMENTED --- Review of head 83362d09 (comment only, no approval). No blocking findings. Checked: - `tools/resource_root.py`: `main(argv)` forwards to `parse_args`, returns 0 and is wrapped in `raise SystemExit(main())`. Upfront checks for negative `--offset`, non-positive `--stored` / `--decoded`, and directory archive. `struct.error` joins the caught set, so malformed input exits 1 through `parser.exit` instead of a traceback. JSON stdout contract is unchanged. - `tests/resource_root_cli_check.py` (10 tests) guards these behaviors through the CLI. Registered as `runtime_resource_root_cli_check`. - No other open or merged PR touches `resource_root`. - Not a startup-path or shader change, so no game or WARP-readback claim applies. Commands run locally (Linux, pefile venv, 10 commits behind main): - `python3 -B tests/resource_root_cli_check.py` -> OK - `python3 -B tests/resource_root_check.py` -> OK - `python3 tests/docs_links_check.py` -> passed - `python3 tests/bidi_controls_check.py` -> passed - `git diff --check origin/main...HEAD` -> clean - Mutations, each makes the new suite fail, then reverted: drop `struct.error` (1 error); `--stored` check `<= 0` to `< 0` (3 failures); disable the directory check (1 failure). A Windows Server 2025 run on the current head follows separately. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 21:01:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:45:42Z.


Win2025 WARP receipt for head 1c984af0 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 1c984af05d639e796b2560b666c708f6892e9109:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 78.96s (configure 2.35s)
    • Test (ctest --preset dev -R '^(runtime_resource_root_cli_check|resource_root.*)$' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (5.90s: runtime_resource_root_cli_check 5.70s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 87.66s (configure 2.10s)
    • Test (ctest --preset release -R '^(runtime_resource_root_cli_check|resource_root.*)$' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (4.89s: runtime_resource_root_cli_check 4.77s)
  • Windows Python checks: tests/resource_root_cli_check.py ok (5.2s), tests/resource_root_check.py ok (0.8s)
  • sccache: 187/568 hits; wall 188.8s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7174150988 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2543#issuecomment-7174150988). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:45:42Z. --- Win2025 WARP receipt for head 1c984af0 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `1c984af05d639e796b2560b666c708f6892e9109`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `78.96s` (configure `2.35s`) - Test (`ctest --preset dev -R '^(runtime_resource_root_cli_check|resource_root.*)$' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`5.90s`: `runtime_resource_root_cli_check` `5.70s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `87.66s` (configure `2.10s`) - Test (`ctest --preset release -R '^(runtime_resource_root_cli_check|resource_root.*)$' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`4.89s`: `runtime_resource_root_cli_check` `4.77s`) - **Windows Python checks**: `tests/resource_root_cli_check.py` ok (`5.2s`), `tests/resource_root_check.py` ok (`0.8s`) - `sccache`: 187/568 hits; wall `188.8s` 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!2535
No description provided.