textures: extract main(argv), atomic manifest writes, and path/JSON/bounds guards in ttpf_batch_export with CLI suite #2550

Merged
Ammmae0x merged 1 commit from upstream-pr/2558 into main 2026-11-25 20:59:07 +00:00
Ammmae0x commented 2026-11-25 20:53:22 +00:00 (Migrated from github.com)

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


Change

Harden tools/ttpf_batch_export.py CLI argument/path/JSON validation and manifest publishing, and add a standalone pure-Python CLI/mutation test suite (tests/ttpf_batch_export_cli_check.py, registered as ttpf_batch_export_cli_check in CMakeLists.txt):

  • Update main(argv: list[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 in batch_export() that --threads >= 1, --start >= 0, --count >= 0, pool is a regular file, --out is not an existing non-directory or colliding with pool, and --manifest is not an existing directory, does not collide with pool or --out (_same_path() via resolve() and samefile()), and is not an ancestor of --out.
  • Validate --history, --calibration, and --tools-path upfront against directories, missing paths, OSError, json.JSONDecodeError, non-object JSON, and unsupported calibration versions before creating output directories or opening the pool.
  • Publish manifest_path atomically via tempfile.TemporaryDirectory(dir=path.parent) + os.replace() (_atomic_write_text()) so failures leave zero temporary directories or partial manifests and preserve pre-existing manifests.
  • Guard (RuntimeError, OSError, ValueError, struct.error, json.JSONDecodeError) in main() via parser.error(str(exc)) (exit code 2, zero raw tracebacks) while preserving the exact JSON summary stdout schema.

AI-assisted.

Verification

Verified on commit 24898e8dd9202ad7f2815d056f9c5007ed8c1921 (rebased onto upstream/main d82d5871) using out\pe-env\Scripts\python.exe -B:

  • out\pe-env\Scripts\python.exe -B tests/ttpf_batch_export_cli_check.py -v -> exit 0 (Ran 9 tests in 4.189s, OK)
  • out\pe-env\Scripts\python.exe -B tests/ttpf_batch_export_check.py -v -> exit 0 (Ran 13 tests in 1.427s, OK; 12 passed, 1 skipped: test_real_exporter_dds_and_pixel_verification — optional local ttpf tools directory)
  • 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 486 links.)
  • out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py -> exit 0 (Self-test passed. Checked 1789 tracked source, script and build/CI files: no bidirectional controls.)
  • Spot mutation check: 14/14 targeted mutations in tools/ttpf_batch_export.py (_same_path resolve()/samefile(), --threads < 1 -> < 0, --start < 0, --count < 0, pool regular-file, --out non-dir, --manifest dir/pool/out/ancestor guards, --history JSON object guard, struct.error guard, atomic manifest staging write) caused tests/ttpf_batch_export_cli_check.py to fail (exit 1).

Evidence and follow-up

  • New fixtures in tests/ttpf_batch_export_cli_check.py are synthetic in-memory ttpf_mips.py modules and minimal RDS5/BADSTRUCT placeholder files generated inside TemporaryDirectory() under the repository MIT License.
  • Negative controls cover missing/directory pool, regular-file --out, --threads <= 0, --start < 0, --count < 0, existing-directory/colliding/ancestor --manifest (resolve() and hardlink samefile()), directory/malformed/non-dict/missing --history and --calibration, missing/non-directory --tools-path, struct.error during pool parsing, os.replace() OSError leaving zero temp dirs and preserving prior manifests, and missing required CLI arguments (Python 3.14 argparse-compatible checks).

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:6613540842 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2558). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T20:53:22Z. --- ## Change Harden `tools/ttpf_batch_export.py` CLI argument/path/JSON validation and manifest publishing, and add a standalone pure-Python CLI/mutation test suite (`tests/ttpf_batch_export_cli_check.py`, registered as `ttpf_batch_export_cli_check` in `CMakeLists.txt`): - Update `main(argv: list[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 in `batch_export()` that `--threads >= 1`, `--start >= 0`, `--count >= 0`, `pool` is a regular file, `--out` is not an existing non-directory or colliding with `pool`, and `--manifest` is not an existing directory, does not collide with `pool` or `--out` (`_same_path()` via `resolve()` and `samefile()`), and is not an ancestor of `--out`. - Validate `--history`, `--calibration`, and `--tools-path` upfront against directories, missing paths, `OSError`, `json.JSONDecodeError`, non-object JSON, and unsupported calibration versions before creating output directories or opening the pool. - Publish `manifest_path` atomically via `tempfile.TemporaryDirectory(dir=path.parent)` + `os.replace()` (`_atomic_write_text()`) so failures leave zero temporary directories or partial manifests and preserve pre-existing manifests. - Guard `(RuntimeError, OSError, ValueError, struct.error, json.JSONDecodeError)` in `main()` via `parser.error(str(exc))` (exit code 2, zero raw tracebacks) while preserving the exact JSON summary stdout schema. AI-assisted. ## Verification Verified on commit `24898e8dd9202ad7f2815d056f9c5007ed8c1921` (rebased onto `upstream/main` `d82d5871`) using `out\pe-env\Scripts\python.exe -B`: - `out\pe-env\Scripts\python.exe -B tests/ttpf_batch_export_cli_check.py -v` -> exit 0 (`Ran 9 tests in 4.189s`, `OK`) - `out\pe-env\Scripts\python.exe -B tests/ttpf_batch_export_check.py -v` -> exit 0 (`Ran 13 tests in 1.427s`, `OK`; 12 passed, 1 skipped: `test_real_exporter_dds_and_pixel_verification` — optional local ttpf tools directory) - `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 486 links.`) - `out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py` -> exit 0 (`Self-test passed. Checked 1789 tracked source, script and build/CI files: no bidirectional controls.`) - Spot mutation check: 14/14 targeted mutations in `tools/ttpf_batch_export.py` (`_same_path` `resolve()`/`samefile()`, `--threads < 1` -> `< 0`, `--start < 0`, `--count < 0`, `pool` regular-file, `--out` non-dir, `--manifest` dir/pool/out/ancestor guards, `--history` JSON object guard, `struct.error` guard, atomic manifest staging write) caused `tests/ttpf_batch_export_cli_check.py` to fail (exit 1). ## Evidence and follow-up - New fixtures in `tests/ttpf_batch_export_cli_check.py` are synthetic in-memory `ttpf_mips.py` modules and minimal `RDS5`/`BADSTRUCT` placeholder files generated inside `TemporaryDirectory()` under the repository MIT License. - Negative controls cover missing/directory `pool`, regular-file `--out`, `--threads <= 0`, `--start < 0`, `--count < 0`, existing-directory/colliding/ancestor `--manifest` (`resolve()` and hardlink `samefile()`), directory/malformed/non-dict/missing `--history` and `--calibration`, missing/non-directory `--tools-path`, `struct.error` during pool parsing, `os.replace()` `OSError` leaving zero temp dirs and preserving prior manifests, and missing required CLI arguments (Python 3.14 `argparse`-compatible checks). ## 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:28 +00:00
tedin7 commented 2026-11-25 21:01:28 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 24898e8d (code + tests only, no Windows run in this review).

