tools: add atomic I/O, input-overwrite protection and CLI tests for gen_bcpack_runtime_tables.py #1811
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!1811
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/gen-bcpack-tables-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: GEN-BCPACK-TABLES-ATOMIC-IO-AND-CLI-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162264899)
What and why
generate) and binary (write_profile) outputs intools/gen_bcpack_runtime_tables.pythrough_atomic_write()(tempfile.mkstempbesideos.path.realpath(output), parent directory creation, explicitnewline="\n"for text,os.fsync,published_mode, andreplace_retry) so write failures never truncate existing files._validate_output_path) to reject empty/whitespace paths, trailing separators, existing directories, and non-directory parent components cleanly before writing.--profile JSON OUTwhenOUTaliases the source JSON (orbc6h.json/bc7.jsonin a source directory) viasame_report_path.main(argv=None)to reject combining positional output with--profile, catch(OSError, ValueError, KeyError, TypeError, RecursionError)with exit2instead of tracebacks, and broaden the stdoutreconfigureguard to(AttributeError, ValueError, OSError).tests/test_gen_bcpack_runtime_tables.py.Tested
python -I tests/test_gen_bcpack_runtime_tables.py -v->Ran 6 tests in 0.629s,OK(verified in a detachedupstream/mainworktree that all new tests fail before the fix:FAILED (failures=8)).python -I tests/test_ci_registration.py->Ran 16 tests in 4.413s,OK.python -I tests/test_text_write_line_endings.py->Ran 3 tests in 12.495s,OK.python -I scripts/check_no_game_data.py tools/gen_bcpack_runtime_tables.py tests/test_gen_bcpack_runtime_tables.py-> exit0.python -I -m compileall -q tools/gen_bcpack_runtime_tables.py tests/test_gen_bcpack_runtime_tables.pyandgit diff --check-> clean.GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)
AI-assisted: yes
Checklist
needs rebase).Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.
python -m pytest -q tests/test_gen_bcpack_runtime_tables.py:(AI-assisted test run; output checked by hand.)
Thanks, the atomic write helps the parallel build. One thing:
main()also catchesTypeError/KeyErroraroundgenerate(). CMake runs the generator at build time, so a bug in it now shows as one line with exit 2 and no traceback.exceptto the--profilepath (user JSON), or let errors fromgenerate()raise.AI-assisted (Claude Code, Claude Opus 5.5).
Thanks @aslan2142 — updated
main()soTypeError/KeyError/ValueError/RecursionErrorare caught only around--profileJSON serialization, whilegenerate()lets internal bugs raise normally with a traceback (only_validate_output_pathandOSErrorwrite failures map to exit 2). Added regression coverage intests/test_gen_bcpack_runtime_tables.py(7 passed, 5 repo checks clean).Red/green: classified READY by cloud-4 (red on main 09c153948, green on head merged with main); head 8b2839dd5f8b unchanged since 2026-11-27, before that run.
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)