tooling: guard empty or zero-sum treemaps and CLI errors in coverage_svg #2127
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2135"
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 R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T01:23:28Z.
Change
Harden
tools/coverage_svg.pyagainst degenerate treemap inputs and CLI I/O errors, add a dedicated stdlib unit and CLI test suite (tests/coverage_svg_check.py), and register it inCMakeLists.txtascoverage_svg(immediately afteremit_variants):squarify(): guards empty items, non-positive container dimensions (w <= 0orh <= 0), non-positive total/item weights, and zero-width/height strip underflow without raisingZeroDivisionError.fit(): returnsNonefortotal <= 0,w <= 0, orh <= 0.render(): validates root/area/group JSON object types,blocked_by_skipentry types and non-empty tokens, and non-negative groupcovered/totalcounts.main(argv=None) -> int: extracts testable CLI entrypoint, rejects resolvedoutput == inputpath collisions, writes SVG output atomically via a sibling temporary file (cleaning up the temp file on any failure), and reports(OSError, ValueError, KeyError, TypeError)cleanly viaparser.exit(1, ...)without tracebacks.Verification
Verified on commit
3c817838(rebased onupstream/main71ae5584):./out/pe-env/Scripts/python.exe -B tests/coverage_svg_check.py-> exit0(coverage_svg: treemap guards, fitting, rendering, CLI errors, and atomic writes passed)./out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py-> exit0(form coverage checks passed)./out/pe-env/Scripts/python.exe -B tests/docs_links_check.py-> exit0(Self-test passed. Checked 18 Markdown files and 398 links.)./out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py-> exit0(Self-test passed. Checked 1437 tracked source, script and build/CI files: no bidirectional controls.)tools/coverage_svg.py(squarifynon-positive total guard,fitnon-positive guard,maininput/output collision check,_write_atomictemp-file unlink, andrendernegative-count check); all 5 mutations were killed bytests/coverage_svg_check.py(exit1) and cleanly restored.coverage_svgregistration inCMakeLists.txtwas inspected in-diff; full CMake reconfigure/CTest run was not executed locally on this pure-Python worktree and is covered by PR CI (--preset pr).Evidence and follow-up
All fixtures in
tests/coverage_svg_check.pyare synthetic in-memory JSON dictionaries (MIT License, stdlib only). Positive controls cover treemap layout geometry, square fitting, group boxes, SVG rendering,--sourcebanner escaping, and CLI file output; negative controls cover empty/zero/negative treemap weights and dimensions, invalid/missing/incomplete JSON, input/output path collisions (direct and..alias), and write-failure temp-file cleanup.Checklist
AI-assisted.