fix(alerts): require runtime closure for coverage
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 2m27s
CD Pipeline / build-and-deploy (push) Successful in 6m46s
CD Pipeline / post-deploy-checks (push) Successful in 1m41s
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 2m27s
CD Pipeline / build-and-deploy (push) Successful in 6m46s
CD Pipeline / post-deploy-checks (push) Successful in 1m41s
This commit is contained in:
@@ -38,6 +38,7 @@ def _payload(
|
||||
runtime_log_readback: dict | None = None,
|
||||
log_controlled_writeback_consumer: dict | None = None,
|
||||
monitoring_live_receipt_apply_readback: dict | None = None,
|
||||
telegram_matrix: dict | None = None,
|
||||
) -> dict:
|
||||
default_post_apply_verifier = {
|
||||
"schema_version": "telegram_alert_learning_context_post_apply_verifier_v1",
|
||||
@@ -64,6 +65,11 @@ def _payload(
|
||||
"km_converted_event_count_7d": 4,
|
||||
"playbook_draft_event_count_7d": 3,
|
||||
"outbound_telegram_total_7d": 8,
|
||||
"automation_triggered_run_count_7d": 3,
|
||||
"automation_closed_run_count_7d": 3,
|
||||
"automation_open_run_count_7d": 0,
|
||||
"automation_runtime_closure_percent": 100.0,
|
||||
"automation_runtime_closure_ready": True,
|
||||
},
|
||||
"event_type_counts_7d": {
|
||||
"ALERT_RECEIVED": 15,
|
||||
@@ -138,7 +144,7 @@ def _payload(
|
||||
},
|
||||
],
|
||||
},
|
||||
telegram_matrix={
|
||||
telegram_matrix=telegram_matrix or {
|
||||
"schema_version": "telegram_alert_ai_automation_matrix_v1",
|
||||
"status": "telegram_alert_ai_automation_matrix_ready",
|
||||
"summary": {
|
||||
@@ -309,13 +315,13 @@ def test_telegram_alert_monitoring_coverage_readback_surfaces_live_gaps():
|
||||
assert summary["runtime_telegram_sent_event_count_7d"] == 8
|
||||
assert summary["source_contract_ready"] is True
|
||||
assert summary["runtime_event_type_with_receipts_count"] == 4
|
||||
assert summary["alert_receipt_pipeline_stage_count"] == 7
|
||||
assert summary["alert_receipt_pipeline_ready_count"] == 6
|
||||
assert summary["alert_receipt_pipeline_stage_count"] == 9
|
||||
assert summary["alert_receipt_pipeline_ready_count"] == 8
|
||||
assert summary["ai_controlled_gap_queue_count"] == 2
|
||||
assert summary["ai_controlled_live_receipt_batch_count"] == 2
|
||||
assert summary["required_tag_dimension_count"] == 12
|
||||
assert summary["monitoring_asset_config_kind_count"] == 2
|
||||
assert summary["telegram_monitoring_audit_completion_percent"] == 88.9
|
||||
assert summary["telegram_monitoring_audit_completion_percent"] == 90.9
|
||||
assert "monitoring_live_receipt_gap:60" in payload["active_blockers"]
|
||||
|
||||
tag_dimensions = {item["dimension"] for item in payload["required_tag_dimensions"]}
|
||||
@@ -348,8 +354,8 @@ def test_telegram_alert_monitoring_coverage_readback_surfaces_live_gaps():
|
||||
|
||||
progress = payload["work_item_progress"]
|
||||
assert progress["work_item_id"] == "CIR-P0-TG-001"
|
||||
assert progress["completed_check_count"] == 8
|
||||
assert progress["total_check_count"] == 9
|
||||
assert progress["completed_check_count"] == 10
|
||||
assert progress["total_check_count"] == 11
|
||||
assert payload["ai_controlled_gap_queue"][0]["work_item_id"] == (
|
||||
"CIR-P0-TG-001-LR-01"
|
||||
)
|
||||
@@ -416,7 +422,7 @@ def test_telegram_alert_monitoring_coverage_accepts_metadata_live_receipts():
|
||||
== 60
|
||||
)
|
||||
assert payload["summary"]["ai_controlled_gap_queue_count"] == 0
|
||||
assert payload["summary"]["alert_receipt_pipeline_ready_count"] == 7
|
||||
assert payload["summary"]["alert_receipt_pipeline_ready_count"] == 9
|
||||
assert payload["summary"]["telegram_monitoring_audit_completion_percent"] == 100.0
|
||||
assert payload["active_blockers"] == []
|
||||
assert payload["ai_controlled_gap_queue"] == []
|
||||
@@ -428,6 +434,79 @@ def test_telegram_alert_monitoring_coverage_accepts_metadata_live_receipts():
|
||||
assert payload["operation_boundaries"]["raw_alert_payload_stored"] is False
|
||||
|
||||
|
||||
def test_telegram_alert_monitoring_coverage_blocks_open_runtime_lifecycle():
|
||||
runtime_log_readback = {
|
||||
"status": "ok",
|
||||
"summary": {
|
||||
"alert_operation_log_total_7d": 539,
|
||||
"telegram_sent_event_count_7d": 77,
|
||||
"automation_triggered_run_count_7d": 7,
|
||||
"automation_closed_run_count_7d": 0,
|
||||
"automation_open_run_count_7d": 7,
|
||||
"automation_runtime_closure_percent": 0.0,
|
||||
"automation_runtime_closure_ready": False,
|
||||
},
|
||||
"event_type_counts_7d": {
|
||||
"ALERT_RECEIVED": 441,
|
||||
"TELEGRAM_SENT": 77,
|
||||
"AUTO_REPAIR_TRIGGERED": 7,
|
||||
"GUARDRAIL_BLOCKED": 9,
|
||||
},
|
||||
}
|
||||
|
||||
payload = _payload(
|
||||
runtime_log_readback=runtime_log_readback,
|
||||
monitoring_live_receipt_apply_readback=_metadata_live_receipt_apply_readback(),
|
||||
)
|
||||
|
||||
assert payload["status"] == (
|
||||
"blocked_telegram_alert_monitoring_coverage_gaps_present"
|
||||
)
|
||||
assert payload["operator_answer"][
|
||||
"all_telegram_monitoring_alerts_ai_agent_automation_ready"
|
||||
] is False
|
||||
assert payload["summary"]["runtime_automation_closure_percent"] == 0.0
|
||||
assert payload["summary"]["runtime_automation_open_run_count_7d"] == 7
|
||||
assert "runtime_ai_automation_lifecycle_open:7" in payload["active_blockers"]
|
||||
pipeline = {stage["stage_id"]: stage for stage in payload["alert_receipt_pipeline"]}
|
||||
assert pipeline["runtime_ai_automation_lifecycle_closure"]["ready"] is False
|
||||
assert pipeline["runtime_ai_automation_lifecycle_closure"]["gap_count"] == 7
|
||||
|
||||
|
||||
def test_telegram_alert_monitoring_coverage_blocks_partial_surface_contracts():
|
||||
payload = _payload(
|
||||
telegram_matrix={
|
||||
"schema_version": "telegram_alert_ai_automation_matrix_v1",
|
||||
"status": "telegram_alert_ai_automation_matrix_partial",
|
||||
"summary": {
|
||||
"telegram_alert_surface_count": 9,
|
||||
"known_direct_send_gap_count": 0,
|
||||
"db_or_log_receipt_ready_surface_count": 8,
|
||||
"ai_route_ready_surface_count": 9,
|
||||
"controlled_queue_ready_surface_count": 6,
|
||||
"post_verifier_ready_surface_count": 7,
|
||||
"learning_writeback_ready_surface_count": 9,
|
||||
},
|
||||
},
|
||||
monitoring_live_receipt_apply_readback=_metadata_live_receipt_apply_readback(),
|
||||
)
|
||||
|
||||
assert payload["status"] == (
|
||||
"blocked_telegram_alert_monitoring_coverage_gaps_present"
|
||||
)
|
||||
assert payload["summary"]["telegram_matrix_db_receipt_gap_count"] == 1
|
||||
assert payload["summary"]["telegram_matrix_controlled_queue_gap_count"] == 3
|
||||
assert payload["summary"]["telegram_matrix_post_verifier_gap_count"] == 2
|
||||
assert payload["summary"]["telegram_matrix_control_contract_ready"] is False
|
||||
assert "telegram_alert_matrix_db_receipt_gap:1" in payload["active_blockers"]
|
||||
assert "telegram_alert_matrix_controlled_queue_gap:3" in payload[
|
||||
"active_blockers"
|
||||
]
|
||||
assert "telegram_alert_matrix_post_verifier_gap:2" in payload[
|
||||
"active_blockers"
|
||||
]
|
||||
|
||||
|
||||
def test_telegram_alert_monitoring_coverage_uses_consumer_context_fallback():
|
||||
payload = _payload(
|
||||
post_apply_verifier={
|
||||
@@ -466,7 +545,7 @@ def test_telegram_alert_monitoring_coverage_uses_consumer_context_fallback():
|
||||
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
|
||||
assert summary["telegram_monitoring_audit_completion_percent"] == 77.8
|
||||
assert summary["telegram_monitoring_audit_completion_percent"] == 81.8
|
||||
|
||||
assert (
|
||||
payload["operator_answer"][
|
||||
@@ -695,6 +774,32 @@ async def test_telegram_alert_monitoring_runtime_log_uses_direct_fallback(
|
||||
assert runtime_log["event_type_counts_7d"]["TELEGRAM_SENT"] == 1
|
||||
|
||||
|
||||
def test_telegram_alert_runtime_log_calculates_incident_closure() -> None:
|
||||
payload = coverage_service._runtime_log_readback_from_rows(
|
||||
event_rows=[
|
||||
{"event_type": "AUTO_REPAIR_TRIGGERED", "count": 3},
|
||||
{"event_type": "EXECUTION_STARTED", "count": 3},
|
||||
{"event_type": "EXECUTION_COMPLETED", "count": 2},
|
||||
{"event_type": "TELEGRAM_RESULT_SENT", "count": 2},
|
||||
],
|
||||
lifecycle_row={
|
||||
"triggered_run_count": 3,
|
||||
"closed_run_count": 2,
|
||||
"latest_triggered_at": "2026-07-11T02:00:00+00:00",
|
||||
"latest_closed_at": "2026-07-11T01:59:00+00:00",
|
||||
},
|
||||
outbound_row={},
|
||||
readback_source="test",
|
||||
)
|
||||
|
||||
summary = payload["summary"]
|
||||
assert summary["automation_triggered_run_count_7d"] == 3
|
||||
assert summary["automation_closed_run_count_7d"] == 2
|
||||
assert summary["automation_open_run_count_7d"] == 1
|
||||
assert summary["automation_runtime_closure_percent"] == 66.7
|
||||
assert summary["automation_runtime_closure_ready"] is False
|
||||
|
||||
|
||||
@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