Files
awoooi/apps/api/tests/test_incident_lifecycle_reconciler.py
Your Name d0835a7be1
All checks were successful
Code Review / ai-code-review (push) Successful in 11s
CD Pipeline / tests (push) Successful in 1m2s
CD Pipeline / build-and-deploy (push) Successful in 3m34s
CD Pipeline / post-deploy-checks (push) Successful in 1m35s
fix(api): reconcile completed stuck incidents
2026-05-19 11:45:15 +08:00

51 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",
}
assert service.resolve_incident.await_args_list[1].args == ("INC-TIMEOUT",)
assert service.resolve_incident.await_args_list[1].kwargs == {
"resolution_type": "timeout",
}