feat(telegram): verify alert context receipts
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Failing after 1m47s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Failing after 1m47s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
This commit is contained in:
@@ -30,6 +30,9 @@ from src.services.awoooi_priority_work_order_readback import (
|
||||
from src.services.harbor_registry_controlled_recovery_preflight import (
|
||||
load_latest_harbor_registry_controlled_recovery_preflight,
|
||||
)
|
||||
from src.services.telegram_alert_learning_context_post_apply_verifier import (
|
||||
build_telegram_alert_learning_context_post_apply_verifier,
|
||||
)
|
||||
from src.services.stockplatform_public_api_controlled_recovery_preflight import (
|
||||
load_latest_stockplatform_public_api_controlled_recovery_preflight,
|
||||
)
|
||||
@@ -472,6 +475,7 @@ def test_ai_automation_live_closure_readbacks_close_node_receipts():
|
||||
executor_readback=executor,
|
||||
verifier_readback=verifier,
|
||||
consumer_readback=_consumer_readback_ready(),
|
||||
telegram_alert_context_verifier_readback=_telegram_alert_context_verifier_ready(),
|
||||
)
|
||||
|
||||
receipts_by_id = {
|
||||
@@ -490,7 +494,7 @@ def test_ai_automation_live_closure_readbacks_close_node_receipts():
|
||||
"controlled_consumer_context_receipt_readback"
|
||||
)
|
||||
assert receipts_by_id["post_verifier"]["verifier_result"] == (
|
||||
"post_write_verifier_dry_run_ready"
|
||||
"telegram_alert_learning_context_post_apply_verified"
|
||||
)
|
||||
assert receipts_by_id["learning_writeback"]["verifier_result"] == (
|
||||
"consumer_context_receipt_writeback_ready"
|
||||
@@ -508,6 +512,12 @@ def test_ai_automation_live_closure_readbacks_close_node_receipts():
|
||||
assert payload["summary"][
|
||||
"ai_automation_consumer_target_context_receipt_write_count"
|
||||
] == 6
|
||||
assert payload["summary"][
|
||||
"ai_automation_telegram_alert_post_apply_verifier_ready"
|
||||
] is True
|
||||
assert payload["summary"][
|
||||
"ai_automation_telegram_alert_post_apply_verified_context_receipt_count"
|
||||
] == 6
|
||||
|
||||
|
||||
def test_awoooi_priority_work_order_readback_endpoint_returns_snapshot(
|
||||
@@ -533,6 +543,11 @@ def test_awoooi_priority_work_order_readback_endpoint_returns_snapshot(
|
||||
"load_latest_ai_agent_log_controlled_writeback_consumer_readback",
|
||||
_consumer_readback_ready_async,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
agents,
|
||||
"load_latest_telegram_alert_learning_context_post_apply_verifier",
|
||||
_telegram_alert_context_verifier_ready_async,
|
||||
)
|
||||
app = FastAPI()
|
||||
app.include_router(router, prefix="/api/v1")
|
||||
client = TestClient(app)
|
||||
@@ -626,6 +641,9 @@ def test_awoooi_priority_work_order_readback_endpoint_returns_snapshot(
|
||||
)
|
||||
assert endpoint_receipts["execution_boundary"]["node_status"] == "ready"
|
||||
assert endpoint_receipts["post_verifier"]["node_status"] == "ready"
|
||||
assert endpoint_receipts["post_verifier"]["verifier_result"] == (
|
||||
"telegram_alert_learning_context_post_apply_verified"
|
||||
)
|
||||
assert endpoint_receipts["learning_writeback"]["node_status"] == "ready"
|
||||
assert endpoint_receipts["learning_writeback"]["km_writeback_ref"] == (
|
||||
"context_receipt:km=1"
|
||||
@@ -1648,6 +1666,84 @@ async def _consumer_readback_ready_async() -> dict:
|
||||
return _consumer_readback_ready()
|
||||
|
||||
|
||||
async def _telegram_alert_context_verifier_ready_async() -> dict:
|
||||
return _telegram_alert_context_verifier_ready()
|
||||
|
||||
|
||||
def _telegram_alert_context_verifier_ready() -> dict:
|
||||
return build_telegram_alert_learning_context_post_apply_verifier(
|
||||
consumer_readback=_consumer_readback_ready()
|
||||
)
|
||||
|
||||
|
||||
def _telegram_context_receipts() -> list[dict]:
|
||||
targets = [
|
||||
("km", "knowledge_memory_context"),
|
||||
("rag", "rag_index_candidate_context"),
|
||||
("playbook", "playbook_trust_candidate_context"),
|
||||
("mcp", "mcp_audit_feedback_context"),
|
||||
("verifier", "post_apply_verifier_feedback_context"),
|
||||
("ai_agent", "autonomous_runtime_decision_context"),
|
||||
]
|
||||
return [
|
||||
{
|
||||
"receipt_id": f"telegram_alert_learning_context::msg-telegram-1::{target}",
|
||||
"source_receipt_id": "msg-telegram-1",
|
||||
"source_run_id": "run-telegram-1",
|
||||
"source_message_id": "msg-telegram-1",
|
||||
"work_item_id": "CIR-P0-TG-001",
|
||||
"target": target,
|
||||
"consumer_surface": surface,
|
||||
"source_ref": f"{target}://awoooi/telegram-alert/msg-telegram-1",
|
||||
"ai_agent_context_ref": (
|
||||
"ai-agent://awoooi/telegram-alert-learning-context/"
|
||||
"run-telegram-1/msg-telegram-1"
|
||||
),
|
||||
"status": "ready_for_ai_loop_context",
|
||||
"metadata_only": True,
|
||||
"target_write_performed": False,
|
||||
"raw_payload_included": False,
|
||||
"target_selector": {
|
||||
"project_id": "awoooi",
|
||||
"run_id": "run-telegram-1",
|
||||
"message_id": "msg-telegram-1",
|
||||
"target": target,
|
||||
"source_ref": f"{target}://awoooi/telegram-alert/msg-telegram-1",
|
||||
},
|
||||
"source_of_truth_diff": {
|
||||
"current_state": "telegram_alert_learning_registry_readable",
|
||||
"desired_state": "ai_loop_agent_context_receipt_available",
|
||||
"delta_kind": f"telegram_alert_{target}_context_binding",
|
||||
"raw_payload_included": False,
|
||||
},
|
||||
"check_mode": {
|
||||
"enabled": True,
|
||||
"checks": [
|
||||
"ai_alert_card_delivery_receipt_present",
|
||||
"learning_registry_binding_ready",
|
||||
"metadata_only_raw_payload_absent",
|
||||
"ai_agent_context_ref_present",
|
||||
],
|
||||
},
|
||||
"rollback": {
|
||||
"required": True,
|
||||
"rollback_ref": (
|
||||
"rollback://telegram-alert-learning-context/"
|
||||
f"msg-telegram-1/{target}"
|
||||
),
|
||||
},
|
||||
"post_apply_verifier": {
|
||||
"required": True,
|
||||
"verifier_refs": [
|
||||
"verifier://awoooi/telegram-alert-delivery-receipt/run-telegram-1",
|
||||
f"{target}://awoooi/telegram-alert/msg-telegram-1",
|
||||
],
|
||||
},
|
||||
}
|
||||
for target, surface in targets
|
||||
]
|
||||
|
||||
|
||||
def _consumer_readback_ready() -> dict:
|
||||
return {
|
||||
"schema_version": "ai_agent_log_controlled_writeback_consumer_readback_v1",
|
||||
@@ -1691,6 +1787,43 @@ def _consumer_readback_ready() -> dict:
|
||||
"verifier_context_receipt_write_count": 1,
|
||||
"ai_agent_context_receipt_write_count": 1,
|
||||
"runtime_target_write_performed": True,
|
||||
"telegram_alert_learning_context_readback_ready": True,
|
||||
"telegram_alert_learning_context_receipt_count": 6,
|
||||
"telegram_alert_learning_ai_agent_context_receipt_count": 1,
|
||||
"telegram_alert_learning_ready_target_count": 6,
|
||||
"telegram_alert_learning_target_count": 6,
|
||||
},
|
||||
"telegram_alert_learning_context": {
|
||||
"schema_version": "telegram_alert_ai_loop_consumer_context_readback_v1",
|
||||
"status": "ai_loop_agent_context_receipt_ready",
|
||||
"priority_work_item_id": "CIR-P0-TG-001",
|
||||
"project_id": "awoooi",
|
||||
"source_endpoint": "/api/v1/platform/runs/ai-alert-cards",
|
||||
"source_registry_status": "learning_registry_ready",
|
||||
"consumer_context_route": "ai_loop_agent.telegram_alert_learning_context",
|
||||
"target_count": 6,
|
||||
"ready_target_count": 6,
|
||||
"context_receipt_count": 6,
|
||||
"ai_agent_context_receipt_count": 1,
|
||||
"next_action": (
|
||||
"verify_telegram_alert_learning_context_receipts_with_ai_loop_post_apply_verifier"
|
||||
),
|
||||
"context_receipts": _telegram_context_receipts(),
|
||||
"active_blockers": [],
|
||||
"operation_boundaries": {
|
||||
"metadata_read_performed": True,
|
||||
"db_or_log_receipt_read_performed": True,
|
||||
"runtime_target_write_performed": False,
|
||||
"km_write_performed": False,
|
||||
"rag_index_write_performed": False,
|
||||
"playbook_trust_write_performed": False,
|
||||
"mcp_tool_call_performed": False,
|
||||
"agent_runtime_action_performed": False,
|
||||
"telegram_send_performed": False,
|
||||
"raw_payload_included": False,
|
||||
"secret_value_collection_allowed": False,
|
||||
"github_api_used": False,
|
||||
},
|
||||
},
|
||||
"active_blockers": [],
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ def test_telegram_alert_ai_automation_matrix_loader_returns_gap_matrix():
|
||||
}
|
||||
|
||||
summary = payload["summary"]
|
||||
assert summary["telegram_alert_surface_count"] == 7
|
||||
assert summary["telegram_alert_surface_count"] == 8
|
||||
assert summary["known_direct_send_gap_count"] == 0
|
||||
assert summary["known_direct_send_gap_file_count"] == 0
|
||||
assert summary["workflow_direct_send_gap_count"] == 0
|
||||
@@ -55,8 +55,9 @@ def test_telegram_alert_ai_automation_matrix_loader_returns_gap_matrix():
|
||||
assert summary["ai_alert_card_learning_writeback_refs_count"] == 1
|
||||
assert summary["ai_alert_card_learning_registry_readback_count"] == 1
|
||||
assert summary["telegram_alert_ai_loop_consumer_context_readback_count"] == 1
|
||||
assert summary["telegram_alert_post_apply_verifier_readback_count"] == 1
|
||||
assert summary["next_priority_action_id"] == (
|
||||
"verify_telegram_alert_learning_context_receipts_with_ai_loop_post_apply_verifier"
|
||||
"surface_verified_telegram_alert_context_receipts_in_awooop_runs_work_items_alerts"
|
||||
)
|
||||
|
||||
matrix = {item["surface_id"]: item for item in payload["matrix"]}
|
||||
@@ -95,6 +96,12 @@ def test_telegram_alert_ai_automation_matrix_loader_returns_gap_matrix():
|
||||
assert matrix["telegram_ai_loop_agent_consumer_context"]["ai_route"] == (
|
||||
"ready_ai_loop_agent_context_reuse"
|
||||
)
|
||||
assert matrix["telegram_ai_loop_post_apply_verifier"]["status"] == (
|
||||
"post_apply_verifier_readback_present"
|
||||
)
|
||||
assert matrix["telegram_ai_loop_post_apply_verifier"]["post_verifier"] == (
|
||||
"ready_context_receipt_post_apply_verifier"
|
||||
)
|
||||
|
||||
assert payload["direct_send_gap_refs"] == []
|
||||
assert not any(
|
||||
@@ -142,6 +149,10 @@ def test_telegram_matrix_source_contract_supports_container_layout(tmp_path):
|
||||
"telegram_alert_ai_loop_consumer_context_readback_v1\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(tmp_path / "src/services/telegram_alert_learning_context_post_apply_verifier.py").write_text(
|
||||
"telegram_alert_learning_context_post_apply_verifier_v1\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
proof = _inspect_source_contract(tmp_path)
|
||||
|
||||
@@ -158,6 +169,8 @@ def test_telegram_matrix_source_contract_supports_container_layout(tmp_path):
|
||||
assert proof["ai_alert_card_ai_agent_context_ref_present"] is True
|
||||
assert proof["telegram_alert_ai_loop_consumer_context_readback_present"] is True
|
||||
assert proof["telegram_alert_ai_loop_consumer_context_readback_count"] == 1
|
||||
assert proof["telegram_alert_post_apply_verifier_readback_present"] is True
|
||||
assert proof["telegram_alert_post_apply_verifier_readback_count"] == 1
|
||||
|
||||
|
||||
def test_telegram_alert_ai_automation_matrix_endpoint_returns_readback():
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from src.api.v1 import agents
|
||||
from src.api.v1.agents import router
|
||||
from src.services.telegram_alert_learning_context_post_apply_verifier import (
|
||||
build_telegram_alert_learning_context_post_apply_verifier,
|
||||
)
|
||||
|
||||
|
||||
def _context_receipts() -> list[dict]:
|
||||
targets = [
|
||||
("km", "knowledge_memory_context"),
|
||||
("rag", "rag_index_candidate_context"),
|
||||
("playbook", "playbook_trust_candidate_context"),
|
||||
("mcp", "mcp_audit_feedback_context"),
|
||||
("verifier", "post_apply_verifier_feedback_context"),
|
||||
("ai_agent", "autonomous_runtime_decision_context"),
|
||||
]
|
||||
return [
|
||||
{
|
||||
"receipt_id": f"telegram_alert_learning_context::msg-telegram-1::{target}",
|
||||
"source_receipt_id": "msg-telegram-1",
|
||||
"source_run_id": "run-telegram-1",
|
||||
"source_message_id": "msg-telegram-1",
|
||||
"work_item_id": "CIR-P0-TG-001",
|
||||
"target": target,
|
||||
"consumer_surface": surface,
|
||||
"source_ref": f"{target}://awoooi/telegram-alert/msg-telegram-1",
|
||||
"ai_agent_context_ref": (
|
||||
"ai-agent://awoooi/telegram-alert-learning-context/"
|
||||
"run-telegram-1/msg-telegram-1"
|
||||
),
|
||||
"status": "ready_for_ai_loop_context",
|
||||
"metadata_only": True,
|
||||
"target_write_performed": False,
|
||||
"raw_payload_included": False,
|
||||
"target_selector": {
|
||||
"project_id": "awoooi",
|
||||
"run_id": "run-telegram-1",
|
||||
"message_id": "msg-telegram-1",
|
||||
"target": target,
|
||||
"source_ref": f"{target}://awoooi/telegram-alert/msg-telegram-1",
|
||||
},
|
||||
"source_of_truth_diff": {
|
||||
"current_state": "telegram_alert_learning_registry_readable",
|
||||
"desired_state": "ai_loop_agent_context_receipt_available",
|
||||
"delta_kind": f"telegram_alert_{target}_context_binding",
|
||||
"raw_payload_included": False,
|
||||
},
|
||||
"check_mode": {
|
||||
"enabled": True,
|
||||
"checks": [
|
||||
"ai_alert_card_delivery_receipt_present",
|
||||
"learning_registry_binding_ready",
|
||||
"metadata_only_raw_payload_absent",
|
||||
"ai_agent_context_ref_present",
|
||||
],
|
||||
},
|
||||
"rollback": {
|
||||
"required": True,
|
||||
"rollback_ref": (
|
||||
"rollback://telegram-alert-learning-context/"
|
||||
f"msg-telegram-1/{target}"
|
||||
),
|
||||
},
|
||||
"post_apply_verifier": {
|
||||
"required": True,
|
||||
"verifier_refs": [
|
||||
"verifier://awoooi/telegram-alert-delivery-receipt/run-telegram-1",
|
||||
f"{target}://awoooi/telegram-alert/msg-telegram-1",
|
||||
],
|
||||
},
|
||||
}
|
||||
for target, surface in targets
|
||||
]
|
||||
|
||||
|
||||
def _consumer_readback(*, receipts: list[dict] | None = None) -> dict:
|
||||
return {
|
||||
"schema_version": "ai_agent_log_controlled_writeback_consumer_readback_v1",
|
||||
"status": "controlled_writeback_consumer_readback_ready",
|
||||
"telegram_alert_learning_context": {
|
||||
"schema_version": "telegram_alert_ai_loop_consumer_context_readback_v1",
|
||||
"status": "ai_loop_agent_context_receipt_ready",
|
||||
"project_id": "awoooi",
|
||||
"source_registry_status": "learning_registry_ready",
|
||||
"consumer_context_route": "ai_loop_agent.telegram_alert_learning_context",
|
||||
"target_count": 6,
|
||||
"ready_target_count": 6,
|
||||
"context_receipt_count": 6,
|
||||
"ai_agent_context_receipt_count": 1,
|
||||
"context_receipts": receipts if receipts is not None else _context_receipts(),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_telegram_alert_learning_context_post_apply_verifier_passes_receipts():
|
||||
payload = build_telegram_alert_learning_context_post_apply_verifier(
|
||||
consumer_readback=_consumer_readback()
|
||||
)
|
||||
|
||||
assert payload["schema_version"] == (
|
||||
"telegram_alert_learning_context_post_apply_verifier_v1"
|
||||
)
|
||||
assert payload["status"] == (
|
||||
"telegram_alert_learning_context_post_apply_verified"
|
||||
)
|
||||
assert payload["active_blockers"] == []
|
||||
assert payload["controlled_verifier"]["post_apply_verifier_executed"] is True
|
||||
assert payload["controlled_verifier"]["raw_payload_absence_verified"] is True
|
||||
assert payload["operation_boundaries"]["runtime_target_write_performed"] is False
|
||||
assert payload["operation_boundaries"]["telegram_send_performed"] is False
|
||||
assert payload["operation_boundaries"]["secret_value_collection_allowed"] is False
|
||||
|
||||
rollups = payload["rollups"]
|
||||
assert rollups["telegram_alert_learning_context_post_apply_verifier_ready"] is True
|
||||
assert rollups["context_receipt_count"] == 6
|
||||
assert rollups["verified_context_receipt_count"] == 6
|
||||
assert rollups["verified_target_count"] == 6
|
||||
assert rollups["verified_ai_agent_context_receipt_count"] == 1
|
||||
assert rollups["raw_payload_included_count"] == 0
|
||||
assert rollups["runtime_write_performed_count"] == 0
|
||||
|
||||
ai_agent_result = [
|
||||
result
|
||||
for result in payload["verifier_results"]
|
||||
if result["target"] == "ai_agent"
|
||||
][0]
|
||||
assert ai_agent_result["verifier_status"] == "passed"
|
||||
assert ai_agent_result["target_selector_verified"] is True
|
||||
assert ai_agent_result["rollback_verified"] is True
|
||||
assert ai_agent_result["post_apply_verifier_refs"]
|
||||
|
||||
serialized = json.dumps(payload, ensure_ascii=False)
|
||||
assert "TELEGRAM_BOT_TOKEN" not in serialized
|
||||
assert "raw Telegram payload" not in serialized
|
||||
|
||||
|
||||
def test_telegram_alert_learning_context_post_apply_verifier_blocks_bad_receipt():
|
||||
receipts = _context_receipts()
|
||||
receipts[0]["rollback"] = {"required": True, "rollback_ref": ""}
|
||||
|
||||
payload = build_telegram_alert_learning_context_post_apply_verifier(
|
||||
consumer_readback=_consumer_readback(receipts=receipts)
|
||||
)
|
||||
|
||||
assert payload["status"] == (
|
||||
"blocked_telegram_alert_learning_context_post_apply_verifier"
|
||||
)
|
||||
assert payload["rollups"]["failed_context_receipt_count"] == 1
|
||||
assert any(
|
||||
blocker.startswith("telegram_alert_context_receipt_verifier_failed:")
|
||||
for blocker in payload["active_blockers"]
|
||||
)
|
||||
|
||||
|
||||
def test_telegram_alert_learning_context_post_apply_verifier_endpoint(monkeypatch):
|
||||
async def fake_loader():
|
||||
return build_telegram_alert_learning_context_post_apply_verifier(
|
||||
consumer_readback=_consumer_readback()
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
agents,
|
||||
"load_latest_telegram_alert_learning_context_post_apply_verifier",
|
||||
fake_loader,
|
||||
)
|
||||
app = FastAPI()
|
||||
app.include_router(router, prefix="/api/v1")
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get(
|
||||
"/api/v1/agents/telegram-alert-learning-context-post-apply-verifier"
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "telegram_alert_learning_context_post_apply_verified"
|
||||
assert data["rollups"]["verified_target_count"] == 6
|
||||
Reference in New Issue
Block a user