fix(CORE-001D3B): validate alert history entry types

This commit is contained in:
Bu5hm4nn
2026-03-26 15:19:42 +01:00
parent 65da5b8f1d
commit 99d22302ee
2 changed files with 40 additions and 0 deletions

View File

@@ -188,6 +188,15 @@ def test_alert_history_repository_raises_on_non_list_payload(tmp_path: Path) ->
repository.load()
def test_alert_history_repository_raises_on_non_object_entry(tmp_path: Path) -> None:
history_path = tmp_path / "alert_history.json"
history_path.write_text('["bad entry"]', encoding="utf-8")
repository = AlertHistoryRepository(history_path=history_path)
with pytest.raises(AlertHistoryLoadError, match="Alert history entry 0 must be an object"):
repository.load()
def test_alert_history_repository_raises_on_invalid_list_entry(tmp_path: Path) -> None:
history_path = tmp_path / "alert_history.json"
history_path.write_text('[{"severity": "warning"}]', encoding="utf-8")
@@ -197,6 +206,20 @@ def test_alert_history_repository_raises_on_invalid_list_entry(tmp_path: Path) -
repository.load()
def test_alert_history_repository_raises_on_wrong_typed_fields(tmp_path: Path) -> None:
history_path = tmp_path / "alert_history.json"
history_path.write_text(
'[{"severity": "warning", "message": "bad", "ltv_ratio": "oops", "warning_threshold": 0.7, '
'"critical_threshold": 0.75, "spot_price": 215.0, "updated_at": "2026-03-24T12:00:00Z", '
'"email_alerts_enabled": false}]',
encoding="utf-8",
)
repository = AlertHistoryRepository(history_path=history_path)
with pytest.raises(AlertHistoryLoadError, match="Alert history entry 0 is invalid"):
repository.load()
def test_alert_service_marks_history_unavailable_on_corrupt_storage(alert_service: AlertService) -> None:
alert_service.repository.history_path.write_text("{not valid json", encoding="utf-8")
config = PortfolioConfig(