from __future__ import annotations

from types import SimpleNamespace

from src.models.incident import Severity
from src.services.incident_memory import _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"

