shader: harden probe_root_devices validation and add offline unit suite #1928

Merged
Ammmae0x merged 3 commits from upstream-pr/1935 into main 2026-11-24 22:16:22 +00:00
Ammmae0x commented 2026-11-24 21:42:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T21:42:43Z.


Change

Harden input, inventory, and output validation in tools/probe_root_devices.py and add an offline synthetic PE32+/DXBC/RTS0 unit and refusal suite in tests/probe_root_devices_check.py, registered in CTest as probe_root_devices_check:

  • Accept argv=None and return 0 in main(argv=None) for programmatic invocation and clean exit propagation (raise SystemExit(main())).
  • Validate rows[0] is a dict with safe .get(...) lookups in the compute_root / compute_tables control loop, validate six-apis.json parses as a dict, and check that b"RTS0" is present in each container's DXBC parts before hashing.
  • Ensure dest.parent.mkdir(parents=True, exist_ok=True) runs before writing via NamedTemporaryFile and unlink the temporary file on error before replacing dest.
  • Catch (OSError, ValueError, KeyError, TypeError, struct.error, pefile.PEFormatError, subprocess.SubprocessError) and exit cleanly with code 1 (parser.exit(1, ...)) without a Python traceback.
  • Add tests/probe_root_devices_check.py (8 tests covering measure(), --warp-only/dual-backend control runs, RTS0 deduplication & atomic write, control failure rows, missing/mismatched image SHA-256, missing/invalid six-apis.json, non-PE/subprocess errors, and build-inside-report-dir refusal) and register probe_root_devices_check in CMakeLists.txt.

AI-assisted.

Verification

  • python.exe -B tests/probe_root_devices_check.py -v: Ran 8 tests in 0.285s — OK (with tools/probe_root_devices.py reverted as a mutation sanity check, 7/8 tests error/fail as expected).
  • cmake --preset dev -DINTAKE_PYTHON=... & ctest --preset dev -N: Total Tests: 1219.
  • ctest --preset dev --no-tests=error -R "^probe_root_devices_check$" -V: 1/1 passed (8/8 tests OK).
  • cmake --preset release -DINTAKE_PYTHON=... & ctest --preset release -N: Total Tests: 1219.
  • ctest --preset release --no-tests=error -R "^probe_root_devices_check$" -V: 1/1 passed (8/8 tests OK).
  • python.exe -B tests/form_coverage_check.py, python.exe -B tests/docs_links_check.py, python.exe -B tests/bidi_controls_check.py: all exited 0.

Evidence and follow-up

All fixtures in tests/probe_root_devices_check.py are synthetic AMD64 PE32+ images with DXBC/RTS0 containers built in memory and mocked root_device_probe.exe outputs; no packaged binaries or GPU hardware are required for CTest execution.

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:6591994183 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1935). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T21:42:43Z. --- ## Change Harden input, inventory, and output validation in `tools/probe_root_devices.py` and add an offline synthetic PE32+/DXBC/`RTS0` unit and refusal suite in `tests/probe_root_devices_check.py`, registered in CTest as `probe_root_devices_check`: - Accept `argv=None` and return `0` in `main(argv=None)` for programmatic invocation and clean exit propagation (`raise SystemExit(main())`). - Validate `rows[0]` is a `dict` with safe `.get(...)` lookups in the `compute_root` / `compute_tables` control loop, validate `six-apis.json` parses as a `dict`, and check that `b"RTS0"` is present in each container's DXBC parts before hashing. - Ensure `dest.parent.mkdir(parents=True, exist_ok=True)` runs before writing via `NamedTemporaryFile` and unlink the temporary file on error before replacing `dest`. - Catch `(OSError, ValueError, KeyError, TypeError, struct.error, pefile.PEFormatError, subprocess.SubprocessError)` and exit cleanly with code `1` (`parser.exit(1, ...)`) without a Python traceback. - Add `tests/probe_root_devices_check.py` (8 tests covering `measure()`, `--warp-only`/dual-backend control runs, `RTS0` deduplication & atomic write, control failure rows, missing/mismatched image SHA-256, missing/invalid `six-apis.json`, non-PE/subprocess errors, and build-inside-report-dir refusal) and register `probe_root_devices_check` in `CMakeLists.txt`. AI-assisted. ## Verification - `python.exe -B tests/probe_root_devices_check.py -v`: `Ran 8 tests in 0.285s` — `OK` (with `tools/probe_root_devices.py` reverted as a mutation sanity check, 7/8 tests error/fail as expected). - `cmake --preset dev -DINTAKE_PYTHON=...` & `ctest --preset dev -N`: `Total Tests: 1219`. - `ctest --preset dev --no-tests=error -R "^probe_root_devices_check$" -V`: `1/1` passed (`8/8` tests OK). - `cmake --preset release -DINTAKE_PYTHON=...` & `ctest --preset release -N`: `Total Tests: 1219`. - `ctest --preset release --no-tests=error -R "^probe_root_devices_check$" -V`: `1/1` passed (`8/8` tests OK). - `python.exe -B tests/form_coverage_check.py`, `python.exe -B tests/docs_links_check.py`, `python.exe -B tests/bidi_controls_check.py`: all exited `0`. ## Evidence and follow-up All fixtures in `tests/probe_root_devices_check.py` are synthetic AMD64 PE32+ images with DXBC/`RTS0` containers built in memory and mocked `root_device_probe.exe` outputs; no packaged binaries or GPU hardware are required for CTest execution. ## 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. - [ ] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
tedin7 commented 2026-11-24 22:00:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:00:16Z.

