|
| 1 | +"""WhatsApp and SMS are plain-text channels: no Slack link markup may reach them.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from tools.investigation.reporting.context import build_report_context |
| 6 | +from tools.investigation.reporting.formatters.messages import build_report_messages |
| 7 | +from tools.investigation.reporting.formatters.report import format_whatsapp_message |
| 8 | + |
| 9 | + |
| 10 | +def _make_state() -> dict: |
| 11 | + return { |
| 12 | + "alert_name": "Checkout latency spike", |
| 13 | + "severity": "critical", |
| 14 | + "root_cause": "Checkout service was throttled by the upstream API cluster.", |
| 15 | + "validated_claims": [ |
| 16 | + { |
| 17 | + "claim": "Grafana logs show repeated 500 responses.", |
| 18 | + "evidence_sources": ["grafana_logs"], |
| 19 | + } |
| 20 | + ], |
| 21 | + "available_sources": { |
| 22 | + "grafana": { |
| 23 | + "grafana_endpoint": "https://myorg.grafana.net", |
| 24 | + "service_name": "checkout-api", |
| 25 | + }, |
| 26 | + }, |
| 27 | + "evidence": { |
| 28 | + "grafana_logs": [{"message": "service unavailable"}], |
| 29 | + "grafana_logs_query": '{service="checkout-api"}', |
| 30 | + }, |
| 31 | + } |
| 32 | + |
| 33 | + |
| 34 | +def test_whatsapp_message_renders_evidence_links_as_plain_text() -> None: |
| 35 | + body = format_whatsapp_message(build_report_context(_make_state())) |
| 36 | + |
| 37 | + assert "<https://" not in body |
| 38 | + assert "E1 (https://myorg.grafana.net" in body |
| 39 | + |
| 40 | + |
| 41 | +def test_whatsapp_message_renders_s3_trace_links_as_plain_text() -> None: |
| 42 | + state = _make_state() |
| 43 | + state["raw_alert"] = { |
| 44 | + "annotations": { |
| 45 | + "landing_bucket": "tracer-landing", |
| 46 | + "s3_key": "runs/checkout/input.json", |
| 47 | + }, |
| 48 | + } |
| 49 | + |
| 50 | + body = format_whatsapp_message(build_report_context(state)) |
| 51 | + |
| 52 | + assert "<https://" not in body |
| 53 | + assert "S3 object (https://" in body |
| 54 | + |
| 55 | + |
| 56 | +def test_sms_body_carries_no_slack_link_markup() -> None: |
| 57 | + messages = build_report_messages(build_report_context(_make_state())) |
| 58 | + |
| 59 | + assert messages.sms_text == messages.whatsapp_text |
| 60 | + assert "<https://" not in messages.sms_text |
| 61 | + |
| 62 | + |
| 63 | +def test_slack_and_telegram_keep_their_own_link_syntax() -> None: |
| 64 | + """The plain-text conversion must not bleed into the other channels.""" |
| 65 | + messages = build_report_messages(build_report_context(_make_state())) |
| 66 | + |
| 67 | + assert "<https://myorg.grafana.net" in messages.slack_text |
| 68 | + assert '<a href="https://myorg.grafana.net' in messages.telegram_html |
0 commit comments