ffx: harden ffx_working_set_delta validation and add unit suite #1941

Merged
Ammmae0x merged 3 commits from upstream-pr/1948 into main 2026-11-24 22:41:17 +00:00
Ammmae0x commented 2026-11-24 21:59:20 +00:00 (Migrated from github.com)

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


Change

Wrap tools/ffx_working_set_delta.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/ffx_working_set_delta_check.py (run via CMakeLists.txt as ffx_working_set_delta_check).

  • Positive controls (tests/ffx_working_set_delta_check.py): synthesizes an AMD64 PE32+ DLL exporting create_delta and release_delta with .pdata entries and verifies both generate(image, False) and main(argv) / subprocess CLI output.
  • Negative controls: verifies deterministic refusal (no tracebacks, no partial .cpp output) on --package SHA-256 mismatch, missing create_delta / release_delta exports, missing or multi-range .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 (ffx_working_set_delta_check registered as test #1224).
  • ctest --preset dev --no-tests=error -R "^(ffx_working_set_delta_check|ffx_create_context_check|ffx_dispatch_profile_check)$" -V: 3/3 passed (ffx_dispatch_profile_check 10 tests, ffx_create_context_check 6 tests, ffx_working_set_delta_check 7 tests).
  • ctest --preset release --no-tests=error -R "^(ffx_working_set_delta_check|ffx_create_context_check|ffx_dispatch_profile_check)$" -V: 3/3 passed.
  • python -B tests/ffx_working_set_delta_check.py -v: 7/7 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/ffx_working_set_delta_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:6592245750 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1948). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T21:59:20Z. --- ## Change Wrap `tools/ffx_working_set_delta.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/ffx_working_set_delta_check.py` (run via `CMakeLists.txt` as `ffx_working_set_delta_check`). - Positive controls (`tests/ffx_working_set_delta_check.py`): synthesizes an AMD64 PE32+ DLL exporting `create_delta` and `release_delta` with `.pdata` entries and verifies both `generate(image, False)` and `main(argv)` / subprocess CLI output. - Negative controls: verifies deterministic refusal (no tracebacks, no partial `.cpp` output) on `--package` SHA-256 mismatch, missing `create_delta` / `release_delta` exports, missing or multi-range `.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 (`ffx_working_set_delta_check` registered as test `#1224`). - `ctest --preset dev --no-tests=error -R "^(ffx_working_set_delta_check|ffx_create_context_check|ffx_dispatch_profile_check)$" -V`: `3/3` passed (`ffx_dispatch_profile_check` 10 tests, `ffx_create_context_check` 6 tests, `ffx_working_set_delta_check` 7 tests). - `ctest --preset release --no-tests=error -R "^(ffx_working_set_delta_check|ffx_create_context_check|ffx_dispatch_profile_check)$" -V`: `3/3` passed. - `python -B tests/ffx_working_set_delta_check.py -v`: `7/7` 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/ffx_working_set_delta_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:11 +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:12:15Z.


Ran the suite, broke four paths, all four caught

Windows 11 build 26300.9974:

out/pe-env/Scripts/python.exe -B tests/ffx_working_set_delta_check.py
Ran 7 tests in 3.233s
OK      exit 0

Mutations to tools/ffx_working_set_delta.py, each reverted:

mutation result
except (OSError, ValueError, pefile.PEFormatError) → except (KeyboardInterrupt,) caught
parser.exit(1, …) → parser.exit(0, …) caught
if args.output.suffix.lower() != ".cpp" or args.output.resolve() == args.image.resolve(): → if False: caught
the suffix half of that condition dropped, leaving only the aliasing half caught

The third and fourth are the ones I would have expected to slip, because they are refusals whose outcome (exit 1, no file
written) can be produced by a later error instead of the guard. Here they do not slip — and I think that is deliberate: the refusals
assert the message text, not only the exit code.

self.assertNotIn("Traceback", err)
self.assertIn("version-query profile", err)

