build: harden atomic report writes and path/IO error guards in verify_build with CLI suite #2578
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2586"
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-25T22:05:16Z.
Summary
Hardens
tools/verify_build.pywith atomic report staging viatempfile.TemporaryDirectory, deterministic sorted file discovery, upfront input/output directory validation, and cleanOSError/ValueErrorerror handling without raw tracebacks, backed by a standalone pure-Python CLI test suite registered in CTest.Changes
tools/verify_build.py:.pid.tmpstaging with_write_json_atomic()usingtempfile.TemporaryDirectory(dir=destination.parent)+os.replace(), creating parent directories, leaving zero temporary artifacts on failure, and preserving any pre-existing report if serialization or replacement fails.root.is_dir()afterargs.directory.resolve(strict=True)and reject existing directory targets for--outputbefore runningverify_pieces().root.rglob("*")ininventory()androot.glob(pattern)inmanifest()for deterministic ordering across filesystems.OSErroralongsideValueErrorduringinventory(),verify_pieces(), and atomic report writing viaparser.error(...)(exit 2, zero raw tracebacks), while preserving all existingtests/layout_chunks_check.pyexpectations.tests/verify_build_cli_check.py:sys.argv/__main__entrypoint, path guard, error-handling, and mutation-killing tests.CMakeLists.txt:build_verify_build_cli_checkin CTest right afterconditional_import_paths.Verification
All commands executed after rebasing onto
upstream/main(fb2f86ac):out/pe-env/Scripts/python.exe -B tests/verify_build_cli_check.py -vRan 6 tests in 1.075s/OK(exit 0)out/pe-env/Scripts/python.exe -B tests/layout_chunks_check.pylayout chunk summary ok(exit 0)out/pe-env/Scripts/python.exe -B tests/form_coverage_check.pyform coverage checks passed(exit 0)out/pe-env/Scripts/python.exe -B tests/docs_links_check.pySelf-test passed. Checked 19 Markdown files and 495 links.(exit 0)out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.pySelf-test passed. Checked 1816 tracked source, script and build/CI files: no bidirectional controls.(exit 0)inventory(),root.is_dir(), output dir/inside-root guards, atomic staging/staging dir,verify_piecesOSError/ValueError, report-writeOSError/ValueError,argvforwarding, and failure return code1): 12/12 killed.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:07:15Z.
Review: COMMENTED
Review of head
8d4936bc(comment only, no merge).Code (
tools/verify_build.py): reads sound. Atomic write withos.replacefrom a temp dir in the destination parent, earlyis_dir/ output-is-directory checks, andOSErrormapped toparser.errorall look right. No sibling callsite ofinventory()ormanifest()was left out.Finding (test robustness):
tests/verify_build_cli_check.py:~170-190,test_inventory_and_manifest_glob_are_sorted, errors on Python 3.14.8:TypeError: ...reversed_glob() got an unexpected keyword argument 'case_sensitive'.Since Python 3.13,
Path.rglobcallsself.glob(pattern, case_sensitive=..., recurse_symlinks=...), so the mockedreversed_glob(path_obj, pattern)(andreversed_rglob) are too narrow. Fix: accept*args, **kwargsin both mocks and forward them to the real function. The test also patchesPathinternals and asserts the exact glob patterns, which ties it to the implementation. A real directory with out-of-order names and a sort-sensitive assertion on the report would guard the behavior more robustly.The other 5 tests pass;
tests/layout_chunks_check.pypasses.Mutations on the code under test (each reverted):
os.replaceremoved: suite FAILED (3 failures, 1 error, the error being the pre-existing 3.14 one above).sorted(...)removed ininventory()and theis_dirguard disabled: suite FAILED (2 failures).So the new tests do catch both changes.
Other commands:
git diff --check origin/main...HEAD,python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.pyall clean. No Windows run on this head yet and CI was pending, so not merged from my side. Please fix the mock signature, then it can be re-checked.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:21:53Z.
Review: COMMENTED
Review of head
4924be40(comment only).Checked:
tools/verify_build.py: atomic write via a staging dir next to the output,os.replace; not-a-directory and output-is-directory guards; OSError guards around inventory, piece verification and report write; sorted globs for stable results. No overlap with merged #2471 / #646 / #51 (different guards).tests/verify_build_cli_check.pyis registered in CMake asbuild_verify_build_cli_checknext to the sibling intake Python tests.inventory(root)is reported as "cannot write report", which is slightly misleading.Commands run (Linux, worktree at this head):
python3 -B tests/verify_build_cli_check.py-> 6 tests OKpython3 tests/docs_links_check.py-> OK;python3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleanos.replace(staged, destination)withpass-> 3 failures + 1 errorWindows run and merge decision follow separately.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T22:20:17Z.
Addressed in commit
4924be40(tests/verify_build_cli_check.py):reversed_rglobandreversed_globintest_inventory_and_manifest_glob_are_sortedto accept and forward*args, **kwargsso Python 3.13+/3.14Path.rglobdelegation toself.glob(..., case_sensitive=..., recurse_symlinks=...)works withoutTypeError.seen_glob_patternsequality assertion (which also observes"*"whenPath.rglobdelegates toPath.glob) and added a real directory with out-of-order filenames (z_extra.bin,m/z.bin,a_extra.bin,m/a.bin) verifying bothinventory()key order and the report'sextra_disk_filesordering.Local verification after
4924be40:out\pe-env\Scripts\python.exe -B tests/verify_build_cli_check.py -v-> 6 tests OKout\pe-env\Scripts\python.exe -B tests/layout_chunks_check.py-> okout\pe-env\Scripts\python.exe -B tests/form_coverage_check.py-> passedout\pe-env\Scripts\python.exe -B tests/docs_links_check.py-> 19 Markdown files, 495 links okout\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py-> 1816 tracked files okAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:25:40Z.
Win2025 WARP receipt for head
a31f2366after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
a31f236679200ba675f612a4bcf99782c0f55c0d:--preset dev):cmake --build --preset dev -- -j 2):28.77s(configure4.43s)ctest --preset dev -R 'build_verify_build_cli_check' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (2.33s:build_verify_build_cli_check2.10s)/O2(--preset release):cmake --build --preset release -- -j 2):22.47s(configure3.22s)ctest --preset release -R 'build_verify_build_cli_check' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (1.93s:build_verify_build_cli_check1.76s)tests/layout_chunks_check.pyok (1.5s)sccache: 194/271 hits; wall77.8sAI-assisted; commands listed were executed locally.