Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
from contextlib import asynccontextmanager
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from src.models.incident import Severity
|
|
from src.services import incident_memory as incident_memory_module
|
|
from src.services.incident_memory import (
|
|
IncidentDbAdapter,
|
|
_derive_incident_alert_metadata,
|
|
)
|
|
|
|
|
|
def test_signal_worker_incident_metadata_uses_signal_alert_name() -> None:
|
|
incident = SimpleNamespace(
|
|
incident_id="INC-TEST",
|
|
severity=Severity.P2,
|
|
signals=[
|
|
SimpleNamespace(
|
|
alert_name="HostErrorLogFlood",
|
|
severity=Severity.P2,
|
|
source="journal",
|
|
labels={"error_count": "29"},
|
|
annotations={"summary": "29 ERROR log entries in last 5min"},
|
|
fingerprint="b000a87cfe4bc658",
|
|
)
|
|
],
|
|
)
|
|
|
|
metadata = _derive_incident_alert_metadata(incident)
|
|
|
|
assert metadata["alertname"] == "HostErrorLogFlood"
|
|
assert metadata["alert_category"] == "host_resource"
|
|
assert metadata["notification_type"] == "TYPE-3"
|
|
assert metadata["description"] == "29 ERROR log entries in last 5min"
|
|
assert metadata["actor"] == "journal"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_incident_db_adapter_uses_explicit_project_context(monkeypatch) -> None:
|
|
project_ids: list[str | None] = []
|
|
|
|
class FakeResult:
|
|
def scalar_one_or_none(self):
|
|
return None
|
|
|
|
class FakeDb:
|
|
async def execute(self, _statement):
|
|
return FakeResult()
|
|
|
|
@asynccontextmanager
|
|
async def fake_get_db_context(project_id=None):
|
|
project_ids.append(project_id)
|
|
yield FakeDb()
|
|
|
|
monkeypatch.setattr(
|
|
incident_memory_module,
|
|
"get_db_context",
|
|
fake_get_db_context,
|
|
)
|
|
|
|
result = await IncidentDbAdapter(project_id="awoooi").load("INC-NOT-FOUND")
|
|
|
|
assert result is None
|
|
assert project_ids == ["awoooi"]
|