fix(valid-detection-benchmark): require a strict integer for the accepted positive total

total_accepted_positives accepted floats and booleans on both the direct and the decode path. Both now fail closed with STATE_MISMATCH through one sibling helper that keeps _validate_closure within the complexity cap.
This commit is contained in:
Marius Ciepluch
2026-11-23 11:40:09 +01:00
parent 60bb7f0bdd
commit 9e884e8342
2 changed files with 54 additions and 3 deletions
+8 -3
View File
@@ -128,6 +128,13 @@ def _closed_counts(pairs: object) -> tuple[tuple[str, int], ...]:
return pairs
def _closed_total(value: object) -> int:
"""A non-negative exact int: booleans and floats are not closure counts."""
if type(value) is not int or value < 0:
raise _mismatch()
return value
def _gates(item: PositiveSetClosureV1) -> tuple[bool, bool, bool]:
total_ok = item.total_accepted_positives >= COMBINED_POSITIVE_FLOOR
ecosystems_ok = all(count > 0 for _, count in item.positives_by_ecosystem)
@@ -146,9 +153,7 @@ def _validate_closure(item: PositiveSetClosureV1) -> None:
raise _mismatch()
_closed_vocabulary(item.accepted_families, _FAMILY)
_closed_counts(item.positives_by_ecosystem)
if item.total_accepted_positives < 0 or item.total_accepted_positives != sum(
count for _, count in item.positives_by_ecosystem
):
if _closed_total(item.total_accepted_positives) != sum(count for _, count in item.positives_by_ecosystem):
raise _mismatch()
if bool(item.accepted_batch_digests) != (item.total_accepted_positives > 0):
raise _mismatch()