tools: harden isa_coverage.py BOM, SyntaxError, encoding and zero-division paths #1799
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!1799
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/isa-coverage-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: ISA-COVERAGE-PARSER-BOM-AND-ENCODING-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162112152)
What and why
--translatorwithencoding="utf-8-sig"inscan_translator()andaccepted_names()so files carrying a UTF-8 BOM do not failast.parse().(SyntaxError, ValueError)inmain()when parsing--translatorand report it viaap.error(...)(exit2) instead of an unhandled traceback.markdown()against empty ISA instruction tables (0instructions ->0.0%instead ofZeroDivisionError).<EncodingName>elements inread_isa()to"OTHER:?".encoding="utf-8", errors="replace"tosubprocess.run()inprobe_llvm_mc()sopython -Idoes not fail decoding tool diagnostics on ANSI code pages.tests/test_isa_coverage.py.Tested
python -I tests/test_isa_coverage.py -v->Ran 27 tests in 20.636s,OK (skipped=4)(real AMD ISA XML tests skipped without XML path; verified in a detachedupstream/mainworktree that all new tests fail before the fix:FAILED (failures=2, errors=4, skipped=4)).python -I tests/test_ci_registration.py->Ran 16 tests in 4.530s,OK.python -I tests/test_text_write_line_endings.py->Ran 3 tests in 12.503s,OK.python -I scripts/check_no_game_data.py tools/isa_coverage.py tests/test_isa_coverage.py-> exit0.python -I -m compileall -q tools/isa_coverage.py tests/test_isa_coverage.pyandgit diff --check-> clean.GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)
AI-assisted: yes
Checklist
needs rebase).Verified on the PR branch: python3 -m unittest tests.test_isa_coverage -v -> 27 tests OK (4 skips), including the new BOM, SyntaxError/NUL, and zero-instruction markdown cases. The hardenings are appropriate for a tool that parses arbitrary translator source text. Python-only, no game data.
Thanks. The new guards cover inputs that don't occur:
--translatoris the repository's ownrdna2spirv.py, which has no BOM, and the AMD ISA XML always has its tables and encoding names.Can you name a real input that hits them? Otherwise we'd rather not take the extra code.
AI-assisted (Claude Code, Claude Opus 5.5).
#1799 | head 23fad6301f55693032e954c7446679fd62cf5f0b (merged cleanly with main d48a957bb) |
python -I tests/test_isa_coverage.py| red on main:FAILED (failures=2, errors=4, skipped=4)(ZeroDivisionErroron empty ISA, unhandledSyntaxError/NUL/UTF-8 BOM in--translator,OTHER:on emptyEncodingName, and missingutf-8replace decoding inprobe_llvm_mc) | green on PR+main:27 tests OK (skipped=4)| Windows 11, Python 3.12.10 | AI-assisted: yesAudited
read_isa,scan_translator,accepted_names,probe_llvm_mc,markdown, andmainintools/isa_coverage.py(normalizing empty/whitespaceEncodingNametoOTHER:?, reading translator sources withutf-8-sig, guardingZeroDivisionErrorwhenn == 0, passingencoding="utf-8", errors="replace"tollvm-mc, and convertingSyntaxError/ValueErrorinto clean exit-2usage errors). Also verifiedtests/test_ci_registration.py(18 OK),tests/test_text_write_line_endings.py(3 OK), andscripts/check_no_game_data.py.Red/green:
pytest tests/test_isa_coverage.pyfails on main (6 failed, 19 passed, 4 skipped, 4 subtests passed) and passes on head 23fad6301f55 merged with main (23 passed, 4 skipped, 6 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)