Skip to content

Your lightweight open-source personal agent.

test(telegram): cover local attachment filenames

Xubin Ren50698c3d1c0a
diff --git a/tests/channels/test_telegram_channel.py b/tests/channels/test_telegram_channel.py
index e45059222..803415dfd 100644
--- a/tests/channels/test_telegram_channel.py
+++ b/tests/channels/test_telegram_channel.py
@@ -1,4 +1,3 @@
-import asyncio
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import AsyncMock
@@ -13,8 +12,12 @@ except ImportError:
from nanobot.bus.events import OutboundMessage
from nanobot.bus.queue import MessageBus
-from nanobot.channels.telegram import TELEGRAM_REPLY_CONTEXT_MAX_LEN, TelegramChannel, _StreamBuf
-from nanobot.channels.telegram import TelegramConfig
+from nanobot.channels.telegram import (
+ TELEGRAM_REPLY_CONTEXT_MAX_LEN,
+ TelegramChannel,
+ TelegramConfig,
+ _StreamBuf,
+)
class _FakeHTTPXRequest:
@@ -752,6 +755,36 @@ async def test_send_remote_media_url_after_security_validation(monkeypatch) -> N
]
+async def test_send_local_media_preserves_filename(tmp_path: Path) -> None:
+ channel = TelegramChannel(
+ TelegramConfig(enabled=True, token="123:abc", allow_from=["*"]),
+ MessageBus(),
+ )
+ channel._app = _FakeApp(lambda: None)
+ attachment = tmp_path / "report.final.md"
+ attachment.write_bytes(b"# Report\n")
+
+ await channel.send(
+ OutboundMessage(
+ channel="telegram",
+ chat_id="123",
+ content="",
+ media=[str(attachment)],
+ )
+ )
+
+ assert channel._app.bot.sent_media == [
+ {
+ "kind": "document",
+ "chat_id": 123,
+ "document": b"# Report\n",
+ "reply_parameters": None,
+ "filename": "report.final.md",
+ }
+ ]
+
+
@pytest.mark.asyncio
async def test_send_blocks_unsafe_remote_media_url(monkeypatch) -> None:
channel = TelegramChannel(