feat: add audit events and runtime state snapshots to database
- Introduced new tables for audit events and runtime state snapshots in the database schema. - Created data classes for AuditRecord and RuntimeStateRecord to represent the new entities. - Implemented AuditRepository and RuntimeStateRepository for inserting and retrieving records. - Enhanced the dashboard to include an audit trail section, displaying recent audit events. - Added tests for the new audit repository and runtime lifecycle functionalities. - Updated settings validation to ensure proper configuration for alerting features. - Integrated alert notifications across various components, including execution sequencer and loss limits.
This commit is contained in:
@@ -1,10 +1,38 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from arbitrade.risk.stop_conditions import StopConditionsGuard
|
||||
|
||||
|
||||
class _FakeAlertNotifier:
|
||||
def __init__(self) -> None:
|
||||
self.events: list[dict[str, Any]] = []
|
||||
|
||||
async def notify(
|
||||
self,
|
||||
*,
|
||||
category: str,
|
||||
severity: str,
|
||||
title: str,
|
||||
message: str,
|
||||
details: dict[str, str] | None = None,
|
||||
) -> bool:
|
||||
self.events.append(
|
||||
{
|
||||
"category": category,
|
||||
"severity": severity,
|
||||
"title": title,
|
||||
"message": message,
|
||||
"details": details or {},
|
||||
}
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def test_stop_conditions_guard_halts_on_source_latency_breach() -> None:
|
||||
guard = StopConditionsGuard(max_source_latency_ms=50.0)
|
||||
|
||||
@@ -55,3 +83,17 @@ def test_stop_conditions_guard_rejects_invalid_configuration() -> None:
|
||||
|
||||
with pytest.raises(ValueError, match="max_consecutive_failures"):
|
||||
StopConditionsGuard(max_consecutive_failures=0)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_conditions_guard_emits_alert_on_failure_threshold() -> None:
|
||||
notifier = _FakeAlertNotifier()
|
||||
guard = StopConditionsGuard(max_consecutive_failures=1, alert_notifier=notifier)
|
||||
|
||||
guard.register_failure()
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert guard.is_halted
|
||||
assert len(notifier.events) == 1
|
||||
assert notifier.events[0]["category"] == "threshold"
|
||||
assert notifier.events[0]["title"] == "Consecutive failures limit breached"
|
||||
|
||||
Reference in New Issue
Block a user