tools: add atomic I/O, input-overwrite protection and CLI tests for gen_bcpack_runtime_tables.py #1811
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1811"
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-25T12:23:09Z.
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).Imported from ubiquitarianism/leonida. Originally posted by madvillain91 on 2026-11-25T13:19:45Z.
Review: COMMENTED
Independent Windows 11 26H2 (26300.9711) check at
8dfb5cd58against main384abe5b0(PR base0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. All 25 tests passed across test_gen_bcpack_runtime_tables.py (6/6 in 1.067s), test_ci_registration.py (16/16 in 7.907s), and test_text_write_line_endings.py (3/3 in 16.304s), with check_no_game_data.py and compileall clean. Verified LF line endings on generated C++ tables, BCPHIST1 profile roundtrip, atomic replace_retry writes with cleanup on failure, and exit-2 rejection for self-overwrite, directory paths, and combining positional output with --profile. LGTM.Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-25T15:52:09Z.
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.)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T17:27:30Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T11:56:57Z.
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).Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T15:01:16Z.
Red/green: classified READY by cloud-4 (red on main
09c153948, green on head merged with main); head8b2839dd5funchanged since 2026-11-27, before that run.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)