Checked:

  • main(argv) now forwards argv and returns 0; batch_export() validates threads/start/count, pool/out/manifest collisions and ancestor case, and --history/--calibration/--tools-path before creating output dirs or opening the pool. out_dir.mkdir was moved after pool open, so failures leave no stray directories.
  • Manifest is now published through a staging temp dir + os.replace(); pre-existing manifests survive failures.
  • Sibling suite tests/ttpf_batch_export_check.py still passes (13 tests, 1 skipped). No other open or merged PR touches the same slice (only #798 and #813, both merged and earlier).

Commands run locally on the exact head:

  • python3 tests/ttpf_batch_export_cli_check.py -> 9 tests OK
  • python3 -B tests/ttpf_batch_export_check.py -> OK (skipped=1)
  • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py -> OK
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: disable the threads < 1 guard -> new suite fails (2 failures, 2 errors)
  • Mutation 2: replace os.replace(staged, path) with a direct write -> new suite fails (2 failures)

No blocking findings. The change is Python tooling only and does not claim any startup behavior.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6064878964 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2558#pullrequestreview-6064878964). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:57:03Z. **Review:** COMMENTED --- Review of head 24898e8d (code + tests only, no Windows run in this review). Checked: - `main(argv)` now forwards argv and returns 0; `batch_export()` validates threads/start/count, pool/out/manifest collisions and ancestor case, and `--history`/`--calibration`/`--tools-path` before creating output dirs or opening the pool. `out_dir.mkdir` was moved after pool open, so failures leave no stray directories. - Manifest is now published through a staging temp dir + `os.replace()`; pre-existing manifests survive failures. - Sibling suite `tests/ttpf_batch_export_check.py` still passes (13 tests, 1 skipped). No other open or merged PR touches the same slice (only #798 and #813, both merged and earlier). Commands run locally on the exact head: - `python3 tests/ttpf_batch_export_cli_check.py` -> 9 tests OK - `python3 -B tests/ttpf_batch_export_check.py` -> OK (skipped=1) - `python3 tests/docs_links_check.py`, `python3 tests/bidi_controls_check.py` -> OK - `git diff --check origin/main...HEAD` -> clean - Mutation 1: disable the `threads < 1` guard -> new suite fails (2 failures, 2 errors) - Mutation 2: replace `os.replace(staged, path)` with a direct write -> new suite fails (2 failures) No blocking findings. The change is Python tooling only and does not claim any startup behavior. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 21:01:35 +00:00 (Migrated from github.com)

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


Win2025 WARP receipt for head 24898e8d.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 24898e8dd9202ad7f2815d056f9c5007ed8c1921:

  • Windows Python checks: tests/ttpf_batch_export_check.py ok (1.1s)
  • Wall: 15.6s

Note: the auto-selected Windows Python check was the sibling suite; the new CLI suite was run on Linux (9 tests OK).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7174419271 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2558#issuecomment-7174419271). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:57:33Z. --- Win2025 WARP receipt for head 24898e8d. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `24898e8dd9202ad7f2815d056f9c5007ed8c1921`: - **Windows Python checks**: `tests/ttpf_batch_export_check.py` ok (`1.1s`) - Wall: `15.6s` Note: the auto-selected Windows Python check was the sibling suite; the new CLI suite was run on Linux (9 tests OK). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 21:01:35 +00:00 (Migrated from github.com)

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


Win2025 WARP receipt for head 24898e8d.

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 23.10s (configure 1.81s)
    • Test (ctest --preset dev -R 'ttpf_batch_export' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (2.98s: ttpf_batch_export 1.35s, ttpf_batch_export_cli_check 2.87s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 22.28s (configure 1.80s)
    • Test (ctest --preset release -R 'ttpf_batch_export' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (2.63s: ttpf_batch_export 1.11s, ttpf_batch_export_cli_check 2.53s)
  • Windows Python checks: tests/ttpf_batch_export_check.py ok (1.1s)
  • sccache: 378/380 hits; wall 62.2s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7174449322 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2558#issuecomment-7174449322). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:58:55Z. --- Win2025 WARP receipt for head 24898e8d. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `24898e8dd9202ad7f2815d056f9c5007ed8c1921`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `23.10s` (configure `1.81s`) - Test (`ctest --preset dev -R 'ttpf_batch_export' --parallel 6 --no-tests=error --output-on-failure`): **2/2 passed** (`2.98s`: `ttpf_batch_export` `1.35s`, `ttpf_batch_export_cli_check` `2.87s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `22.28s` (configure `1.80s`) - Test (`ctest --preset release -R 'ttpf_batch_export' --parallel 6 --no-tests=error --output-on-failure`): **2/2 passed** (`2.63s`: `ttpf_batch_export` `1.11s`, `ttpf_batch_export_cli_check` `2.53s`) - **Windows Python checks**: `tests/ttpf_batch_export_check.py` ok (`1.1s`) - `sccache`: 378/380 hits; wall `62.2s` 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!2550
No description provided.