fix(incidents): bind durable readback tenant context

This commit is contained in:
ogt
2026-07-11 20:10:17 +08:00
parent 476c6a6315
commit ca5ed596dc
6 changed files with 79 additions and 18 deletions

View File

@@ -37,11 +37,18 @@ async def test_readback_prefers_durable_resolved_incident_over_stale_cache(monke
working_read = AsyncMock(return_value=cached)
monkeypatch.setattr(service, "get_from_working_memory", working_read)
result = await service.get_for_readback(durable.incident_id)
result = await service.get_for_readback(
durable.incident_id,
project_id="awoooi",
)
assert result is durable
assert result.status is IncidentStatus.RESOLVED
working_read.assert_not_awaited()
service.get_from_episodic_memory.assert_awaited_once_with(
durable.incident_id,
project_id="awoooi",
)
@pytest.mark.asyncio
@@ -61,7 +68,10 @@ async def test_readback_falls_back_to_working_memory_when_durable_record_unavail
AsyncMock(return_value=cached),
)
result = await service.get_for_readback(cached.incident_id)
result = await service.get_for_readback(
cached.incident_id,
project_id="awoooi",
)
assert result is cached
@@ -76,11 +86,17 @@ async def test_incident_detail_endpoint_uses_durable_readback(monkeypatch):
service = _Service()
monkeypatch.setattr(incidents_api, "get_incident_service", lambda: service)
result = await incidents_api.get_incident(durable.incident_id)
result = await incidents_api.get_incident(
durable.incident_id,
project_id="awoooi",
)
assert result.incident_id == durable.incident_id
assert result.status == IncidentStatus.RESOLVED.value
service.get_for_readback.assert_awaited_once_with(durable.incident_id)
service.get_for_readback.assert_awaited_once_with(
durable.incident_id,
project_id="awoooi",
)
@pytest.mark.asyncio
@@ -98,7 +114,7 @@ async def test_active_incidents_come_from_durable_repository(monkeypatch):
lambda: repository,
)
incidents = await service.get_active_incidents()
incidents = await service.get_active_incidents(project_id="awoooi")
assert incidents == [durable_active]
repository.get_active.assert_awaited_once_with()
repository.get_active.assert_awaited_once_with(project_id="awoooi")

View File

@@ -15,7 +15,12 @@ from src.models.incident import Incident, Severity
class _IncidentService:
async def get_active_incidents(self) -> list[Incident]:
async def get_active_incidents(
self,
*,
project_id: str | None = None,
) -> list[Incident]:
assert project_id == "awoooi"
return [
Incident(
incident_id="INC-20260506-PURE01",
@@ -52,7 +57,10 @@ async def test_list_incidents_does_not_trigger_ai_decision_by_default(monkeypatc
monkeypatch.setattr(incidents_api, "get_incident_service", lambda: _IncidentService())
monkeypatch.setattr(incidents_api, "get_decision_manager", lambda: decision_manager)
result = await incidents_api.list_incidents(generate_missing_decisions=False)
result = await incidents_api.list_incidents(
project_id="awoooi",
generate_missing_decisions=False,
)
assert result.count == 1
assert result.incidents[0].incident_id == "INC-20260506-PURE01"