oclaw/tests/test_gateway_telegram_send_normalize.py
oliver 4a23b715a2 重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。

Made-with: Cursor
2026-04-25 01:24:23 +08:00

55 lines
1.8 KiB
Python

from __future__ import annotations
from oclaw.interfaces.gateway.server_methods.telegram_send_normalize import normalize_transport_target_for_channel
def test_normalize_transport_target_for_channel_non_telegram_passthrough() -> None:
to, extra = normalize_transport_target_for_channel(
channel="discord",
to="room-1",
params={},
)
assert to == "room-1"
assert extra == {}
def test_normalize_transport_target_for_channel_handles_topic_target() -> None:
to, extra = normalize_transport_target_for_channel(
channel="telegram",
to="telegram:group:-100123:topic:88",
params={"replyToId": "9"},
)
assert to == "telegram:group:-100123:topic:88"
target = extra.get("target") or {}
assert target.get("chatId") == "-100123"
assert target.get("chatType") == "group"
assert target.get("messageThreadId") == 88
assert extra.get("threadId") == 88
assert extra.get("replyToMessageId") == 9
def test_normalize_transport_target_for_channel_supports_username_lookup_targets() -> None:
to, extra = normalize_transport_target_for_channel(
channel="telegram",
to="@MyUser_01",
params={},
)
assert to == "telegram:@myuser_01"
target = extra.get("target") or {}
assert target.get("chatId") == "@myuser_01"
assert target.get("chatType") == "unknown"
assert "threadId" not in extra
def test_normalize_transport_target_for_channel_uses_explicit_thread_id_override() -> None:
to, extra = normalize_transport_target_for_channel(
channel="telegram",
to="telegram:-100500:topic:2",
params={"threadId": "99"},
)
assert to == "telegram:-100500:topic:2"
assert extra.get("threadId") == 99
target = extra.get("target") or {}
# parsed target remains the source target
assert target.get("messageThreadId") == 2