textures: extract main(argv), atomic manifest writes, and path/JSON/bounds guards in ttpf_batch_export with CLI suite #2550
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2558"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T20:53:22Z.
Change
Harden
tools/ttpf_batch_export.pyCLI 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 asttpf_batch_export_cli_checkinCMakeLists.txt):main(argv: list[str] | None = None) -> intto forwardargvtoparser.parse_args(argv)and return0, invokingraise SystemExit(main())underif __name__ == "__main__".batch_export()that--threads >= 1,--start >= 0,--count >= 0,poolis a regular file,--outis not an existing non-directory or colliding withpool, and--manifestis not an existing directory, does not collide withpoolor--out(_same_path()viaresolve()andsamefile()), and is not an ancestor of--out.--history,--calibration, and--tools-pathupfront against directories, missing paths,OSError,json.JSONDecodeError, non-object JSON, and unsupported calibration versions before creating output directories or opening the pool.manifest_pathatomically viatempfile.TemporaryDirectory(dir=path.parent)+os.replace()(_atomic_write_text()) so failures leave zero temporary directories or partial manifests and preserve pre-existing manifests.(RuntimeError, OSError, ValueError, struct.error, json.JSONDecodeError)inmain()viaparser.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 ontoupstream/maind82d5871) usingout\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.)tools/ttpf_batch_export.py(_same_pathresolve()/samefile(),--threads < 1->< 0,--start < 0,--count < 0,poolregular-file,--outnon-dir,--manifestdir/pool/out/ancestor guards,--historyJSON object guard,struct.errorguard, atomic manifest staging write) causedtests/ttpf_batch_export_cli_check.pyto fail (exit 1).Evidence and follow-up
tests/ttpf_batch_export_cli_check.pyare synthetic in-memoryttpf_mips.pymodules and minimalRDS5/BADSTRUCTplaceholder files generated insideTemporaryDirectory()under the repository MIT License.pool, regular-file--out,--threads <= 0,--start < 0,--count < 0, existing-directory/colliding/ancestor--manifest(resolve()and hardlinksamefile()), directory/malformed/non-dict/missing--historyand--calibration, missing/non-directory--tools-path,struct.errorduring pool parsing,os.replace()OSErrorleaving zero temp dirs and preserving prior manifests, and missing required CLI arguments (Python 3.14argparse-compatible checks).Checklist
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-pathbefore creating output dirs or opening the pool.out_dir.mkdirwas moved after pool open, so failures leave no stray directories.os.replace(); pre-existing manifests survive failures.tests/ttpf_batch_export_check.pystill 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 OKpython3 -B tests/ttpf_batch_export_check.py-> OK (skipped=1)python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleanthreads < 1guard -> new suite fails (2 failures, 2 errors)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.
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:tests/ttpf_batch_export_check.pyok (1.1s)15.6sNote: 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.
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:--preset dev):cmake --build --preset dev -- -j 2):23.10s(configure1.81s)ctest --preset dev -R 'ttpf_batch_export' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (2.98s:ttpf_batch_export1.35s,ttpf_batch_export_cli_check2.87s)/O2(--preset release):cmake --build --preset release -- -j 2):22.28s(configure1.80s)ctest --preset release -R 'ttpf_batch_export' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (2.63s:ttpf_batch_export1.11s,ttpf_batch_export_cli_check2.53s)tests/ttpf_batch_export_check.pyok (1.1s)sccache: 378/380 hits; wall62.2sAI-assisted; commands listed were executed locally.