Review: COMMENTED


Review of head 93f8cee93d (files: CMakeLists.txt, tests/probe_root_devices_check.py, tools/probe_root_devices.py).

Commands run locally:

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.
  • gh pr checks 1935: all pass (the /O2 and chart jobs are skipped).
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/bidi_controls_check.py: pass.
  • python3 tests/docs_links_check.py: pass.
  • python3 -B tests/probe_root_devices_check.py on Linux: cannot run as is. It needs pefile and sys.getwindowsversion. With pefile installed and a getwindowsversion shim: 8 tests OK.
  • python3 x2w_pipe.py win2025 1935 --wait 900: Debug and Release /O2 both pass. probe_root_devices_check and root_device_controls_warp passed 2/2 in each.

Mutations (run on Linux with the shim, then git checkout -- .):

  1. Replaced remaining_flags != 0 with False in the control check. The suite FAILED, so it is covered.
  2. Replaced if b"RTS0" not in container_parts: with if False:. The suite still PASSED, so the mutation survived. See P2.

Findings:

P1: none.

P2

  • tools/probe_root_devices.py:63. The new "missing RTS0" refusal has no test. No fixture builds a DXBC container without an RTS0 part, and the suite passes with the check removed. Without the check, container_parts[b"RTS0"] raises KeyError. The outer handler catches that and exits 1, but with a bare 'RTS0' message. Please add a case with a container that has no RTS0 and assert exit code 1 and the "missing RTS0" text on stderr.

