spirv_asm: validate --out upfront, accept UTF-8 BOM, and write atomically #2264
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2264
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/spirv-asm-cli-safety"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: SPIRV-ASM-CLI-BOM-DIR-GUARD-AND-ATOMIC-WRITE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191092674)
What and why
tools/spirv_asm.pypreviously:.spvasminput before validating--out, causing full assembly before rejecting empty paths, directories, or missing parent directories..spvasmwith"utf-8"instead of"utf-8-sig", rejecting UTF-8 BOM inputs withunknown opcode '\ufeff...'..spvoutput directly in place withopen(args.out, "wb"), risking truncated or corrupted existing outputs if a write failed partway.This adds
_check_out_pathupfront inmain(), reads source files withutf-8-sig(keepingnewline=""), publishes assembled SPIR-V atomically withtempfile+file_mode.published_mode+replace_retry.replace, and adds unit/CLI tests covering all three behaviors.Tested
python -I tests/test_spirv_asm.py -v: 41 tests run (40 passed; 1 skipped:spirv-as not installed)upstream/mainbaseline negative control: failed on the new CLI tests before the fixpython -I tests/test_ci_registration.py(16 passed),python -I tests/test_text_write_line_endings.py(3 passed),python -I scripts/check_no_game_data.py,python -I -m compileall -q, andgit diff --cached --checkGPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_spirv_asm.py: 41 tests OK. The PR's test file against main's tool: 2 failures and 1 error, so the new tests fail on main and pass with the change. compileall clean.
AI-assisted: yes (Claude Code)
Approving 9569d1806.
--outis checked (not empty, not a directory, parent exists) before the source is read, the source is read BOM-tolerant, and the module is published through a temp file andreplace_retry.Merged onto
maind1dff7949in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13.tests/test_spirv_asm.py: 41 passed (main: 38). AI-assisted (Claude Code, Claude Opus 5.5).#2264 | head 9569d180657b0e50a25eaec9ecca17969d086af0 (merged cleanly with main 6c7f79343) |
python -I tests/test_spirv_asm.py| red on main:FAILED (failures=2, errors=1, skipped=2)(unknown opcode '\ufeffOpCapability'on UTF-8 BOM input,assemblerunning before--outvalidation, and non-atomic direct output write) | green on PR+main:41 tests OK (skipped=2)| Windows 11, Python 3.12.10 | AI-assisted: yesAudited
_check_out_path(upfront empty/directory/missing-parent checks before reading or assembling inputs),utf-8-sigsource decoding, and_write_atomic_bytes(NamedTemporaryFile+published_mode+replace_retry.replacewithfinallytemp cleanup) intools/spirv_asm.py. Also passedtests/test_ci_registration.py(18 OK),tests/test_text_write_line_endings.py(3 OK),tests/test_runner_calls_all_tests.py(3 OK), andscripts/check_no_game_data.py.Red/green:
pytest tests/test_spirv_asm.pyfails on main (3 failed, 38 passed, 1 skipped, 250 subtests passed) and passes on head 9569d180657b merged with main (41 passed, 1 skipped, 250 subtests passed).Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)