ffx: extract main(argv), atomic output writes, and error guards in ffx_dispatch_profile with CLI suite #2375
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2383"
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-25T14:34:58Z.
Change
Harden
tools/ffx_dispatch_profile.pyfor programmatic and CLI use without changing its stdout summary format or.binpayload outputs:__main__block intomain(argv=None) -> intforwardingargvtoparser.parse_args(argv).output_directorycolliding withimagevia_same_path()(Path.resolve()equality andPath.samefile()for hardlinks/aliases) and reject an existing non-directory path before creating directories or writing files.<name>.binfile insidetempfile.TemporaryDirectory(dir=args.output_directory)and commit it withos.replace()so write/replace failures leave no partial.binfiles or leftover staging directories.(OSError, ValueError, struct.error, pefile.PEFormatError)cleanly viaparser.exit(1, ...)with no raw Python tracebacks.tests/ffx_dispatch_profile_cli_check.pyand registerffx_dispatch_profile_cli_checkinCMakeLists.txt.Verification
Verified on commit
1e18e8b2(rebased onupstream/maina31f70a1):out/pe-env/Scripts/python.exe -B tests/ffx_dispatch_profile_cli_check.py -v->Ran 9 tests in 0.909s - OK(exit 0)out/pe-env/Scripts/python.exe -B tests/ffx_dispatch_profile_check.py -v->Ran 10 tests in 0.217s - OK(exit 0)out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py->form coverage checks passed(exit 0)out/pe-env/Scripts/python.exe -B tests/docs_links_check.py->Self-test passed. Checked 19 Markdown files and 462 links.(exit 0)out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 1675 tracked source, script and build/CI files: no bidirectional controls.(exit 0)Spot mutation checks against
tools/ffx_dispatch_profile.py(8/8 killed bytests/ffx_dispatch_profile_cli_check.py, restored cleanly):argvforwarding, bypassresolve()collision check, bypasssamefile()collision check, remove non-directory check, bypassTemporaryDirectory+os.replace()staging, and individually dropstruct.error,pefile.PEFormatError, andOSErrorhandlers (all returned exit 1).Evidence and follow-up
tests/ffx_dispatch_profile_check.build_synthetic_pe()(MIT, repo-authored; no game files, dumps, or binaries).UPSCALERhash, invalid PE (pefile.PEFormatError), truncated data (struct.error), path collision via..alias and hardlink, existing regular file asoutput_directory, andos.replace()OSErrorleaving zero partial.binfiles or staging directories.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T14:46:48Z.
I found and fixed one output collision on this branch. A valid input can itself be named initializer.bin, so the generated file path can alias the input even when the output directory does not. The tool now checks all generated destinations before staging any output. The new synthetic test keeps the input bytes intact and verifies that no earlier program outputs are written. Both Windows suites passed, 20 cases total.