Merge remote-tracking branch 'origin/main' into codex/p0-006-ai-log-triage-20260709
This commit is contained in:
@@ -532,6 +532,8 @@ async def test_live_runtime_receipt_readback_returns_partial_when_query_budget_e
|
||||
async def test_log_controlled_writeback_consumer_timeout_returns_fallback(
|
||||
monkeypatch,
|
||||
):
|
||||
runtime_control_module._clear_runtime_receipt_readback_cache()
|
||||
|
||||
async def _slow_consumer_readback(*, project_id: str):
|
||||
assert project_id == "awoooi"
|
||||
await asyncio.sleep(1)
|
||||
@@ -548,9 +550,12 @@ async def test_log_controlled_writeback_consumer_timeout_returns_fallback(
|
||||
_slow_consumer_readback,
|
||||
)
|
||||
|
||||
readback = await runtime_control_module._load_log_controlled_writeback_consumer_readback(
|
||||
project_id="awoooi",
|
||||
)
|
||||
try:
|
||||
readback = await runtime_control_module._load_log_controlled_writeback_consumer_readback(
|
||||
project_id="awoooi",
|
||||
)
|
||||
finally:
|
||||
runtime_control_module._clear_runtime_receipt_readback_cache()
|
||||
|
||||
assert readback["status"] == "blocked_waiting_controlled_writeback_consumer_receipts"
|
||||
assert "log_controlled_writeback_consumer_readback_unavailable" in readback[
|
||||
@@ -559,6 +564,50 @@ async def test_log_controlled_writeback_consumer_timeout_returns_fallback(
|
||||
assert readback["readback"]["error_type"] == "TimeoutError"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_log_controlled_writeback_consumer_timeout_uses_cached_ready_readback(
|
||||
monkeypatch,
|
||||
):
|
||||
runtime_control_module._clear_runtime_receipt_readback_cache()
|
||||
calls = 0
|
||||
|
||||
async def _sometimes_slow_consumer_readback(*, project_id: str):
|
||||
nonlocal calls
|
||||
assert project_id == "awoooi"
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
return _log_controlled_writeback_consumer_readback()
|
||||
await asyncio.sleep(1)
|
||||
return _log_controlled_writeback_consumer_readback()
|
||||
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"_LOG_CONTROLLED_WRITEBACK_CONSUMER_TIMEOUT_SECONDS",
|
||||
0.01,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"load_latest_ai_agent_log_controlled_writeback_consumer_readback",
|
||||
_sometimes_slow_consumer_readback,
|
||||
)
|
||||
|
||||
try:
|
||||
first = await runtime_control_module._load_log_controlled_writeback_consumer_readback(
|
||||
project_id="awoooi",
|
||||
)
|
||||
second = await runtime_control_module._load_log_controlled_writeback_consumer_readback(
|
||||
project_id="awoooi",
|
||||
)
|
||||
finally:
|
||||
runtime_control_module._clear_runtime_receipt_readback_cache()
|
||||
|
||||
assert first["status"] == "controlled_writeback_consumer_readback_ready"
|
||||
assert second["status"] == "controlled_writeback_consumer_readback_ready"
|
||||
assert second["cache_fallback_active"] is True
|
||||
assert second["record_quality"] == "cached_live_consumer_readback"
|
||||
assert second["readback"]["cache_fallback_error_type"] == "TimeoutError"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_runtime_receipt_readback_uses_short_cache_to_protect_db_pool(
|
||||
monkeypatch,
|
||||
@@ -1676,6 +1725,10 @@ def test_runtime_receipt_auxiliary_alert_query_partial_does_not_block_runtime_tr
|
||||
],
|
||||
partial_query_failures=[
|
||||
{"query_name": "legacy_mcp_counts", "error_type": "DBAPIError"},
|
||||
{
|
||||
"query_name": "playbook_trust_counts",
|
||||
"error_type": "RuntimeReceiptQueryBudgetExceeded",
|
||||
},
|
||||
{"query_name": "alert_operation_counts", "error_type": "DBAPIError"},
|
||||
{
|
||||
"query_name": "alertmanager_event_counts",
|
||||
|
||||
@@ -216,6 +216,14 @@ def test_telegram_alert_monitoring_coverage_readback_surfaces_live_gaps():
|
||||
]
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
payload["operator_answer"]["km_rag_mcp_playbook_ai_agent_context_ready"]
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
payload["operator_answer"]["km_rag_mcp_playbook_ai_agent_context_source"]
|
||||
== "post_apply_verifier"
|
||||
)
|
||||
assert (
|
||||
payload["operator_answer"][
|
||||
"all_monitoring_inventory_surfaces_have_accepted_live_receipt"
|
||||
@@ -351,6 +359,11 @@ def test_telegram_alert_monitoring_coverage_uses_consumer_context_fallback():
|
||||
assert summary["ai_loop_context_fallback_used"] is True
|
||||
assert summary["ai_loop_context_receipt_count"] == 6
|
||||
assert summary["ai_loop_ai_agent_context_receipt_count"] == 1
|
||||
assert summary["km_rag_mcp_playbook_ai_agent_context_ready"] is True
|
||||
assert (
|
||||
summary["km_rag_mcp_playbook_ai_agent_context_source"]
|
||||
== "log_controlled_writeback_consumer"
|
||||
)
|
||||
assert summary["effective_ai_alert_context_receipt_total"] == 6
|
||||
assert summary["effective_ai_alert_context_ready_total"] == 6
|
||||
assert summary["log_controlled_consumer_readback_ready"] is True
|
||||
@@ -362,6 +375,14 @@ def test_telegram_alert_monitoring_coverage_uses_consumer_context_fallback():
|
||||
]
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
payload["operator_answer"]["km_rag_mcp_playbook_ai_agent_context_ready"]
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
payload["operator_answer"]["km_rag_mcp_playbook_ai_agent_context_source"]
|
||||
== "log_controlled_writeback_consumer"
|
||||
)
|
||||
assert (
|
||||
"awooop_ai_alert_card_delivery_db_readback_unavailable"
|
||||
in payload["active_blockers"]
|
||||
@@ -446,6 +467,16 @@ async def test_telegram_alert_monitoring_live_readbacks_are_bounded(
|
||||
slow_runtime_log,
|
||||
)
|
||||
|
||||
async def no_direct_runtime_log(*, project_id: str):
|
||||
assert project_id == "awoooi"
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(
|
||||
coverage_service,
|
||||
"_load_runtime_log_readback_direct",
|
||||
no_direct_runtime_log,
|
||||
)
|
||||
|
||||
verifier = await coverage_service._load_post_apply_verifier_readback(
|
||||
project_id="awoooi"
|
||||
)
|
||||
@@ -464,6 +495,52 @@ async def test_telegram_alert_monitoring_live_readbacks_are_bounded(
|
||||
assert runtime_log["event_type_counts_7d"] == {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_telegram_alert_monitoring_runtime_log_uses_direct_fallback(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
async def failed_runtime_log(*, project_id: str):
|
||||
assert project_id == "awoooi"
|
||||
raise TimeoutError
|
||||
|
||||
async def direct_runtime_log(*, project_id: str):
|
||||
assert project_id == "awoooi"
|
||||
return {
|
||||
"status": "ok",
|
||||
"summary": {
|
||||
"readback_source": "direct_connection",
|
||||
"alert_operation_log_total_7d": 3,
|
||||
"telegram_sent_event_count_7d": 1,
|
||||
"km_converted_event_count_7d": 1,
|
||||
"playbook_draft_event_count_7d": 1,
|
||||
"outbound_telegram_total_7d": 1,
|
||||
},
|
||||
"event_type_counts_7d": {
|
||||
"TELEGRAM_SENT": 1,
|
||||
"KM_CONVERTED": 1,
|
||||
"PLAYBOOK_DRAFT_CREATED": 1,
|
||||
},
|
||||
}
|
||||
|
||||
monkeypatch.setattr(
|
||||
coverage_service,
|
||||
"_load_runtime_log_readback_once",
|
||||
failed_runtime_log,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
coverage_service,
|
||||
"_load_runtime_log_readback_direct",
|
||||
direct_runtime_log,
|
||||
)
|
||||
|
||||
runtime_log = await coverage_service._load_runtime_log_readback(project_id="awoooi")
|
||||
|
||||
assert runtime_log["status"] == "ok"
|
||||
assert runtime_log["summary"]["readback_source"] == "direct_connection"
|
||||
assert runtime_log["summary"]["alert_operation_log_total_7d"] == 3
|
||||
assert runtime_log["event_type_counts_7d"]["TELEGRAM_SENT"] == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_telegram_alert_monitoring_marks_ai_alert_cards_source_unavailable(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
|
||||
Reference in New Issue
Block a user