fix(agents): bound AI alert card DB readback
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled

This commit is contained in:
ogt
2026-07-09 22:47:29 +08:00
parent f125589f7d
commit abd7ec0815
2 changed files with 93 additions and 3 deletions

View File

@@ -1328,6 +1328,51 @@ async def test_list_ai_alert_card_delivery_readback_failsofts_db_unavailable(
assert payload["learning_registry"]["missing_target_count"] == 6
@pytest.mark.asyncio
async def test_list_ai_alert_card_delivery_readback_failsofts_slow_db(
monkeypatch: pytest.MonkeyPatch,
) -> None:
class SlowDb:
async def execute(self, *_args, **_kwargs):
await asyncio.sleep(1)
class SlowDbContext:
async def __aenter__(self):
return SlowDb()
async def __aexit__(self, exc_type, exc, tb):
return False
monkeypatch.setattr(
platform_operator_service,
"_AI_ALERT_CARD_QUERY_TIMEOUT_SECONDS",
0.01,
)
monkeypatch.setattr(
platform_operator_service,
"_AI_ALERT_CARD_DB_CONTEXT_EXIT_TIMEOUT_SECONDS",
0.01,
)
monkeypatch.setattr(
platform_operator_service,
"get_db_context",
lambda _project_id: SlowDbContext(),
)
payload = await platform_operator_service.list_ai_alert_card_delivery_readback(
project_id="awoooi",
page=1,
per_page=6,
refresh=True,
)
assert payload["summary"]["db_read_status"] == "unavailable"
assert payload["summary"]["source_unavailable_reason"] == "TimeoutError"
assert payload["summary"]["learning_registry_next_action"] == (
"repair_awooop_ai_alert_card_delivery_readback_then_consume_learning_registry"
)
def test_list_callback_replies_keeps_audit_summary_separate_from_km_summary() -> None:
source = inspect.getsource(platform_operator_service.list_callback_replies)