Files
awoooi/apps/api/tests/test_incident_lifecycle_reconciler.py
Your Name 1d285dd9d4
Some checks failed
Code Review / ai-code-review (push) Successful in 11s
CD Pipeline / tests (push) Successful in 1m18s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
fix(api): suppress batch reconcile postmortems
2026-05-19 12:18:17 +08:00

53 lines
1.6 KiB
Python

from types import SimpleNamespace
from unittest.mock import AsyncMock
import pytest
from src.jobs.incident_lifecycle_reconciler import (
LifecycleCandidate,
reconcile_stuck_incidents,
)
@pytest.mark.asyncio
async def test_reconcile_stuck_incidents_resolves_strong_evidence(monkeypatch):
service = SimpleNamespace(resolve_incident=AsyncMock(return_value=object()))
monkeypatch.setattr(
"src.jobs.incident_lifecycle_reconciler._fetch_candidates",
AsyncMock(
return_value=[
LifecycleCandidate(
incident_id="INC-EXEC-SUCCESS",
resolution_type="auto_repair",
reason="approval_execution_success",
),
LifecycleCandidate(
incident_id="INC-TIMEOUT",
resolution_type="timeout",
reason="approval_expired",
),
]
),
)
monkeypatch.setattr(
"src.services.incident_service.get_incident_service",
lambda: service,
)
resolved, errors = await reconcile_stuck_incidents(limit=2)
assert (resolved, errors) == (2, 0)
assert service.resolve_incident.await_args_list[0].args == (
"INC-EXEC-SUCCESS",
)
assert service.resolve_incident.await_args_list[0].kwargs == {
"resolution_type": "auto_repair",
"emit_postmortem": False,
}
assert service.resolve_incident.await_args_list[1].args == ("INC-TIMEOUT",)
assert service.resolve_incident.await_args_list[1].kwargs == {
"resolution_type": "timeout",
"emit_postmortem": False,
}