4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
"""Tests for the alert inbox domain queue (HTTP intake lives in gateway.webapp)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
import pytest
|
|
|
|
from core.domain.alerts.inbox import AlertInbox, IncomingAlert
|
|
|
|
|
|
class TestIncomingAlert:
|
|
def test_valid_minimal(self) -> None:
|
|
alert = IncomingAlert(text="CPU spike")
|
|
assert alert.text == "CPU spike"
|
|
|
|
def test_valid_full(self) -> None:
|
|
alert = IncomingAlert.model_validate(
|
|
{
|
|
"text": "disk full",
|
|
"alert_name": "DiskAlert",
|
|
"severity": "critical",
|
|
"source": "datadog",
|
|
"received_at": datetime.now(UTC).isoformat(),
|
|
}
|
|
)
|
|
assert alert.alert_name == "DiskAlert"
|
|
|
|
def test_rejects_extra_fields(self) -> None:
|
|
with pytest.raises(ValueError, match="Unexpected field"):
|
|
IncomingAlert.model_validate({"text": "x", "unknown": "y"})
|
|
|
|
def test_text_is_required(self) -> None:
|
|
with pytest.raises(ValueError, match="Field required"):
|
|
IncomingAlert.model_validate({})
|
|
|
|
|
|
class TestAlertInbox:
|
|
def test_put_and_pop(self) -> None:
|
|
inbox = AlertInbox(maxsize=3)
|
|
inbox.put(IncomingAlert(text="a"))
|
|
inbox.put(IncomingAlert(text="b"))
|
|
assert inbox.qsize == 2
|
|
assert inbox.pop_nowait() is not None
|
|
assert inbox.qsize == 1
|
|
|
|
def test_iter_pending_drains(self) -> None:
|
|
inbox = AlertInbox(maxsize=5)
|
|
for i in range(3):
|
|
inbox.put(IncomingAlert(text=f"alert {i}"))
|
|
items = inbox.iter_pending()
|
|
assert len(items) == 3
|
|
assert inbox.qsize == 0
|
|
|
|
def test_pop_nowait_returns_none_when_empty(self) -> None:
|
|
assert AlertInbox().pop_nowait() is None
|
|
|
|
def test_drop_oldest_on_overflow(self) -> None:
|
|
inbox = AlertInbox(maxsize=2)
|
|
inbox.put(IncomingAlert(text="a"))
|
|
inbox.put(IncomingAlert(text="b"))
|
|
inbox.put(IncomingAlert(text="c"))
|
|
assert inbox.qsize == 2
|
|
assert inbox.dropped == 1
|
|
assert [a.text for a in inbox.iter_pending()] == ["b", "c"]
|