fix(agent): preserve log consumer readback on trace failure
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 44s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 44s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from src.services import ai_agent_autonomous_runtime_control as runtime_control_module
|
||||
from src.services.ai_agent_autonomous_runtime_control import (
|
||||
_RUNTIME_ALERT_OPERATION_COUNTS_SQL,
|
||||
_RUNTIME_ALERTMANAGER_EVENT_COUNTS_SQL,
|
||||
@@ -10,6 +13,19 @@ from src.services.ai_agent_autonomous_runtime_control import (
|
||||
)
|
||||
|
||||
|
||||
class _FailingRuntimeDb:
|
||||
async def execute(self, *_args, **_kwargs):
|
||||
raise RuntimeError("runtime trace query unavailable")
|
||||
|
||||
|
||||
class _FailingRuntimeDbContext:
|
||||
async def __aenter__(self) -> _FailingRuntimeDb:
|
||||
return _FailingRuntimeDb()
|
||||
|
||||
async def __aexit__(self, _exc_type, _exc, _tb) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _assert_log_controlled_writeback_executor(payload: dict):
|
||||
assert payload["schema_version"] == "ai_agent_log_controlled_writeback_executor_readback_v1"
|
||||
assert payload["priority"] == "P1-LOG-KM-RAG-MCP-PLAYBOOK"
|
||||
@@ -190,6 +206,62 @@ def _assert_log_controlled_writeback_consumer(payload: dict):
|
||||
assert payload["operation_boundaries"]["github_api_used"] is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_runtime_receipt_keeps_consumer_readback_when_trace_query_fails(
|
||||
monkeypatch,
|
||||
):
|
||||
async def _fake_consumer_readback(*, project_id: str):
|
||||
assert project_id == "awoooi"
|
||||
return _log_controlled_writeback_consumer_readback()
|
||||
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"get_db_context",
|
||||
lambda project_id: _FailingRuntimeDbContext(),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"_load_log_controlled_writeback_consumer_readback",
|
||||
_fake_consumer_readback,
|
||||
)
|
||||
|
||||
readback = (
|
||||
await runtime_control_module.load_ai_agent_autonomous_runtime_receipt_readback()
|
||||
)
|
||||
|
||||
assert readback["db_read_status"] == "unavailable"
|
||||
assert readback["error"]["type"] == "RuntimeError"
|
||||
_assert_log_controlled_writeback_consumer(
|
||||
readback["log_controlled_writeback_consumer"]
|
||||
)
|
||||
|
||||
|
||||
def test_runtime_control_rollups_project_consumer_dispatch_ledger_if_trace_missing():
|
||||
payload = build_ai_agent_autonomous_runtime_control()
|
||||
readback = build_runtime_receipt_readback_from_rows(
|
||||
project_id="awoooi",
|
||||
db_read_status="unavailable",
|
||||
log_controlled_writeback_consumer=_log_controlled_writeback_consumer_readback(),
|
||||
)
|
||||
|
||||
runtime_control_module._attach_runtime_receipt_readback(payload, readback)
|
||||
|
||||
assert payload["rollups"]["live_log_controlled_writeback_dispatch_count"] == 6
|
||||
assert (
|
||||
payload["rollups"][
|
||||
"live_log_controlled_writeback_consumer_dispatch_ledger_count"
|
||||
]
|
||||
== 6
|
||||
)
|
||||
assert payload["rollups"]["live_log_controlled_writeback_consumer_binding_count"] == 6
|
||||
assert (
|
||||
payload["rollups"]["live_log_controlled_writeback_consumer_ready_binding_count"]
|
||||
== 6
|
||||
)
|
||||
assert payload["rollups"]["live_log_controlled_writeback_consumer_ready_count"] == 1
|
||||
assert payload["rollups"]["live_log_controlled_writeback_consumer_blocker_count"] == 0
|
||||
|
||||
|
||||
def test_runtime_receipt_auxiliary_sql_keeps_source_family_counts_schema_safe():
|
||||
from src.services.ai_agent_autonomous_runtime_control import (
|
||||
_RUNTIME_OPERATION_COUNTS_SQL,
|
||||
|
||||
Reference in New Issue
Block a user