runtime: harden bink_frame_aot CLI with atomic writes and add CLI suite #2680

Merged
Ammmae0x merged 2 commits from upstream-pr/2688 into main 2026-11-26 03:46:20 +00:00
Ammmae0x commented 2026-11-26 02:04:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T02:04:42Z.


Change

Harden CLI path validation and atomic output writing in tools/bink_frame_aot.py and add a pure-Python CLI suite (tests/bink_frame_aot_cli_check.py), registered in CMakeLists.txt as runtime_bink_frame_aot_cli_check.

  • Validate upfront in _validate_args() that image exists and is a regular file (not a directory), and that output has a .cpp suffix, is not a symlink, directory, under a non-directory parent/ancestor, or resolve()/samefile() equal to image before calling generate().
  • Replace direct write_text() with sibling-temp _write_atomic() creating missing parent directories and unlinking temp files on all errors, while preserving clean stderr output and non-zero exit codes with zero raw tracebacks.
  • Preserve existing generate() behavior and tests/bink_frame_aot_check.py unchanged.

Verification

Verified on commit 332b627b (based on upstream/main 572723f9) on Windows using out/pe-env/Scripts/python.exe -B:

  • out\pe-env\Scripts\python.exe -B tests\bink_frame_aot_check.py -> exit 0 (7/7 OK).
  • out\pe-env\Scripts\python.exe -B tests\bink_frame_aot_cli_check.py -> exit 0 (7/7 tests OK, 0 skips: atomic .cpp in nested dirs & overwrite with 0 .tmp, argv=None / __main__, missing/dir/corrupt/unmatched-hash image, output dir/symlink/file-parent/samefile/hardlink/non-.cpp guards, os.replace failure preserving target bytes, Python 3.14-safe argparse checks, and 4 fast in-memory mutations).
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py, tests\docs_links_check.py, tests\bidi_controls_check.py -> all exit 0.
  • On-disk spot-mutation negative controls (3/3 killed by tests/bink_frame_aot_cli_check.py): disabling output.is_symlink() guard, disabling samefile() hardlink collision check, and disabling .tmp unlink cleanup on replace failure.

Evidence and follow-up

  • Pure-Python synthetic placeholder images and mocked generate() output in temporary directories (MIT License; no game files or binaries).
  • No external tools or GPU hardware required.

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.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6617885249 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2688). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T02:04:42Z. --- ## Change Harden CLI path validation and atomic output writing in `tools/bink_frame_aot.py` and add a pure-Python CLI suite (`tests/bink_frame_aot_cli_check.py`), registered in `CMakeLists.txt` as `runtime_bink_frame_aot_cli_check`. - Validate upfront in `_validate_args()` that `image` exists and is a regular file (not a directory), and that `output` has a `.cpp` suffix, is not a symlink, directory, under a non-directory parent/ancestor, or `resolve()`/`samefile()` equal to `image` before calling `generate()`. - Replace direct `write_text()` with sibling-temp `_write_atomic()` creating missing parent directories and unlinking temp files on all errors, while preserving clean stderr output and non-zero exit codes with zero raw tracebacks. - Preserve existing `generate()` behavior and `tests/bink_frame_aot_check.py` unchanged. ## Verification Verified on commit `332b627b` (based on `upstream/main` `572723f9`) on Windows using `out/pe-env/Scripts/python.exe -B`: - `out\pe-env\Scripts\python.exe -B tests\bink_frame_aot_check.py` -> exit 0 (7/7 OK). - `out\pe-env\Scripts\python.exe -B tests\bink_frame_aot_cli_check.py` -> exit 0 (7/7 tests OK, 0 skips: atomic `.cpp` in nested dirs & overwrite with 0 `.tmp`, `argv=None` / `__main__`, missing/dir/corrupt/unmatched-hash image, output dir/symlink/file-parent/samefile/hardlink/non-`.cpp` guards, `os.replace` failure preserving target bytes, Python 3.14-safe argparse checks, and 4 fast in-memory mutations). - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py`, `tests\docs_links_check.py`, `tests\bidi_controls_check.py` -> all exit 0. - On-disk spot-mutation negative controls (3/3 killed by `tests/bink_frame_aot_cli_check.py`): disabling `output.is_symlink()` guard, disabling `samefile()` hardlink collision check, and disabling `.tmp` unlink cleanup on replace failure. ## Evidence and follow-up - Pure-Python synthetic placeholder images and mocked `generate()` output in temporary directories (MIT License; no game files or binaries). - No external tools or GPU hardware required. ## 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. AI-assisted.
upstream-sync closed this pull request 2026-11-26 04:04:21 +00:00
tedin7 commented 2026-11-26 04:04:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:26:18Z.

