Files
ai_academy/internal/im/telegram/adapter_test.go
T
runny 9058149576
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
refactor: 项目更名 WeKnora → Academy
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名)
- 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块)
- docreader proto 描述符采用等长替换,保持序列化字节布局有效
- Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像
- 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
2026-11-13 20:52:51 +08:00

109 lines
2.7 KiB
Go

package telegram
import (
"testing"
"academy/internal/im"
)
func TestParseTelegramMessage_ForumTopicThread(t *testing.T) {
msg := &telegramMsg{
MessageID: 100,
MessageThreadID: 42, // Forum topic ID
From: &telegramUser{ID: 1001, FirstName: "Alice"},
Chat: telegramChat{ID: -9999, Type: "supergroup"},
Text: "hello",
}
incoming := parseTelegramMessage(msg)
if incoming == nil {
t.Fatal("expected non-nil message")
}
if incoming.ThreadID != "42" {
t.Errorf("ThreadID = %q, want %q", incoming.ThreadID, "42")
}
}
func TestParseTelegramMessage_NonForumGroup(t *testing.T) {
msg := &telegramMsg{
MessageID: 200,
MessageThreadID: 0, // not a Forum group
From: &telegramUser{ID: 1002, FirstName: "Bob"},
Chat: telegramChat{ID: -8888, Type: "group"},
Text: "hello",
}
incoming := parseTelegramMessage(msg)
if incoming == nil {
t.Fatal("expected non-nil message")
}
// Non-Forum groups: ThreadID should be empty
if incoming.ThreadID != "" {
t.Errorf("ThreadID = %q, want empty for non-Forum group", incoming.ThreadID)
}
}
func TestParseTelegramMessage_DirectMessage(t *testing.T) {
msg := &telegramMsg{
MessageID: 300,
From: &telegramUser{ID: 1003, FirstName: "Carol"},
Chat: telegramChat{ID: 1003, Type: "private"},
Text: "hi bot",
}
incoming := parseTelegramMessage(msg)
if incoming == nil {
t.Fatal("expected non-nil message")
}
if incoming.ThreadID != "" {
t.Errorf("ThreadID = %q, want empty for DM", incoming.ThreadID)
}
if incoming.ChatType != im.ChatTypeDirect {
t.Errorf("ChatType = %q, want %q", incoming.ChatType, im.ChatTypeDirect)
}
}
func TestParseTelegramMessage_NilMessage(t *testing.T) {
incoming := parseTelegramMessage(nil)
if incoming != nil {
t.Error("expected nil for nil message")
}
}
func TestParseTelegramMessage_Document(t *testing.T) {
msg := &telegramMsg{
MessageID: 400,
MessageThreadID: 7, // in a Forum topic
From: &telegramUser{ID: 1004, FirstName: "Dave"},
Chat: telegramChat{ID: -7777, Type: "supergroup"},
Document: &telegramDoc{
FileID: "doc-123",
FileName: "report.pdf",
FileSize: 2048,
},
}
incoming := parseTelegramMessage(msg)
if incoming == nil {
t.Fatal("expected non-nil message")
}
if incoming.ThreadID != "7" {
t.Errorf("ThreadID = %q, want %q", incoming.ThreadID, "7")
}
if incoming.MessageType != im.MessageTypeFile {
t.Errorf("MessageType = %q, want %q", incoming.MessageType, im.MessageTypeFile)
}
}
func TestParseUpdate_NilMessage(t *testing.T) {
update := &telegramUpdate{UpdateID: 1, Message: nil}
incoming := parseUpdate(update)
if incoming != nil {
t.Error("expected nil for nil update.Message")
}
}