Skip to content

Your lightweight open-source personal agent.

test(telegram): verify fenced code at outbound send boundary

Xubin Renb3fba7c78fc3
diff --git a/nanobot/channels/telegram/tests/test_telegram_channel.py b/nanobot/channels/telegram/tests/test_telegram_channel.py
index 423372274..32c400958 100644
--- a/nanobot/channels/telegram/tests/test_telegram_channel.py
+++ b/nanobot/channels/telegram/tests/test_telegram_channel.py
@@ -2974,6 +2974,24 @@ def test_markdown_to_html_tilde_fence_is_code() -> None:
)
[email protected]("fence", ["~~~", "````"])
+async def test_send_preserves_fenced_code_and_escapes_html(fence) -> None:
+ channel = TelegramChannel(
+ TelegramConfig(enabled=True, token="123:abc", allow_from=["*"]),
+ MessageBus(),
+ )
+ _install_ready_app(channel)
+ await channel.send(OutboundMessage(
+ channel="telegram", chat_id="123",
+ content=f"{fence}python\n# setup\na < b && __raw__\n{fence}",
+ ))
+ assert len(channel._app.bot.sent_messages) == 1
+ sent = channel._app.bot.sent_messages[0]
+ assert sent["parse_mode"] == "HTML"
+ assert sent["text"] == "<pre><code># setup\na &lt; b &amp;&amp; __raw__\n</code></pre>"
+
+
def test_markdown_to_html_longer_fence_keeps_nested_example() -> None:
from nanobot.channels.telegram.runtime import _markdown_to_telegram_html