ffx: add clean CLI error handling in ffx_create_context and unit and refusal suite #1903
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1910"
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-24T20:53:13Z.
Change
Add clean CLI error handling to
tools/ffx_create_context.pyand add a synthetic AMD64 PE32+ unit and refusal suite intests/ffx_create_context_check.pyregistered asffx_create_context_checkinCMakeLists.txt:main(argv=None)intools/ffx_create_context.pyand wrap output validation andgenerate(args.loader)soOSError,ValueError, andpefile.PEFormatErrorexit cleanly viaparser.exit(1, ...)instead of emitting raw tracebacks.create_source()andgenerate()lowering contracts (null-host/allocator/zero-alloc checks returning6,host->table->createoutput slot handling, and allocation-failurehost->table->destroyrollback returning5).tests/ffx_create_context_check.pywith positive controls (create_source()guards/rollback and synthetic PE32+generate()/main()emission) and refusal controls (missing loader file, non-PE input with both unpatched and patched digest, SHA-256 profile mismatch, non-.cppoutput suffix, and matching loader/output paths).Verification
python -B tests/ffx_create_context_check.py -v:Ran 6 tests in 3.046s—OK.cmake --preset dev+ctest --preset dev --no-tests=error -R "^ffx_create_context_check$" -V:1/1passed (Ran 6 tests in 2.940s,3.63 sec); pre-rebase sibling smoke runctest --preset dev --no-tests=error -R "^(ffx_create_context_check|ffx_provider_loop_warp|ffx_device_init_warp|ffx_recurrent_warp)$" --output-on-failurepassed4/4.cmake --preset release+ctest --preset release --no-tests=error -R "^ffx_create_context_check$" -V:1/1passed (Ran 6 tests in 3.031s,3.68 sec); pre-rebase sibling smoke runctest --preset release --no-tests=error -R "^(ffx_create_context_check|ffx_provider_loop_warp|ffx_device_init_warp|ffx_recurrent_warp)$" --output-on-failurepassed4/4.python -B tests/form_coverage_check.py: passed.python -B tests/docs_links_check.py: passed (Checked 18 Markdown files and 377 links.).python -B tests/bidi_controls_check.py: passed (Checked 1339 tracked source, script and build/CI files: no bidirectional controls.).Evidence and follow-up
tests/ffx_create_context_check.pybuilds minimal in-memory synthetic AMD64 PE32+ binaries withstructand patchesffx_create_context.LOADERin unit tests; no external binaries or proprietary files are used.try/except (OSError, ValueError, pefile.PEFormatError)wrapper inmain()confirmedtest_non_pe_input_exits_cleanlyfails with an unhandledpefile.PEFormatError.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:57:34Z.
Review: COMMENTED
Review of #1910 at exact head
1d1f638bcdf6305ac7e0e1a50f90aede22960062(checked out frompull/1910/head, HEAD equals currentheadRefOid; merge-base is behind currentmainbutgit merge-treeshows no conflicts).Verdict: no P1/P2 found. Comment only, not an approval.
What I checked
tools/ffx_create_context.py(+14/-5, only the CLI entry is wrapped intomain(argv);generate/create_sourceuntouched),CMakeLists.txt(+2, oneadd_testinside the existingif(EXISTS "${INTAKE_PYTHON}")block),tests/ffx_create_context_check.py(new).parser.errorraisesSystemExitso it is not swallowed by the newexcept;generate()runs beforewrite_text, so a failed generate leaves no output file;UnicodeEncodeErroris aValueError, so it is covered too. Existing CMake caller (CMakeLists.txt:1863) andtests/cpu/create_fixture.py(importscreate_sourceonly) are not affected.Commands run locally (venv
/root/.local/share/x2w-rev-venv)git diff --check origin/main...HEAD-> exit 0, no outputpython -B tests/ffx_create_context_check.py -v->Ran 6 tests ... OKpython -B tests/bidi_controls_check.py->Checked 1339 tracked ... no bidirectional controlspython -B tests/docs_links_check.py->Checked 18 Markdown files and 377 linkswin2025) not run: the PR changes no generated output or Windows-built code, only the Python CLI wrapper, a Python test and a ctest registration.Mutations (each applied to
tools/ffx_create_context.py, suite re-run, thengit checkout -- .)OSErrorfrom the excepttest_missing_loader_exits_cleanly)pefile.PEFormatErrortest_non_pe_input_exits_cleanly)parser.exit(1,...)->parser.exit(0,...)destroy(&inner, allocator)removedreturn 5;->return 0;calloc(notallocate)store<void*>(provider_slot, inner)droppedgenerate(stale file on failure)9/9 killed.
Non-blocking notes (P3)
tests/ffx_create_context_check.py(positive tests): the checks are substring matches on the emitted C++. They prove the guard, create call and rollback text are emitted, but not that the C++ compiles or that the rollback runs on an allocation failure. Thecpu_aot_context_lifecycleWindows test remains the real behavioral guard, so this is fine as a unit layer, just do not read it as proof of OOM behavior.tools/ffx_create_context.py:main,pefile.PEFormatErrorbranch: with the pinnedLOADERSHA-256 this branch is only reachable when the test patchesLOADER. That is fine for a defensive path; a one-line comment would stop a future reader from deleting it as dead code.CMakeLists.txt: the newadd_testhas noTIMEOUTproperty, unlike the neighbouringpe_run_package_trap_missing. The suite runs in about 1.3 s here, so this is cosmetic.iced_x86inINTAKE_PYTHON; othertests/cpu/*.pyalready import it, so no new dependency.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:21:31Z.
Resolved the CTest registration conflict with #1908 by retaining both test entries. On the integrated candidate, Release CTest passed
ffx_create_context_check,bink_heap_aot_checkandffx_dispatch_profile_check(3/3).