fix(automation): expose durable history degradation
All checks were successful
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 2m40s
CD Pipeline / build-and-deploy (push) Successful in 6m59s
CD Pipeline / post-deploy-checks (push) Successful in 1m51s

This commit is contained in:
ogt
2026-07-11 20:43:03 +08:00
parent e793718707
commit 1ecf10507a
3 changed files with 84 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock
import pytest
from fastapi import HTTPException
from src.api.v1 import auto_repair as auto_repair_api
from src.api.v1 import incidents as incidents_api
from src.models.incident import Incident, IncidentStatus, Severity
from src.repositories import incident_repository as incident_repository_module
@@ -247,3 +248,52 @@ async def test_incident_detail_reports_durable_readback_degraded(monkeypatch):
"source_of_truth": "postgresql",
"redis_fallback_used": False,
}
@pytest.mark.asyncio
async def test_repair_history_binds_project_to_durable_incident_read(monkeypatch):
durable_active = _incident(IncidentStatus.INVESTIGATING, minute=38)
class _Service:
get_active_incidents = AsyncMock(return_value=[durable_active])
service = _Service()
monkeypatch.setattr(auto_repair_api, "get_incident_service", lambda: service)
result = await auto_repair_api.get_repair_history(
limit=20,
project_id="awoooi",
)
assert result.count == 0
service.get_active_incidents.assert_awaited_once_with(project_id="awoooi")
@pytest.mark.asyncio
async def test_repair_history_reports_durable_read_degraded(monkeypatch):
class _Service:
get_active_incidents = AsyncMock(
side_effect=IncidentDurableReadError(
"active_incidents_durable_read_unavailable"
)
)
monkeypatch.setattr(
auto_repair_api,
"get_incident_service",
lambda: _Service(),
)
with pytest.raises(HTTPException) as exc_info:
await auto_repair_api.get_repair_history(
limit=20,
project_id="awoooi",
)
assert exc_info.value.status_code == 503
assert exc_info.value.detail == {
"status": "degraded",
"reason_code": "active_incidents_durable_read_unavailable",
"source_of_truth": "postgresql",
"redis_fallback_used": False,
}