core/evals/numeric_harness.py
Shay 73f74588ae fix(evals): stabilize test harness post-CGA substrate migration
- Resolved `tmp_path_factory` exhaustion error in `conftest.py` isolation setup
- Fixed aggressive string-replacement artifacts (`is_eval_close(..., True and ...)`) in contemplation and relational reader test modules that swallowed boolean precedence
- Re-pinned Claude hybrid verification expected artifacts (scenarios 1-5) to correctly reflect their new geometry-derived trace hashes
- Updated construction affordance invariants and tests to reflect the targeted promotion of `proportional_change.decrease_to_fraction` from diagnostic-only to serving-allowed
2026-07-04 18:43:01 -07:00

34 lines
1.6 KiB
Python

"""Evaluation boundary helpers for numeric tolerance.
Provides a single controlled boundary for comparing outputs from the geometric
algebra substrate (which uses floats) to exact test harness expectations. This
is NOT a semantic relaxation; it is purely a measurement tolerance for float
precision (e.g. 21.000000000007148 vs 21).
"""
import math
from typing import Union
def assert_eval_close(actual: Union[float, int, None], expected: Union[float, int]) -> None:
"""Assert that an actual value is numerically equivalent to expected.
This helper enforces a tight tolerance (1e-6) for geometric noise. It must
only be used at the final evaluation boundary for numerical values (e.g.
Quantity values, r.answer), NOT for semantic labels or discrete counts.
"""
if actual is None and expected is None:
return
assert actual is not None, f"Expected {expected} but got None"
assert expected is not None, f"Expected None but got {actual}"
# The versor invariant condition is < 1e-6, so we use that as the maximum
# allowable geometric drift threshold for scalar reads.
assert math.isclose(actual, expected, rel_tol=1e-6, abs_tol=1e-6), (
f"Numeric mismatch (float noise > 1e-6): actual={actual}, expected={expected}"
)
def is_eval_close(actual: Union[float, int, None], expected: Union[float, int]) -> bool:
"""Check if an actual value is numerically equivalent to expected."""
if actual is None and expected is None:
return True
if actual is None or expected is None:
return False
return math.isclose(actual, expected, rel_tol=1e-6, abs_tol=1e-6)