Review: COMMENTED


Review of head 786f3aff (after update with main).

Looks sound. Args are validated before generate(), output is written through a sibling temp file and replaced atomically, temp files are removed on error, and exit codes/messages stay clean. generate() is unchanged. The new runtime_bink_frame_aot_cli_check test is registered next to bink_frame_aot_check. #1968 (merged) covers anchor validation only; no other open PR covers this CLI slice.

Commands run (Linux):

  • tests/bink_frame_aot_cli_check.py -> 7 tests OK
  • tests/bink_frame_aot_check.py -> 7 tests OK
  • docs_links_check.py OK, bidi_controls_check.py OK, git diff --check clean
  • Mutation: disable the output symlink guard -> new suite fails (2 failures)
  • Mutation: disable temp-file cleanup -> new suite fails (2 failures)

Minor note, not blocking: output is now written with newline="\n", so files on Windows no longer get CRLF. Harmless for a compiled .cpp.

Windows WARP run follows separately.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068152281 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2688#pullrequestreview-6068152281). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:26:18Z. **Review:** COMMENTED --- Review of head 786f3aff (after update with main). Looks sound. Args are validated before generate(), output is written through a sibling temp file and replaced atomically, temp files are removed on error, and exit codes/messages stay clean. generate() is unchanged. The new runtime_bink_frame_aot_cli_check test is registered next to bink_frame_aot_check. #1968 (merged) covers anchor validation only; no other open PR covers this CLI slice. Commands run (Linux): - tests/bink_frame_aot_cli_check.py -> 7 tests OK - tests/bink_frame_aot_check.py -> 7 tests OK - docs_links_check.py OK, bidi_controls_check.py OK, git diff --check clean - Mutation: disable the output symlink guard -> new suite fails (2 failures) - Mutation: disable temp-file cleanup -> new suite fails (2 failures) Minor note, not blocking: output is now written with newline="\n", so files on Windows no longer get CRLF. Harmless for a compiled .cpp. Windows WARP run follows separately. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:45:40Z.


Win2025 WARP receipt for head 786f3aff after updating with main.

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 542.00s (configure 4.13s)
    • Test (ctest --preset dev -R 'bink_frame_aot' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (6.45s: bink_frame_aot_check 2.34s, runtime_bink_frame_aot_cli_check 6.29s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 580.39s (configure 4.42s)
    • Test (ctest --preset release -R 'bink_frame_aot' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (5.14s: bink_frame_aot_check 1.98s, runtime_bink_frame_aot_cli_check 5.03s)
  • sccache: 36/2447 hits; wall 1148.4s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182000101 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2688#issuecomment-7182000101). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:45:40Z. --- Win2025 WARP receipt for head 786f3aff after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `786f3aff28f37ca59bbb583682677802f9083431`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `542.00s` (configure `4.13s`) - Test (`ctest --preset dev -R 'bink_frame_aot' --parallel 6 --no-tests=error --output-on-failure`): **2/2 passed** (`6.45s`: `bink_frame_aot_check` `2.34s`, `runtime_bink_frame_aot_cli_check` `6.29s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `580.39s` (configure `4.42s`) - Test (`ctest --preset release -R 'bink_frame_aot' --parallel 6 --no-tests=error --output-on-failure`): **2/2 passed** (`5.14s`: `bink_frame_aot_check` `1.98s`, `runtime_bink_frame_aot_cli_check` `5.03s`) - `sccache`: 36/2447 hits; wall `1148.4s` 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!2680
No description provided.