spirv_asm: validate --out upfront, accept UTF-8 BOM, and write atomically #2264
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2264"
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 ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T11:44:47Z.
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.Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T12:23:34Z.
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)
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:37:08Z.
Review: APPROVED
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).Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T10:35:12Z.
#2264 | head
9569d18065(merged cleanly with main6c7f79343) |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.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T15:06:18Z.
Red/green:
pytest tests/test_spirv_asm.pyfails on main (3 failed, 38 passed, 1 skipped, 250 subtests passed) and passes on head9569d18065merged 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
d48a957bbin GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)