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

@@ -3,6 +3,7 @@
from __future__ import annotations
import json
import math
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import Any
@@ -25,6 +26,22 @@ class AlertEvent:
updated_at: str
email_alerts_enabled: bool
def __post_init__(self) -> None:
for field_name in ("severity", "message", "updated_at"):
value = getattr(self, field_name)
if not isinstance(value, str):
raise TypeError(f"{field_name} must be a string")
for field_name in ("ltv_ratio", "warning_threshold", "critical_threshold", "spot_price"):
value = getattr(self, field_name)
if isinstance(value, bool) or not isinstance(value, (int, float)):
raise TypeError(f"{field_name} must be numeric")
numeric_value = float(value)
if not math.isfinite(numeric_value):
raise ValueError(f"{field_name} must be finite")
setattr(self, field_name, numeric_value)
if not isinstance(self.email_alerts_enabled, bool):
raise TypeError("email_alerts_enabled must be a bool")
def to_dict(self) -> dict[str, Any]:
return asdict(self)