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 2m32s
CD Pipeline / build-and-deploy (push) Successful in 8m2s
CD Pipeline / post-deploy-checks (push) Successful in 2m22s
Restore D037 durable incident readback without weakening database failure semantics. Fence Agent99 dispatch and terminal learning to canonical identities, durable leases, verifier receipts, and reconciler-owned checkpoints. Drain backup and restore legacy receipts in bounded cohorts with strict transport, claim, projection, and no-false-green controls. Keep SSH service refusal visible while separating it from broker network-policy reachability.
107 lines
3.6 KiB
Python
107 lines
3.6 KiB
Python
from __future__ import annotations
|
||
|
||
import pytest
|
||
|
||
from src.services import telegram_gateway as telegram_gateway_module
|
||
|
||
|
||
@pytest.mark.asyncio
|
||
async def test_telegram_projects_correlated_receipt_without_dispatch(
|
||
monkeypatch,
|
||
) -> None:
|
||
calls: list[tuple[str, str]] = []
|
||
correlated_receipt = {
|
||
"schema_version": "agent99_controlled_dispatch_receipt_v1",
|
||
"status": "dispatch_accepted_verifier_pending",
|
||
"identity": {
|
||
"incident_id": "INC-20260711-11C751",
|
||
"run_id": "7cf8fdf7-0966-5ac6-95b2-09e32808b248",
|
||
"trace_id": "00-11111111111111111111111111111111-2222222222222222-01",
|
||
"work_item_id": "agent99-dispatch:awoooi:INC-20260711-11C751:recovery",
|
||
"idempotency_key": "agent99-controlled:stable-key",
|
||
},
|
||
"dispatch_receipt": {
|
||
"status": "accepted_inbox_triggered",
|
||
"transport": "relay",
|
||
"accepted": True,
|
||
"inbox_triggered": True,
|
||
},
|
||
"receipt_persisted": True,
|
||
"runtime_execution_authorized": False,
|
||
"runtime_closure_verified": False,
|
||
"verifier": {"status": "pending"},
|
||
"learning_writeback": {"status": "pending_verifier"},
|
||
}
|
||
|
||
async def fake_read(*, project_id: str, incident_id: str):
|
||
calls.append((project_id, incident_id))
|
||
return correlated_receipt
|
||
|
||
monkeypatch.setattr(
|
||
telegram_gateway_module,
|
||
"read_agent99_dispatch_receipt",
|
||
fake_read,
|
||
)
|
||
|
||
projection = (
|
||
await telegram_gateway_module._mirror_ai_automation_alert_card_to_agent99(
|
||
"\n".join(
|
||
[
|
||
"ℹ️ ACTION REQUIRED | <b>低風險</b>",
|
||
"📋 <code>INC-20260711-11C751</code>",
|
||
"🎯 資源:<code>cold-start-gate</code>",
|
||
"🏷️ 分類:<b>general</b>",
|
||
"🤖 <b>AI 自動化鏈路</b>",
|
||
]
|
||
),
|
||
source="unit-test",
|
||
)
|
||
)
|
||
|
||
assert calls == [("awoooi", "INC-20260711-11C751")]
|
||
assert projection is not None
|
||
assert projection["schema_version"] == (
|
||
"telegram_agent99_dispatch_receipt_projection_v1"
|
||
)
|
||
assert projection["dispatch_performed"] is False
|
||
assert projection["accepted"] is True
|
||
assert projection["incident_id"] == "INC-20260711-11C751"
|
||
assert projection["run_id"] == correlated_receipt["identity"]["run_id"]
|
||
assert projection["trace_id"] == correlated_receipt["identity"]["trace_id"]
|
||
assert projection["idempotency_key"] == (
|
||
correlated_receipt["identity"]["idempotency_key"]
|
||
)
|
||
assert projection["runtime_closure_verified"] is False
|
||
|
||
|
||
@pytest.mark.asyncio
|
||
async def test_telegram_unbound_card_fails_closed_without_receipt_read(
|
||
monkeypatch,
|
||
) -> None:
|
||
reads: list[str] = []
|
||
|
||
async def unexpected_read(*, project_id: str, incident_id: str):
|
||
reads.append(f"{project_id}:{incident_id}")
|
||
return None
|
||
|
||
monkeypatch.setattr(
|
||
telegram_gateway_module,
|
||
"read_agent99_dispatch_receipt",
|
||
unexpected_read,
|
||
)
|
||
|
||
card = telegram_gateway_module.format_aiops_signal_alert_card(
|
||
"SourceProviderIngestionStale provider_freshness_signal freshness "
|
||
"window timeout Sentry SigNoz provider freshness last seen missing "
|
||
"direct ref verifier readback"
|
||
)
|
||
projection = await telegram_gateway_module._mirror_ai_automation_alert_card_to_agent99(
|
||
card,
|
||
source="unit-test",
|
||
)
|
||
|
||
assert projection is not None
|
||
assert projection["dispatch_performed"] is False
|
||
assert projection["status"] == "receipt_unbound_fail_closed"
|
||
assert reads == []
|