shader: extract main(argv), atomic HLSL writes, and directory/struct/zlib guards in shader_profile_audit with CLI suite #2546
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2554"
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:38:43Z.
Change
Harden
tools/shader_profile_audit.pyCLI argument handling, output writes, and error guards, and add a standalone pure-Python CLI/mutation test suite (tests/shader_profile_audit_cli_check.py, registered asshader_profile_audit_cli_checkinCMakeLists.txt):main(argv: Sequence[str] | None = None) -> intto forwardargvtoparser.parse_args(argv)and return0, invokingraise SystemExit(main())underif __name__ == "__main__".s9-slot0-read-probe.hlslwrites until scanning finishes, validate every destination against the archive path (_same_path()viaresolve()andsamefile()) and existing directories, and write atomically viatempfile.TemporaryDirectory(dir=destination.parent)+os.replace()so failures leave zero partial HLSL files or temporary directories.--source-dirregular files or archive collisions upfront before scanning.(OSError, ValueError, struct.error, zlib.error)cleanly viaparser.exit(1, f"Shader profile audit: {error}\n")with zero raw tracebacks while preserving JSON stdout andscan()behavior.AI-assisted.
Verification
Verified on commit
91a483bf0e36aceed10a38818551f811c315b906(rebased ontoupstream/main5f51daaa) usingout\pe-env\Scripts\python.exe -B:out\pe-env\Scripts\python.exe -B tests/shader_profile_audit_cli_check.py -v-> exit 0 (Ran 8 tests in 10.674s,OK)out\pe-env\Scripts\python.exe -B tests/shader_profile_audit_check.py -v-> exit 0 (Ran 3 tests in 3.025s,OK)out\pe-env\Scripts\python.exe -B tests/shader_census_check.py -v-> exit 0 (Ran 9 tests in 0.979s,OK)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 483 links.)out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py-> exit 0 (Self-test passed. Checked 1783 tracked source, script and build/CI files: no bidirectional controls.)tools/shader_profile_audit.py(parse_args(argv),_same_pathresolve()/samefile(),--source-dirarchive collision & non-directory checks, per-destination archive collision, upfrontargs.archive.is_dir(),struct.error&zlib.errorguards, atomic staging write,return 0) causedtests/shader_profile_audit_cli_check.pyto fail (exit 1).Evidence and follow-up
tests/shader_profile_audit_cli_check.pyreuse the synthetic in-memory DXBC/DXIL/PSV0/RPF builders and stub disassembler fromtests/shader_profile_audit_check.pyunder the repository MIT License.--source-dirregular files and archive collisions (relative alias, non-existentresolve(), and hardlinksamefile()), output-file archive collision (s9-slot0-read-probe.hlsl),os.replace()OSErrorleaving zero.hlslfiles or temp dirs, mid-scanstruct.error/zlib.errorleaving zero partial files or tracebacks, and Python 3.14argparse-compatible usage errors.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:49:06Z.
Review: COMMENTED
Review of head
91a483bf(CI is green; the branch is 8 commits behind main).Finding: one new test depends on directory listing order
tests/shader_profile_audit_cli_check.py:114compares[p.name for p in path.parent.iterdir()]with a sorted list.iterdir()order is filesystem-specific. On Linux it fails:['s9-slot0-read-probe.hlsl', 'point-mesh', 'store', 'general'] != ['general', 'point-mesh', 's9-slot0-read-probe.hlsl', 'store']. It only passes where the listing happens to come back sorted (NTFS).sorted(...). The behavior under test (no staging directories left behind, exactly these entries) stays the same.What else I checked (all fine)
main(argv)forwardsargvand returns 0;scan()behavior and JSON stdout are unchanged.struct.errorandzlib.errornow exit with a clean message.shader_profile_audit(#1850 is merged and is a different change).Commands run locally (Linux, PR worktree)
python3 -B tests/shader_profile_audit_cli_check.py: 7 of 8 pass, 1 fails (above)git diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py: passedNot merging until the test is made order-independent.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T20:58:58Z.
Addressed in
3957ecc5:path.parent.iterdir()insorted(p.name for p in path.parent.iterdir())attests/shader_profile_audit_cli_check.py:114so the directory-listing assertion is independent of filesystem entry order.Verified on
3957ecc5:out/pe-env/Scripts/python.exe -B tests/shader_profile_audit_cli_check.py -v: 8/8 OK (also verified withPath.iterdir()monkeypatched to reverse order).out/pe-env/Scripts/python.exe -B tests/shader_profile_audit_check.py -v: 3/3 OK;tests/shader_census_check.py -v: 9/9 OK.ctest --preset dev -R "^shader_profile_audit" --output-on-failure: 2/2 passed (13.86 s).ctest --preset release -R "^shader_profile_audit" --output-on-failure: 2/2 passed (15.34 s).tests/docs_links_check.py(19 files / 483 links) andtests/bidi_controls_check.py(1783 files): passed.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T21:02:11Z.
Review: COMMENTED
Review of head
3957ecc5(re-review after the author's follow-up; only change since91a483bfistests/shader_profile_audit_cli_check.py:114, nowsorted(p.name for p in path.parent.iterdir())).Previous finding is fixed: the listing comparison no longer depends on directory order.
What I checked on this head (Linux, clean worktree):
python3 -I -B tests/shader_profile_audit_cli_check.py->Ran 8 tests,OKpython3 tests/docs_links_check.py-> ok;python3 tests/bidi_controls_check.py-> okgit diff --check origin/main...HEAD-> cleanos.replace(staged, destination)with a directwrite_text(tools/shader_profile_audit.py:230) -> suite FAILS (2 failures). Good.tools/shader_profile_audit.py:297) -> suite FAILS (1 failure). Good.destination.exists() and destination.is_dir()(tools/shader_profile_audit.py:299) -> suite still passes. Minor: the "output path is a directory" message is not pinned by a test (the write still fails cleanly through theOSErrorhandler). Not a blocker; a test asserting the exact message would pin it.Scope: Python tool + a pure-Python suite + CMake registration, no shader lowering, no startup-path claim. No other open or merged PR covers this slice.
The suite is registered in CTest, so the Windows run is the remaining gate; I will queue it on the updated head.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T21:07:45Z.
Win2025 WARP receipt for head
1275e912after updating with main (run limited to the PR's tests:--regex shader_profile_audit).Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
1275e91206ee2009e0d00441a7984c70426b6359:--preset dev):cmake --build --preset dev -- -j 2):27.00s(configure1.86s)ctest --preset dev -R 'shader_profile_audit' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (3.45s:shader_profile_audit_check1.63s,shader_profile_audit_cli_check3.33s)/O2(--preset release):cmake --build --preset release -- -j 2):62.00s(configure1.87s)ctest --preset release -R 'shader_profile_audit' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (2.92s:shader_profile_audit_check1.37s,shader_profile_audit_cli_check2.80s)tests/shader_census_check.pyok (1.1s)sccache: 30/46 hits; wall103.7sAI-assisted; commands listed were executed locally.