tooling: harden bink_descriptors_aot CLI and add unit suite #1943

Merged
Ammmae0x merged 2 commits from upstream-pr/1950 into main 2026-11-24 22:35:04 +00:00
Ammmae0x commented 2026-11-24 22:01:55 +00:00 (Migrated from github.com)

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


Change

Wrap tools/bink_descriptors_aot.py CLI execution in an explicit main(argv=None) entry point that exits cleanly (status 1, no Python traceback) on OSError, ValueError, and pefile.PEFormatError, and register a synthetic AMD64 PE32+ unit and refusal suite in tests/bink_descriptors_aot_check.py (run via CMakeLists.txt as bink_descriptors_aot_check).

  • Positive controls (tests/bink_descriptors_aot_check.py): synthesizes an AMD64 PE32+ DLL exporting group_init, group_append (with one int3 capacity breakpoint), and frame_planes (with five call r9 sites and .pdata unwind metadata) to verify generate(package=False, frame_planes=False/True), frame_body(..., bind_group=False/True), and main(argv) / subprocess CLI output.
  • Negative controls: verifies deterministic refusal (no tracebacks, no partial .cpp output) on missing (0) or duplicate (2) int3 sites in group_append, != 5 (0, 4, 6) call r9 sites in frame_planes, --package SHA-256 mismatch against BINK_SHA256, missing frame_planes export or .pdata, non-AMD64 / non-PE32+ images, non-.cpp or input-aliasing output paths, and missing/corrupt input files.

AI-assisted.

Verification

  • ctest --preset dev -N and ctest --preset release -N: 1238 total tests in both presets (bink_descriptors_aot_check registered as test #1224).
  • Built cpu_bink_heap_provider, cpu_bink_heap, cpu_bink_heap_lifted, cpu_bink_descriptors, cpu_bink_descriptors_lifted in both dev and release (0 errors).
  • ctest --preset dev --no-tests=error -R "^(bink_descriptors_aot_check|bink_heap_aot_check|cpu_aot_bink_heap|cpu_aot_bink_group|cpu_bink_descriptors|cpu_bink_frame_planes)$" -V: 6/6 passed (cpu_aot_bink_heap, cpu_aot_bink_group, cpu_bink_descriptors, cpu_bink_frame_planes, bink_heap_aot_check 12 tests, bink_descriptors_aot_check 9 tests).
  • ctest --preset release --no-tests=error -R "^(bink_descriptors_aot_check|bink_heap_aot_check|cpu_aot_bink_heap|cpu_aot_bink_group|cpu_bink_descriptors|cpu_bink_frame_planes)$" -V: 6/6 passed.
  • python -B tests/bink_descriptors_aot_check.py -v: 9/9 tests passed.
  • python -B tests/form_coverage_check.py, python -B tests/docs_links_check.py, and python -B tests/bidi_controls_check.py: all exited 0.

Evidence and follow-up

All fixtures in tests/bink_descriptors_aot_check.py are constructed synthetically in memory with zero external or game-specific inputs.

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:6592283988 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1950). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T22:01:55Z. --- ## Change Wrap `tools/bink_descriptors_aot.py` CLI execution in an explicit `main(argv=None)` entry point that exits cleanly (status `1`, no Python traceback) on `OSError`, `ValueError`, and `pefile.PEFormatError`, and register a synthetic AMD64 PE32+ unit and refusal suite in `tests/bink_descriptors_aot_check.py` (run via `CMakeLists.txt` as `bink_descriptors_aot_check`). - Positive controls (`tests/bink_descriptors_aot_check.py`): synthesizes an AMD64 PE32+ DLL exporting `group_init`, `group_append` (with one `int3` capacity breakpoint), and `frame_planes` (with five `call r9` sites and `.pdata` unwind metadata) to verify `generate(package=False, frame_planes=False/True)`, `frame_body(..., bind_group=False/True)`, and `main(argv)` / subprocess CLI output. - Negative controls: verifies deterministic refusal (no tracebacks, no partial `.cpp` output) on missing (`0`) or duplicate (`2`) `int3` sites in `group_append`, `!= 5` (`0`, `4`, `6`) `call r9` sites in `frame_planes`, `--package` SHA-256 mismatch against `BINK_SHA256`, missing `frame_planes` export or `.pdata`, non-AMD64 / non-PE32+ images, non-`.cpp` or input-aliasing output paths, and missing/corrupt input files. AI-assisted. ## Verification - `ctest --preset dev -N` and `ctest --preset release -N`: `1238` total tests in both presets (`bink_descriptors_aot_check` registered as test `#1224`). - Built `cpu_bink_heap_provider`, `cpu_bink_heap`, `cpu_bink_heap_lifted`, `cpu_bink_descriptors`, `cpu_bink_descriptors_lifted` in both `dev` and `release` (`0` errors). - `ctest --preset dev --no-tests=error -R "^(bink_descriptors_aot_check|bink_heap_aot_check|cpu_aot_bink_heap|cpu_aot_bink_group|cpu_bink_descriptors|cpu_bink_frame_planes)$" -V`: `6/6` passed (`cpu_aot_bink_heap`, `cpu_aot_bink_group`, `cpu_bink_descriptors`, `cpu_bink_frame_planes`, `bink_heap_aot_check` 12 tests, `bink_descriptors_aot_check` 9 tests). - `ctest --preset release --no-tests=error -R "^(bink_descriptors_aot_check|bink_heap_aot_check|cpu_aot_bink_heap|cpu_aot_bink_group|cpu_bink_descriptors|cpu_bink_frame_planes)$" -V`: `6/6` passed. - `python -B tests/bink_descriptors_aot_check.py -v`: `9/9` tests passed. - `python -B tests/form_coverage_check.py`, `python -B tests/docs_links_check.py`, and `python -B tests/bidi_controls_check.py`: all exited `0`. ## Evidence and follow-up All fixtures in `tests/bink_descriptors_aot_check.py` are constructed synthetically in memory with zero external or game-specific inputs. ## 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.
upstream-sync closed this pull request 2026-11-24 23:03:12 +00:00
ChazY11 commented 2026-11-24 23:03:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T22:17:53Z.


