fix(checker): aggregate fuzzy f32 rounding when fully matched #1337

Merged
coah80 merged 1 commits from agent/w0929/orch-checker-land into main 2026-10-09 17:10:10 +00:00
2 changed files with 49 additions and 4 deletions

View File

@@ -15,6 +15,11 @@ EXPECTED_TOTAL_DATA = 1832684
EXPECTED_TOTAL_FUNCTIONS = 12563
INTEGER_PATTERN = re.compile(r"-?(0|[1-9][0-9]*)\Z")
CODE_SECTIONS = frozenset({".text", ".init"})
# objdiff accumulates the aggregate fuzzy_match_percent in 32-bit floats over every code byte,
# so a fully matched report can read 99.9998 instead of 100.0. Aggregates are accepted within
# this tolerance only when every code byte is counted as matched; units, sections and functions
# are always checked exactly.
AGGREGATE_FUZZY_TOLERANCE = 0.001
AGGREGATE_FIELDS = (
"total_units",
"total_code",
@@ -85,7 +90,25 @@ def percent(measures, field, label, failures):
failures.append(f"{label}: {value}")
def check_complete_measures(measures, label, failures):
def aggregate_fuzzy(measures, label, failures):
value = required(measures, "fuzzy_match_percent", f"{label} fuzzy_match_percent", failures)
if value is None or exact(value):
return
try:
fully_matched = integer(measures.get("matched_code")) == integer(measures.get("total_code"))
except ValueError:
fully_matched = False
if (
not fully_matched
or not isinstance(value, (int, float))
or isinstance(value, bool)
or not math.isfinite(float(value))
or not 100.0 - AGGREGATE_FUZZY_TOLERANCE <= float(value) <= 100.0
):
failures.append(f"{label} fuzzy_match_percent: {value}")
def check_complete_measures(measures, label, failures, aggregate=False):
for matched, total, name in (
("matched_code", "total_code", "code match"),
("complete_code", "total_code", "code link"),
@@ -101,9 +124,12 @@ def check_complete_measures(measures, label, failures):
"matched_data_percent",
"complete_data_percent",
"matched_functions_percent",
"fuzzy_match_percent",
):
percent(measures, field, f"{label} {field}", failures)
if aggregate:
aggregate_fuzzy(measures, label, failures)
else:
percent(measures, "fuzzy_match_percent", f"{label} fuzzy_match_percent", failures)
def key_for(value):
@@ -131,7 +157,7 @@ def check_report(report):
value = count(measures, field, "overall", failures)
if value is not None and value != expected:
failures.append(f"overall {field}: {value} != {expected}")
check_complete_measures(measures, "overall", failures)
check_complete_measures(measures, "overall", failures, aggregate=True)
units = report.get("units")
if not isinstance(units, list) or len(units) != EXPECTED_TOTAL_UNITS:
@@ -244,7 +270,7 @@ def check_report(report):
if not isinstance(category_measures, dict):
failures.append(f"{name}: missing measures")
continue
check_complete_measures(category_measures, name, failures)
check_complete_measures(category_measures, name, failures, aggregate=True)
for field in AGGREGATE_FIELDS:
if field in category_measures:
value = count(category_measures, field, name, failures)

View File

@@ -233,6 +233,25 @@ class WorkflowGuardTests(unittest.TestCase):
def test_complete_report_schema_passes(self):
self.assertEqual(check_report(self.complete_report()), [])
def test_aggregate_fuzzy_float_rounding_passes_only_when_fully_matched(self):
report = self.complete_report()
report["measures"]["fuzzy_match_percent"] = 99.999886
report["categories"][0]["measures"]["fuzzy_match_percent"] = 99.999886
self.assertEqual(check_report(report), [])
code_unit = next(unit for unit in report["units"] if "total_code" in unit["measures"])
code_unit["measures"]["fuzzy_match_percent"] = 99.999886
self.assertIn(f"{code_unit['name']} fuzzy percent: 99.999886", check_report(report))
report = self.complete_report()
report["measures"]["fuzzy_match_percent"] = 99.9
self.assertIn("overall fuzzy_match_percent: 99.9", check_report(report))
report = self.complete_report()
report["measures"]["fuzzy_match_percent"] = 99.999886
report["measures"]["matched_code"] = int(report["measures"]["total_code"]) - 4
self.assertIn("overall fuzzy_match_percent: 99.999886", check_report(report))
def test_missing_or_extra_unit_fails(self):
for total_units in (1027, 1029):
with self.subTest(total_units=total_units):