tooling: guard empty or zero-sum treemaps and CLI errors in coverage_svg #2127

Merged
Ammmae0x merged 1 commit from upstream-pr/2135 into main 2026-11-25 01:30:28 +00:00
Ammmae0x commented 2026-11-25 01:23:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T01:23:28Z.


Change

Harden tools/coverage_svg.py against 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 in CMakeLists.txt as coverage_svg (immediately after emit_variants):

  • squarify(): guards empty items, non-positive container dimensions (w <= 0 or h <= 0), non-positive total/item weights, and zero-width/height strip underflow without raising ZeroDivisionError.
  • fit(): returns None for total <= 0, w <= 0, or h <= 0.
  • render(): validates root/area/group JSON object types, blocked_by_skip entry types and non-empty tokens, and non-negative group covered/total counts.
  • main(argv=None) -> int: extracts testable CLI entrypoint, rejects resolved output == input path 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 via parser.exit(1, ...) without tracebacks.

Verification

Verified on commit 3c817838 (rebased on upstream/main 71ae5584):

  • ./out/pe-env/Scripts/python.exe -B tests/coverage_svg_check.py -> exit 0 (coverage_svg: treemap guards, fitting, rendering, CLI errors, and atomic writes passed)
  • ./out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> exit 0 (form coverage checks passed)
  • ./out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> exit 0 (Self-test passed. Checked 18 Markdown files and 398 links.)
  • ./out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0 (Self-test passed. Checked 1437 tracked source, script and build/CI files: no bidirectional controls.)
  • Spot-mutation verification: temporarily disabled 5 new guards in tools/coverage_svg.py (squarify non-positive total guard, fit non-positive guard, main input/output collision check, _write_atomic temp-file unlink, and render negative-count check); all 5 mutations were killed by tests/coverage_svg_check.py (exit 1) and cleanly restored.
  • Note: CTest coverage_svg registration in CMakeLists.txt was 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.py are synthetic in-memory JSON dictionaries (MIT License, stdlib only). Positive controls cover treemap layout geometry, square fitting, group boxes, SVG rendering, --source banner 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

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594948212 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2135). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T01:23:28Z. --- ## Change Harden `tools/coverage_svg.py` against 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 in `CMakeLists.txt` as `coverage_svg` (immediately after `emit_variants`): - `squarify()`: guards empty items, non-positive container dimensions (`w <= 0` or `h <= 0`), non-positive total/item weights, and zero-width/height strip underflow without raising `ZeroDivisionError`. - `fit()`: returns `None` for `total <= 0`, `w <= 0`, or `h <= 0`. - `render()`: validates root/area/group JSON object types, `blocked_by_skip` entry types and non-empty tokens, and non-negative group `covered`/`total` counts. - `main(argv=None) -> int`: extracts testable CLI entrypoint, rejects resolved `output == input` path 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 via `parser.exit(1, ...)` without tracebacks. ## Verification Verified on commit `3c817838` (rebased on `upstream/main` `71ae5584`): - `./out/pe-env/Scripts/python.exe -B tests/coverage_svg_check.py` -> exit `0` (`coverage_svg: treemap guards, fitting, rendering, CLI errors, and atomic writes passed`) - `./out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> exit `0` (`form coverage checks passed`) - `./out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> exit `0` (`Self-test passed. Checked 18 Markdown files and 398 links.`) - `./out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> exit `0` (`Self-test passed. Checked 1437 tracked source, script and build/CI files: no bidirectional controls.`) - Spot-mutation verification: temporarily disabled 5 new guards in `tools/coverage_svg.py` (`squarify` non-positive total guard, `fit` non-positive guard, `main` input/output collision check, `_write_atomic` temp-file unlink, and `render` negative-count check); all 5 mutations were killed by `tests/coverage_svg_check.py` (exit `1`) and cleanly restored. - Note: CTest `coverage_svg` registration in `CMakeLists.txt` was 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.py` are synthetic in-memory JSON dictionaries (MIT License, stdlib only). Positive controls cover treemap layout geometry, square fitting, group boxes, SVG rendering, `--source` banner 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 - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-25 02:01:53 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2127
No description provided.