fix(CORE-001D3B): reject malformed alert history entries

This commit is contained in:
Bu5hm4nn
2026-03-26 15:16:21 +01:00
parent ff76e326b1
commit 65da5b8f1d
2 changed files with 31 additions and 2 deletions

View File

@@ -179,6 +179,24 @@ def test_alert_history_repository_raises_on_corrupt_history_file(tmp_path: Path)
repository.load()
def test_alert_history_repository_raises_on_non_list_payload(tmp_path: Path) -> None:
history_path = tmp_path / "alert_history.json"
history_path.write_text('{"severity": "warning"}', encoding="utf-8")
repository = AlertHistoryRepository(history_path=history_path)
with pytest.raises(AlertHistoryLoadError, match="Alert history payload must be a list"):
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")
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(
@@ -208,7 +226,7 @@ def test_alert_service_marks_history_unavailable_on_corrupt_storage(alert_servic
def test_alert_service_preview_marks_history_unavailable_on_corrupt_storage(alert_service: AlertService) -> None:
alert_service.repository.history_path.write_text("{not valid json", encoding="utf-8")
alert_service.repository.history_path.write_text('[{"severity": "warning"}]', encoding="utf-8")
config = PortfolioConfig(
gold_value=215_000.0,
entry_price=215.0,