fix(awooop): strengthen outbound truth references
All checks were successful
Code Review / ai-code-review (push) Successful in 10s
CD Pipeline / tests (push) Successful in 1m12s
CD Pipeline / build-and-deploy (push) Successful in 3m33s
CD Pipeline / post-deploy-checks (push) Successful in 1m15s

This commit is contained in:
Your Name
2026-05-13 12:04:26 +08:00
parent 7d506b785d
commit 7fa9f743dd
6 changed files with 102 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ from src.services.channel_hub import (
ensure_completed_shadow_run,
format_grouped_alert_digest_text,
format_grouped_alert_event_content,
record_outbound_message,
)
@@ -79,10 +80,14 @@ class _FakeSession:
def __init__(self) -> None:
self.statement = ""
self.params = {}
self.statements = []
self.param_sets = []
async def execute(self, statement, params): # noqa: ANN001
self.statement = str(statement)
self.params = params
self.statements.append(str(statement))
self.param_sets.append(params)
return _FakeResult()
@@ -105,3 +110,27 @@ async def test_completed_shadow_run_sets_run_state_not_null_defaults() -> None:
assert "0, 3, 0.0000, 0" in session.statement
assert session.params["project_id"] == "awoooi"
assert session.params["run_id"] == run_id
async def test_record_outbound_message_sets_sent_at_for_sent_messages() -> None:
session = _FakeSession()
run_id = build_grouped_alert_run_id("awoooi", "telegram-message-13152")
await record_outbound_message(
session, # type: ignore[arg-type]
project_id="awoooi",
run_id=run_id,
channel_type="telegram",
channel_chat_id="-100123",
message_type="approval_request",
content="ACTION REQUIRED INC-20260513-9B082D",
provider_message_id="13152",
send_status="sent",
triggered_by_state="legacy_gateway",
is_shadow=False,
)
insert_statement = session.statements[-1]
assert "sent_at" in insert_statement
assert "CASE WHEN :send_status = 'sent' THEN NOW() ELSE NULL END" in insert_statement
assert session.param_sets[-1]["send_status"] == "sent"

View File

@@ -18,7 +18,11 @@ def test_telegram_gateway_sanitizes_bot_token_url() -> None:
def test_outbound_source_envelope_keeps_replay_context_without_raw_payload() -> None:
payload = {
"chat_id": "-100123",
"text": "ACTION REQUIRED token 1234567890:abcdefghijklmnopqrstuvwxyzABCDEFGH",
"text": (
"ACTION REQUIRED INC-20260513-9B082D "
"<code>7f858956</code> token "
"1234567890:abcdefghijklmnopqrstuvwxyzABCDEFGH"
),
"parse_mode": "HTML",
"reply_markup": {
"inline_keyboard": [
@@ -40,6 +44,8 @@ def test_outbound_source_envelope_keeps_replay_context_without_raw_payload() ->
assert envelope["reply_markup"]["button_count"] == 2
assert envelope["reply_markup"]["buttons"][0]["callback_prefix"] == "approve"
assert envelope["reply_markup"]["buttons"][1]["callback_prefix"] == "details"
assert envelope["source_refs"]["incident_ids"] == ["INC-20260513-9B082D"]
assert envelope["source_refs"]["code_refs"] == ["7f858956"]
assert "approval-id-secret" not in str(envelope)
assert "1234567890:" not in str(envelope)
assert "ACTION REQUIRED" not in str(envelope)