fix(treemap): verify every cell share (#124)

* fix(treemap): verify every cell's area, including cells too small to label

Closes #89.

The area check derived its basis from in-cell labels, so a cell with no
label was excluded from it. That is precisely the sliver -- the cell a
4px grid distorts most, and the one that shipped 24% undersized during
review of #87. On current main, widening Oceania from 16px to 24px, a
50% area distortion, still reports OK.

Every cell now declares `data-share`, its percentage of the whole, and
the verifier checks all of them against it. Cells without it are
reported rather than skipped: a treemap whose cells cannot be parsed is
not a passing treemap, it is an unchecked one, and answering OK to it is
the defect. The label and the metadata are also cross-checked, because
two statements of one fact is a new way for the picture to lie while the
gate stays green.

Adversarial tests gain the oversized and undersized unlabelled sliver
(both pass on current main and fail here), a fail-closed case for
missing metadata, and a label/metadata divergence case.

SKILL.md `metadata.version` said 2.4 against 2.5.0 manifests. The
manifests are bumped by a script and that field is hand-maintained, so
nothing read both numbers and nothing could notice. verify-plugin-package
now asserts it tracks the manifest MAJOR.MINOR. The package test's
fixture gains the field with it -- a SKILL.md without one is not a valid
package, and a fixture missing it would only prove the gate can be
tripped by its own test data.

The examples regained the `PARTS ROUNDED, MAY NOT SUM` disclosure the
type reference requires: displayed parts round up to 8.10B against a
stated 8.09B. It was dropped when the examples were rebuilt around the
legend block. The anti-pattern list, which still forbade outright what
the honest-data rule permits once disclosed, now agrees with it.

Also nudges the info mark onto the label row of its neighbours rather
than the vertical centre of its own cell, so the bottom row reads as one
row.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(treemap): reject ambiguous share metadata

---------

Co-authored-by: 0xDarkMatter <0xDarkMatter@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Cathryn Lavery
2026-08-19 22:02:02 -05:00
committed by GitHub
co-authored by 0xDarkMatter Claude Fable 5
parent 91fb4f243b
commit e011b04af8
13 changed files with 442 additions and 85 deletions
+133
View File
@@ -263,6 +263,139 @@ def main() -> int:
else:
print("OK: an unlabelled sliver does not disable the area check")
# 6. The unlabelled sliver, both directions. This is the gap issue #89
# reported: with the basis derived from in-cell labels, the one cell
# carrying no label was the one cell nothing verified — and it is the
# cell a 4px grid distorts most. Both rects of the pair move, because
# a mask and a body at different sizes are two cells, not one.
for label, width, direction in (("oversized", "24", "larger"), ("undersized", "8", "smaller")):
mutated = source.replace(
'<rect x="940" y="296" width="16" height="124"',
f'<rect x="940" y="296" width="{width}" height="124"',
)
if mutated == source:
failures.append(f"could not build the {label}-sliver fixture (anchor moved)")
continue
code, output = run(write(directory, f"sliver-{label}.html", mutated))
if code == 0:
failures.append(
f"{label} unlabelled sliver was accepted — the cell with no label "
f"is exactly the one that must still be checked"
)
elif "declares" not in output:
failures.append(f"{label} sliver reported without an area finding: {output.strip()}")
else:
print(f"OK: an unlabelled sliver drawn {direction} than it declares is rejected")
# 7. Fail closed. A cell with no declared share is unverifiable, and
# reporting OK on it is the defect, not a tolerable gap.
stripped = source.replace(' data-share="0.56"', "", 1)
if stripped == source:
failures.append("could not build the missing-metadata fixture (anchor moved)")
else:
code, output = run(write(directory, "nometa.html", stripped))
if code == 0:
failures.append("a cell with no data-share was accepted — must fail closed")
elif "no data-share" not in output:
failures.append(f"missing metadata reported without the right finding: {output.strip()}")
else:
print("OK: a cell with no declared share fails closed")
# 8. A label that disagrees with the metadata it sits on.
divergent = source.replace("4.78B · 59% of world", "4.78B · 42% of world")
if divergent == source:
failures.append("could not build the label-divergence fixture (anchor moved)")
else:
code, output = run(write(directory, "divergent.html", divergent))
if code == 0:
failures.append("a label contradicting its own data-share was accepted")
elif "same fact" not in output:
failures.append(f"divergence reported without the right finding: {output.strip()}")
else:
print("OK: a label contradicting its cell's declared share is rejected")
# 9. Invalid shares fail closed without raising or slipping through
# float edge cases. Zero used to divide by zero; NaN/Infinity made
# comparisons false; negative and >100 values are not shares of a
# whole even though float() accepts them.
for label, value in (
("non-numeric", "unknown"),
("zero", "0"),
("negative", "-1"),
("non-finite-nan", "NaN"),
("non-finite-infinity", "Infinity"),
("over-100", "101"),
):
invalid = source.replace('data-share="59.04"', f'data-share="{value}"', 1)
if invalid == source:
failures.append(f"could not build the {label}-share fixture")
continue
code, output = run(write(directory, f"share-{label}.html", invalid))
if code == 0:
failures.append(f"{label} data-share was accepted")
elif "invalid share metadata" not in output:
failures.append(f"{label} share lacked a metadata finding: {output.strip()}")
else:
print(f"OK: {label} data-share fails closed")
# 10. The mask/body pair is one logical cell. If both copies state a
# share, they must agree; retaining whichever rect was parsed first
# silently discards contradictory source data.
asia_mask = '<rect x="40" y="40" width="532" height="380" rx="2" fill="#f5f5f5"/>'
conflicting = source.replace(
asia_mask,
asia_mask.replace(' fill=', ' data-share="42" fill='),
1,
)
if conflicting == source:
failures.append("could not build the conflicting-twin fixture")
else:
code, output = run(write(directory, "conflicting-twins.html", conflicting))
if code == 0:
failures.append("conflicting duplicate data-share values were accepted")
elif "conflicting data-share" not in output:
failures.append(f"conflicting twins lacked the right finding: {output.strip()}")
else:
print("OK: conflicting mask/body shares are rejected")
asia_body = (
'<rect x="40" y="40" width="532" height="380" rx="2" '
'data-share="59.04" fill="rgba(235,108,54,0.16)" '
'stroke="#eb6c36" stroke-width="1.5"/>'
)
triplicated = source.replace(asia_body, f"{asia_body}\n {asia_body}", 1)
if triplicated == source:
failures.append("could not build the triplicated-cell fixture")
else:
code, output = run(write(directory, "triplicated-cell.html", triplicated))
if code == 0:
failures.append("a triplicated logical cell was silently deduplicated")
elif "duplicate rects" not in output:
failures.append(f"triplicated cell lacked the right finding: {output.strip()}")
else:
print("OK: extra duplicate cell rects are rejected")
# 11. The shares describe one whole, so a plausible individual number
# cannot hide an incomplete or over-counted set.
incomplete_total = source.replace('data-share="59.04"', 'data-share="50"', 1)
code, output = run(write(directory, "incomplete-share-total.html", incomplete_total))
if code == 0:
failures.append("data-share values that do not total the whole were accepted")
elif "not approximately 100%" not in output:
failures.append(f"bad share total lacked the right finding: {output.strip()}")
else:
print("OK: shares must total approximately 100%")
# 12. A treemap with too few parseable cells is unchecked, not clean.
unparsable = source.replace(' rx="2"', ' rx="3"')
code, output = run(write(directory, "too-few-cells.html", unparsable))
if code == 0:
failures.append("a treemap with no parseable cells was accepted")
elif "expected at least 3 parseable treemap cells" not in output:
failures.append(f"too-few-cells fixture lacked the right finding: {output.strip()}")
else:
print("OK: too few parseable cells fails closed")
for failure in failures:
print(f"FAIL: {failure}")
if failures: