fix(CORE-001D3A): accept decimal boundary inputs
This commit is contained in:
@@ -14,14 +14,14 @@ def alert_service(tmp_path: Path) -> AlertService:
|
||||
return AlertService(history_path=tmp_path / "alert_history.json")
|
||||
|
||||
|
||||
def test_normalize_alert_evaluation_input_coerces_numeric_boundary_values() -> None:
|
||||
def test_normalize_alert_evaluation_input_accepts_decimal_boundary_values() -> None:
|
||||
config = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=151_000.0)
|
||||
|
||||
normalized = _normalize_alert_evaluation_input(
|
||||
config,
|
||||
{
|
||||
"ltv_ratio": "0.7023",
|
||||
"spot_price": "215.0",
|
||||
"ltv_ratio": Decimal("0.7023"),
|
||||
"spot_price": Decimal("215.0"),
|
||||
"quote_updated_at": 123,
|
||||
},
|
||||
)
|
||||
@@ -33,6 +33,38 @@ def test_normalize_alert_evaluation_input_coerces_numeric_boundary_values() -> N
|
||||
assert normalized.critical_threshold == Decimal("0.75")
|
||||
|
||||
|
||||
def test_alert_service_evaluate_accepts_string_boundary_values(alert_service: AlertService) -> None:
|
||||
config = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=151_000.0)
|
||||
|
||||
status = alert_service.evaluate(
|
||||
config,
|
||||
{
|
||||
"ltv_ratio": "0.7023",
|
||||
"spot_price": "215.0",
|
||||
"quote_updated_at": "2026-03-24T12:00:00Z",
|
||||
},
|
||||
persist=False,
|
||||
)
|
||||
|
||||
assert status.severity == "warning"
|
||||
assert status.ltv_ratio == pytest.approx(0.7023, rel=1e-9)
|
||||
assert [event.severity for event in status.history] == ["warning"]
|
||||
|
||||
|
||||
def test_alert_service_rejects_missing_ltv_ratio(alert_service: AlertService) -> None:
|
||||
config = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=151_000.0)
|
||||
|
||||
with pytest.raises(ValueError, match="portfolio.ltv_ratio must be present"):
|
||||
alert_service.evaluate(
|
||||
config,
|
||||
{
|
||||
"spot_price": 215.0,
|
||||
"quote_updated_at": "2026-03-24T12:00:00Z",
|
||||
},
|
||||
persist=False,
|
||||
)
|
||||
|
||||
|
||||
def test_normalize_alert_evaluation_input_rejects_bool_values() -> None:
|
||||
config = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=151_000.0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user