tools: harden isa_coverage.py BOM, SyntaxError, encoding and zero-division paths #1799
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1799"
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:16:48Z.
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).Imported from ubiquitarianism/leonida. Originally posted by madvillain91 on 2026-11-25T13:01:48Z.
Review: COMMENTED
Independent Windows 11 26H2 (26300.9711) check at
23fad6301against main98c2f7777(PR base0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_isa_coverage.py (23 passed, 4 skipped without LEONIDA_RDNA2_ISA_XML, 20.786s), test_ci_registration.py (16/16, 6.163s), and test_text_write_line_endings.py (3/3, 15.982s), with check_no_game_data.py and compileall clean. Confirmed UTF-8 BOM scanning, SyntaxError/NUL-byte usage errors (preserving UnicodeDecodeError precedence), encoding="utf-8", errors="replace" in probe_llvm_mc() for Windows python -I, empty/whitespace normalization to OTHER:?, and zero-instruction markdown() handling. LGTM.Imported from ubiquitarianism/leonida. Originally posted by MSedgeMC on 2026-11-25T17:20:46Z.
Review: APPROVED
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.
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T17:27:35Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:04:43Z.
#1799 | head
23fad6301f(merged cleanly with maind48a957bb) |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.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T15:00:33Z.
Red/green:
pytest tests/test_isa_coverage.pyfails on main (6 failed, 19 passed, 4 skipped, 4 subtests passed) and passes on head23fad6301fmerged 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
d48a957bbin GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)