P3

  • tools/probe_root_devices.py:33. sys.getwindowsversion() is called before the try, so the tool still fails with a traceback on non-Windows. The test file also needs it, so probe_root_devices_check only works on Windows. This is fine while it is registered only under INTAKE_PYTHON, but a short comment or a Windows-only guard in the test would make that explicit.
  • tools/probe_root_devices.py:82. except ... TypeError hides programming errors as "exit 1" messages. KeyError and TypeError are caught for malformed inventory input, which is the intent, so consider narrowing them to the inventory-reading block.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048088618 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1935#pullrequestreview-6048088618). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T22:00:16Z. **Review:** COMMENTED --- Review of head 93f8cee93ddc98fa1b2e55481886fa9374e28d2d (files: CMakeLists.txt, tests/probe_root_devices_check.py, tools/probe_root_devices.py). Commands run locally: - `git merge-tree --write-tree --name-only origin/main HEAD`: clean, no conflicts. - `gh pr checks 1935`: all pass (the /O2 and chart jobs are skipped). - `git diff --check origin/main...HEAD`: clean. - `python3 tests/bidi_controls_check.py`: pass. - `python3 tests/docs_links_check.py`: pass. - `python3 -B tests/probe_root_devices_check.py` on Linux: cannot run as is. It needs `pefile` and `sys.getwindowsversion`. With pefile installed and a `getwindowsversion` shim: 8 tests OK. - `python3 x2w_pipe.py win2025 1935 --wait 900`: Debug and Release /O2 both pass. `probe_root_devices_check` and `root_device_controls_warp` passed 2/2 in each. Mutations (run on Linux with the shim, then `git checkout -- .`): 1. Replaced `remaining_flags != 0` with `False` in the control check. The suite FAILED, so it is covered. 2. Replaced `if b"RTS0" not in container_parts:` with `if False:`. The suite still PASSED, so the mutation survived. See P2. Findings: P1: none. P2 - tools/probe_root_devices.py:63. The new "missing RTS0" refusal has no test. No fixture builds a DXBC container without an RTS0 part, and the suite passes with the check removed. Without the check, `container_parts[b"RTS0"]` raises `KeyError`. The outer handler catches that and exits 1, but with a bare `'RTS0'` message. Please add a case with a container that has no RTS0 and assert exit code 1 and the "missing RTS0" text on stderr. P3 - tools/probe_root_devices.py:33. `sys.getwindowsversion()` is called before the `try`, so the tool still fails with a traceback on non-Windows. The test file also needs it, so `probe_root_devices_check` only works on Windows. This is fine while it is registered only under `INTAKE_PYTHON`, but a short comment or a Windows-only guard in the test would make that explicit. - tools/probe_root_devices.py:82. `except ... TypeError` hides programming errors as "exit 1" messages. `KeyError` and `TypeError` are caught for malformed inventory input, which is the intent, so consider narrowing them to the inventory-reading block. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 22:00:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:00:27Z.

Review: COMMENTED


Review of head 93f8cee93d (files: CMakeLists.txt, tests/probe_root_devices_check.py, tools/probe_root_devices.py).

Commands run locally:

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.
  • gh pr checks 1935: all pass (the /O2 and chart jobs are skipped).
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/bidi_controls_check.py: pass.
  • python3 tests/docs_links_check.py: pass.
  • python3 -B tests/probe_root_devices_check.py on Linux: cannot run as is. It needs pefile and sys.getwindowsversion. With pefile installed and a getwindowsversion shim: 8 tests OK.
  • python3 x2w_pipe.py win2025 1935 --wait 900: Debug and Release /O2 both pass. probe_root_devices_check and root_device_controls_warp passed 2/2 in each.

Mutations (run on Linux with the shim, then git checkout -- .):

  1. Replaced remaining_flags != 0 with False in the control check. The suite FAILED, so it is covered.
  2. Replaced if b"RTS0" not in container_parts: with if False:. The suite still PASSED, so the mutation survived. See P2.

Findings:

P1: none.

P2

  • tools/probe_root_devices.py:63. The new "missing RTS0" refusal has no test. No fixture builds a DXBC container without an RTS0 part, and the suite passes with the check removed. Without the check, container_parts[b"RTS0"] raises KeyError. The outer handler catches that and exits 1, but with a bare 'RTS0' message. Please add a case with a container that has no RTS0 and assert exit code 1 and the "missing RTS0" text on stderr.