That is the difference between "it failed" and "it failed for the reason the test is about". Compare with #1933, where the same-file
case passed with the guard removed because generate() raised a different error first; the two suites look alike but this one pins
the cause.

The positive control is not a smoke test either

generated = ffx_working_set_delta.generate(image, False)
self.assertIn("rcx = input; rdx = counters;", written)
self.assertIn("rax = static_cast<uint64_t>(static_cast<uint64_t>(rcx));", written)
self.assertIn("a + b", written)
self.assertIn("a - b", written)
self.assertIn("return rax;", written)

Five anchors, including both the + and - paths of the delta, so an inverted counter or a dropped subtraction in the emitter
would fail rather than producing plausible-looking C++.

What I did not do

I did not build the generated .cpp or link it against an upscaler image — FFX_UPSCALER_IMAGE is not set on this machine, so
the translated ranges and the --package hash path are only exercised through the synthetic PE. That matches what the description
scopes to a unit suite.

Verdict

Reviewed. The refusals are pinned by cause and the positive output by content; both are what the earlier hardening PRs in this
series were missing.

Notes

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145935887 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1948#issuecomment-7145935887). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T22:12:15Z. --- ## Ran the suite, broke four paths, all four caught Windows 11 build 26300.9974: ```powershell out/pe-env/Scripts/python.exe -B tests/ffx_working_set_delta_check.py Ran 7 tests in 3.233s OK exit 0 ``` Mutations to `tools/ffx_working_set_delta.py`, each reverted: | mutation | result | |---|---| | `except (OSError, ValueError, pefile.PEFormatError)` → `except (KeyboardInterrupt,)` | **caught** | | `parser.exit(1, …)` → `parser.exit(0, …)` | **caught** | | `if args.output.suffix.lower() != ".cpp" or args.output.resolve() == args.image.resolve():` → `if False:` | **caught** | | the suffix half of that condition dropped, leaving only the aliasing half | **caught** | The third and fourth are the ones I would have expected to slip, because they are refusals whose *outcome* (exit 1, no file written) can be produced by a later error instead of the guard. Here they do not slip — and I think that is deliberate: the refusals assert the message text, not only the exit code. ```python self.assertNotIn("Traceback", err) self.assertIn("version-query profile", err) ``` That is the difference between "it failed" and "it failed for the reason the test is about". Compare with #1933, where the same-file case passed with the guard removed because `generate()` raised a different error first; the two suites look alike but this one pins the cause. ## The positive control is not a smoke test either ```python generated = ffx_working_set_delta.generate(image, False) self.assertIn("rcx = input; rdx = counters;", written) self.assertIn("rax = static_cast<uint64_t>(static_cast<uint64_t>(rcx));", written) self.assertIn("a + b", written) self.assertIn("a - b", written) self.assertIn("return rax;", written) ``` Five anchors, including both the `+` and `-` paths of the delta, so an inverted counter or a dropped subtraction in the emitter would fail rather than producing plausible-looking C++. ## What I did not do I did not build the generated `.cpp` or link it against an upscaler image — `FFX_UPSCALER_IMAGE` is not set on this machine, so the translated ranges and the `--package` hash path are only exercised through the synthetic PE. That matches what the description scopes to a unit suite. ## Verdict Reviewed. The refusals are pinned by cause and the positive output by content; both are what the earlier hardening PRs in this series were missing. ## Notes - AI-assisted review.
R0Y00 commented 2026-11-24 23:03:40 +00:00 (Migrated from github.com)

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


Resolved the CMake registration conflict with main while preserving both Bink checks and the FFX working-set delta check. Windows Release CTest ran all three (3/3).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146462902 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1948#issuecomment-7146462902). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T22:38:01Z. --- Resolved the CMake registration conflict with main while preserving both Bink checks and the FFX working-set delta check. Windows Release CTest ran all three (3/3).
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!1941
No description provided.