4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
144 lines
4.8 KiB
Python
144 lines
4.8 KiB
Python
"""Tests for Markdown -> Telegram HTML conversion."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from integrations.telegram.formatting import (
|
|
looks_like_telegram_html,
|
|
markdown_to_telegram_html,
|
|
)
|
|
|
|
|
|
def test_bold_becomes_b_tag() -> None:
|
|
assert (
|
|
markdown_to_telegram_html("- **CLI / shell** questions") == "• <b>CLI / shell</b> questions"
|
|
)
|
|
|
|
|
|
def test_double_underscore_bold() -> None:
|
|
assert markdown_to_telegram_html("__strong__") == "<b>strong</b>"
|
|
|
|
|
|
def test_inline_code_becomes_code_tag() -> None:
|
|
assert markdown_to_telegram_html("you have `github` connected") == (
|
|
"you have <code>github</code> connected"
|
|
)
|
|
|
|
|
|
def test_italic_underscore() -> None:
|
|
assert markdown_to_telegram_html("_also_") == "<i>also</i>"
|
|
|
|
|
|
def test_slack_single_star_bold() -> None:
|
|
assert markdown_to_telegram_html("*Blocked PRs:*") == "<b>Blocked PRs:</b>"
|
|
|
|
|
|
def test_link_becomes_anchor() -> None:
|
|
assert markdown_to_telegram_html("[docs](https://x.com/a)") == (
|
|
'<a href="https://x.com/a">docs</a>'
|
|
)
|
|
|
|
|
|
def test_slack_link_becomes_anchor() -> None:
|
|
assert markdown_to_telegram_html("<https://github.com/pr/1|#3811>") == (
|
|
'<a href="https://github.com/pr/1">#3811</a>'
|
|
)
|
|
|
|
|
|
def test_html_special_chars_are_escaped() -> None:
|
|
assert markdown_to_telegram_html("a < b & c > d") == "a < b & c > d"
|
|
|
|
|
|
def test_code_content_is_escaped_and_not_reformatted() -> None:
|
|
assert markdown_to_telegram_html("`x = a ** b < c`") == "<code>x = a ** b < c</code>"
|
|
|
|
|
|
def test_fenced_code_block_becomes_pre() -> None:
|
|
out = markdown_to_telegram_html("```py\nx = 1 < 2\n```")
|
|
assert out == "<pre>x = 1 < 2\n</pre>"
|
|
|
|
|
|
def test_unbalanced_markdown_left_as_text() -> None:
|
|
assert markdown_to_telegram_html("**oops no close") == "**oops no close"
|
|
|
|
|
|
def test_plain_text_passthrough() -> None:
|
|
assert markdown_to_telegram_html("just plain words") == "just plain words"
|
|
|
|
|
|
def test_atx_header_becomes_bold() -> None:
|
|
assert markdown_to_telegram_html("## Configured Monitors") == "<b>Configured Monitors</b>"
|
|
|
|
|
|
def test_horizontal_rule_becomes_blank_line() -> None:
|
|
assert markdown_to_telegram_html("before\n---\nafter") == "before\n\nafter"
|
|
|
|
|
|
def test_bullet_list_uses_bullet_glyph() -> None:
|
|
assert markdown_to_telegram_html("- Triggers when CPU idle drops below 10%") == (
|
|
"• Triggers when CPU idle drops below 10%"
|
|
)
|
|
|
|
|
|
def test_numbered_list_preserved() -> None:
|
|
assert markdown_to_telegram_html("1. **List open pull requests**") == (
|
|
"1. <b>List open pull requests</b>"
|
|
)
|
|
|
|
|
|
def test_markdown_table_becomes_mobile_friendly_rows() -> None:
|
|
text = (
|
|
"| Monitor | Type | Current State |\n"
|
|
"|---|---|---|\n"
|
|
"| CPU usage is high | Query Alert | No Data |"
|
|
)
|
|
out = markdown_to_telegram_html(text)
|
|
assert out == ("• <b>CPU usage is high</b> — Query Alert · No Data")
|
|
|
|
|
|
def test_pr_table_becomes_mobile_friendly_rows() -> None:
|
|
text = (
|
|
"| # | Title | Author | Status | Checks |\n"
|
|
"|---|---|---|---|---|\n"
|
|
"| 3811 | docs: fix stale cli | Aditya | Blocked | ❌ Failed |"
|
|
)
|
|
out = markdown_to_telegram_html(text)
|
|
assert out == ("• <b>3811</b> — docs: fix stale cli · Aditya · Blocked · ❌ Failed")
|
|
|
|
|
|
def test_pre_rendered_html_is_left_untouched() -> None:
|
|
html = "<b>Daily Reliability Summary</b>\n\n<i>Generated by OpenSRE</i>"
|
|
assert markdown_to_telegram_html(html) == html
|
|
assert looks_like_telegram_html(html) is True
|
|
|
|
|
|
def test_double_star_bold_is_not_wrapped_twice() -> None:
|
|
text = "• **Resolve** — Identifies which integrations to query"
|
|
out = markdown_to_telegram_html(text)
|
|
assert out == "• <b>Resolve</b> — Identifies which integrations to query"
|
|
assert out.count("<b>") == 1
|
|
assert "**" not in out
|
|
|
|
|
|
def test_investigation_pipeline_bullets_render_once() -> None:
|
|
text = (
|
|
"When you trigger an investigation, it runs through these stages:\n\n"
|
|
"• **Resolve** — Identifies which integrations to query\n"
|
|
"• **Intake** — Parses the raw alert into structured state\n"
|
|
"• **Gather evidence** — AI agent queries your connected tools\n"
|
|
"• **Diagnose** — Extracts structured RCA fields\n"
|
|
"• **Report** — Delivers findings to terminal, Slack, GitLab, etc.\n\n"
|
|
"Your current session"
|
|
)
|
|
out = markdown_to_telegram_html(text)
|
|
assert out.count("<b>Resolve</b>") == 1
|
|
assert out.count("<b>Intake</b>") == 1
|
|
assert out.count("<b>Gather evidence</b>") == 1
|
|
assert "• <b>Resolve</b> — Identifies which integrations to query" in out
|
|
assert "**" not in out
|
|
|
|
|
|
def test_triple_star_bold_does_not_double_wrap() -> None:
|
|
out = markdown_to_telegram_html("***Resolve***")
|
|
assert out.count("<b>") == 1
|
|
assert "<b><b>" not in out
|