Ran it and broke eight paths — all caught, including the generator guards the description claims

Windows 11 build 26300.9974:

out/pe-env/Scripts/python.exe -B tests/bink_descriptors_aot_check.py
Ran 9 tests in 3.336s
OK      exit 0

CLI side (main() and its guard), each reverted:

mutation result
except (OSError, ValueError, pefile.PEFormatError) → except (KeyboardInterrupt,) caught
parser.exit(1, …) → parser.exit(0, …) caught
the suffix half of the output guard dropped caught
the aliasing half of the output guard dropped caught
the whole output guard → if False: caught

That the two halves fail separately is the thing I check first in this family of PRs, because in #1933 the same-file case passed
with its guard removed (a later generate() error produced the same exit code). Here either half on its own fails the suite, so
the message text must be asserted, not just the status.

The generator's own refusals are pinned too

The description lists refusals that live in generate(), not in the CLI, so I mutated those as well:

mutation in tools/bink_descriptors_aot.py result
if len(calls) != 5: → if False: (frame plane sites) caught
if len(stops) != 1: → if False: (capacity breakpoint) caught
checked_image(image, BINK_SHA256) if package → plain pefile.PE(...) (hash check skipped) caught

The third is the one worth having: a --package run that stops verifying BINK_SHA256 would still produce plausible output, and
only a test that feeds a mismatching hash and requires a refusal notices.

One observation, not a defect

The synthetic image reproduces the exact counts the tool demands (one int3, five call r9), which is what makes the negative
controls meaningful — a 4- or 6-site image must be refused. If the real package ever changes those counts, this suite will refuse
it loudly rather than silently translating a different shape, which is the correct failure direction for an AOT generator.

What I did not do

Nothing was linked or run against the real package: BINK_SHA256 and the image are synthetic here. That matches the description's
scope, and the honest limitation is the same one the earlier PRs in this series carry — the translated ranges are only exercised
through a fabricated PE.

Verdict

Reviewed. Eight mutations, eight failures, and both the CLI boundary and the generator's refusals are covered by the new suite.

Notes

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146056057 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1950#issuecomment-7146056057). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T22:17:53Z. --- ## Ran it and broke eight paths — all caught, including the generator guards the description claims Windows 11 build 26300.9974: ```powershell out/pe-env/Scripts/python.exe -B tests/bink_descriptors_aot_check.py Ran 9 tests in 3.336s OK exit 0 ``` CLI side (`main()` and its guard), each reverted: | mutation | result | |---|---| | `except (OSError, ValueError, pefile.PEFormatError)` → `except (KeyboardInterrupt,)` | **caught** | | `parser.exit(1, …)` → `parser.exit(0, …)` | **caught** | | the suffix half of the output guard dropped | **caught** | | the aliasing half of the output guard dropped | **caught** | | the whole output guard → `if False:` | **caught** | That the two halves fail *separately* is the thing I check first in this family of PRs, because in #1933 the same-file case passed with its guard removed (a later `generate()` error produced the same exit code). Here either half on its own fails the suite, so the message text must be asserted, not just the status. ## The generator's own refusals are pinned too The description lists refusals that live in `generate()`, not in the CLI, so I mutated those as well: | mutation in `tools/bink_descriptors_aot.py` | result | |---|---| | `if len(calls) != 5:` → `if False:` (frame plane sites) | **caught** | | `if len(stops) != 1:` → `if False:` (capacity breakpoint) | **caught** | | `checked_image(image, BINK_SHA256) if package` → plain `pefile.PE(...)` (hash check skipped) | **caught** | The third is the one worth having: a `--package` run that stops verifying `BINK_SHA256` would still produce plausible output, and only a test that feeds a mismatching hash and requires a refusal notices. ## One observation, not a defect The synthetic image reproduces the exact counts the tool demands (one `int3`, five `call r9`), which is what makes the *negative* controls meaningful — a 4- or 6-site image must be refused. If the real package ever changes those counts, this suite will refuse it loudly rather than silently translating a different shape, which is the correct failure direction for an AOT generator. ## What I did not do Nothing was linked or run against the real package: `BINK_SHA256` and the image are synthetic here. That matches the description's scope, and the honest limitation is the same one the earlier PRs in this series carry — the translated ranges are only exercised through a fabricated PE. ## Verdict Reviewed. Eight mutations, eight failures, and both the CLI boundary and the generator's refusals are covered by the new suite. ## Notes - AI-assisted review.
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!1943
No description provided.