fix(validator): C2.6 — finiteness hardening, Infinity can no longer vacuously clear the gate (closes R-2)

IR schema now refuses non-finite numbers (allow_inf_nan=False on quantity/
unit_cost/claimed_saving_nok) and non-finite or negative assumption-band
endpoints; json.loads accepts the bare Infinity literal, so the bundle seam
is tested directly. ModelMapContract rejects empty-string model ids
(min_length=1). check_turn_safety_net documented as a deliberately
unreachable belt under the range-bound debate loop.

18 new tests; detach-proven (re-allow inf/nan -> 5 red, drop min_length ->
2 red). Full gate: 365 passed, ruff/format/mypy clean; golden untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-07-16 20:10:12 +02:00
commit e7ce6b0a31
6 changed files with 109 additions and 9 deletions

View file

@ -8,6 +8,7 @@ in its reason, and NO percentiles — so it can never be consumed as validated.
from __future__ import annotations
import pytest
from pydantic import ValidationError
from portfolio_optimiser_claude.ir import SavingsProposal
from portfolio_optimiser_claude.validator import (
@ -63,3 +64,19 @@ class TestRejectionIsUnconsumable:
assert isinstance(outcome, Rejection)
for field in ("p10", "p50", "p90", "validates"):
assert not hasattr(outcome, field)
class TestValidatorCannotBeVacuouslyCleared:
"""R-2: the review's run proof — ``unit_cost: Infinity`` used to reach the
validator and clear it with ``ValidatedProposal(validates=True, p90=inf)``.
The IR schema now refuses non-finite numbers, so no proposal the validator
can receive carries them (§3 Step 4 stays blocking, never vacuous)."""
def test_r2_infinity_proposal_cannot_exist(self) -> None:
with pytest.raises(ValidationError):
SavingsProposal(
project_id="P1",
measure="m",
affected_items=[{"code": "EL", "quantity": 1.0, "unit_cost": float("inf")}],
claimed_saving_nok=1e12,
)