P3

  • tools/probe_root_devices.py:33. sys.getwindowsversion() is called before the try, so the tool still fails with a traceback on non-Windows. The test file also needs it, so probe_root_devices_check only works on Windows. This is fine while it is registered only under INTAKE_PYTHON, but a short comment or a Windows-only guard in the test would make that explicit.
  • tools/probe_root_devices.py:82. except ... TypeError hides programming errors as "exit 1" messages. KeyError and TypeError are caught for malformed inventory input, which is the intent, so consider narrowing them to the inventory-reading block.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048090663 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1935#pullrequestreview-6048090663). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T22:00:27Z. **Review:** COMMENTED --- Review of head 93f8cee93ddc98fa1b2e55481886fa9374e28d2d (files: CMakeLists.txt, tests/probe_root_devices_check.py, tools/probe_root_devices.py). Commands run locally: - `git merge-tree --write-tree --name-only origin/main HEAD`: clean, no conflicts. - `gh pr checks 1935`: all pass (the /O2 and chart jobs are skipped). - `git diff --check origin/main...HEAD`: clean. - `python3 tests/bidi_controls_check.py`: pass. - `python3 tests/docs_links_check.py`: pass. - `python3 -B tests/probe_root_devices_check.py` on Linux: cannot run as is. It needs `pefile` and `sys.getwindowsversion`. With pefile installed and a `getwindowsversion` shim: 8 tests OK. - `python3 x2w_pipe.py win2025 1935 --wait 900`: Debug and Release /O2 both pass. `probe_root_devices_check` and `root_device_controls_warp` passed 2/2 in each. Mutations (run on Linux with the shim, then `git checkout -- .`): 1. Replaced `remaining_flags != 0` with `False` in the control check. The suite FAILED, so it is covered. 2. Replaced `if b"RTS0" not in container_parts:` with `if False:`. The suite still PASSED, so the mutation survived. See P2. Findings: P1: none. P2 - tools/probe_root_devices.py:63. The new "missing RTS0" refusal has no test. No fixture builds a DXBC container without an RTS0 part, and the suite passes with the check removed. Without the check, `container_parts[b"RTS0"]` raises `KeyError`. The outer handler catches that and exits 1, but with a bare `'RTS0'` message. Please add a case with a container that has no RTS0 and assert exit code 1 and the "missing RTS0" text on stderr. P3 - tools/probe_root_devices.py:33. `sys.getwindowsversion()` is called before the `try`, so the tool still fails with a traceback on non-Windows. The test file also needs it, so `probe_root_devices_check` only works on Windows. This is fine while it is registered only under `INTAKE_PYTHON`, but a short comment or a Windows-only guard in the test would make that explicit. - tools/probe_root_devices.py:82. `except ... TypeError` hides programming errors as "exit 1" messages. `KeyError` and `TypeError` are caught for malformed inventory input, which is the intent, so consider narrowing them to the inventory-reading block. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-24 22:01:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:56:26Z.


The locked-destination control failed on 93f8cee9: the old report survived but a temporary file was left behind. Cleanup now runs after both write and replace failures, and the test confirms the old report is preserved and no temporary file remains. All nine offline checks pass.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145590435 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1935#issuecomment-7145590435). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T21:56:26Z. --- The locked-destination control failed on `93f8cee9`: the old report survived but a temporary file was left behind. Cleanup now runs after both write and replace failures, and the test confirms the old report is preserved and no temporary file remains. All nine offline checks pass.
upstream-sync closed this pull request 2026-11-24 23:03:06 +00:00
Ammmae0x commented 2026-11-24 23:03:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T22:09:22Z.


Merged upstream/main (resolving the CMakeLists.txt conflict) and addressed the review feedback:

  • Added test_container_missing_rts0_exits_1_cleanly and test_malformed_inventory_entry_exits_1_cleanly in tests/probe_root_devices_check.py, confirming a container without RTS0 exits 1 with missing RTS0 on stderr.
  • Narrowed (KeyError, TypeError) handling in tools/probe_root_devices.py to six-apis.json entry parsing so missing RTS0 is handled exclusively by the explicit check, and documented the Windows-only sys.getwindowsversion() requirement in tests/probe_root_devices_check.py.
  • Verified probe_root_devices_check (11/11) and root_device_controls_warp in both dev and release, plus form_coverage_check.py, docs_links_check.py, and bidi_controls_check.py.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145875589 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1935#issuecomment-7145875589). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T22:09:22Z. --- Merged `upstream/main` (resolving the `CMakeLists.txt` conflict) and addressed the review feedback: - Added `test_container_missing_rts0_exits_1_cleanly` and `test_malformed_inventory_entry_exits_1_cleanly` in `tests/probe_root_devices_check.py`, confirming a container without `RTS0` exits `1` with `missing RTS0` on `stderr`. - Narrowed `(KeyError, TypeError)` handling in `tools/probe_root_devices.py` to `six-apis.json` entry parsing so missing `RTS0` is handled exclusively by the explicit check, and documented the Windows-only `sys.getwindowsversion()` requirement in `tests/probe_root_devices_check.py`. - Verified `probe_root_devices_check` (11/11) and `root_device_controls_warp` in both `dev` and `release`, plus `form_coverage_check.py`, `docs_links_check.py`, and `bidi_controls_check.py`. AI-assisted.
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!1928
No description provided.