This repository has been archived on 2026-08-12. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Cyrene/backend/ai-core/internal/background/thinker_test.go
T
AskaEth 8a3236b8bb refactor: 彻底消除硬编码 qq — 平台标识统一为 obv11
- PlatformName() 返回 "obv11"
- platformFormats key: "obv11"
- 所有 platform == "qq" 检查 → "obv11"
- session prefix: platform_qq_ → platform_obv11_
- env var PLATFORM_CHANNELS: obv11:group:xxx
- ethend 平台标识同步更新
- 注释和测试用例同步

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-23 18:19:52 +08:00

120 lines
3.7 KiB
Go

package background
import (
"testing"
)
func TestExtractProactiveMessage_NoMarker(t *testing.T) {
thinker := &Thinker{platformFormats: defaultPlatformFormats()}
msg, target := thinker.extractProactiveMessage("今天天气真好,开拓者应该出门走走。")
if msg != "" {
t.Errorf("expected empty, got %q", msg)
}
if target != nil {
t.Errorf("expected nil target, got %+v", target)
}
}
func TestExtractProactiveMessage_WebPush(t *testing.T) {
thinker := &Thinker{platformFormats: defaultPlatformFormats()}
content := `今天在想开拓者的事…
【主动消息】今天天气真好,要出去走走吗♪`
msg, target := thinker.extractProactiveMessage(content)
if msg == "" {
t.Fatal("expected message, got empty")
}
if target != nil {
t.Errorf("expected nil target (web push), got %+v", target)
}
if msg != "今天天气真好,要出去走走吗♪" {
t.Errorf("unexpected message: %q", msg)
}
}
func TestExtractProactiveMessage_OBv11Group(t *testing.T) {
thinker := &Thinker{platformFormats: defaultPlatformFormats()}
content := `反思中…
【主动消息】【OBv11群聊:123456】大家早上好呀♪`
msg, target := thinker.extractProactiveMessage(content)
if msg == "" {
t.Fatal("expected message, got empty")
}
if target == nil {
t.Fatal("expected target, got nil")
}
if target.Platform != "obv11" {
t.Errorf("expected platform 'obv11', got %q", target.Platform)
}
if target.ChatType != "group" {
t.Errorf("expected chatType 'group', got %q", target.ChatType)
}
if target.GroupID != "123456" {
t.Errorf("expected groupID '123456', got %q", target.GroupID)
}
if msg != "大家早上好呀♪" {
t.Errorf("unexpected message: %q", msg)
}
}
func TestExtractProactiveMessage_OBv11Private(t *testing.T) {
thinker := &Thinker{platformFormats: defaultPlatformFormats()}
content := `【主动消息】【OBv11私聊:789012】好久不见,最近怎么样?`
msg, target := thinker.extractProactiveMessage(content)
if msg == "" {
t.Fatal("expected message, got empty")
}
if target == nil {
t.Fatal("expected target, got nil")
}
if target.ChatType != "private" {
t.Errorf("expected chatType 'private', got %q", target.ChatType)
}
if target.UserID != "789012" {
t.Errorf("expected userID '789012', got %q", target.UserID)
}
if target.GroupID != "" {
t.Errorf("expected empty groupID for private chat, got %q", target.GroupID)
}
if msg != "好久不见,最近怎么样?" {
t.Errorf("unexpected message: %q", msg)
}
}
func TestExtractProactiveMessage_OBv11GroupAt(t *testing.T) {
thinker := &Thinker{platformFormats: defaultPlatformFormats()}
content := `【主动消息】【OBv11群聊:123456@999888】你说得对呢`
msg, target := thinker.extractProactiveMessage(content)
if msg == "" {
t.Fatal("expected message, got empty")
}
if target == nil {
t.Fatal("expected target, got nil")
}
if target.AtUserID != "999888" {
t.Errorf("expected atUserID '999888', got %q", target.AtUserID)
}
}
func TestExtractProactiveMessage_Negation(t *testing.T) {
thinker := &Thinker{platformFormats: defaultPlatformFormats()}
// "不需要" negates the marker.
content := "开拓者在休息,不需要写【主动消息】打扰他。"
msg, _ := thinker.extractProactiveMessage(content)
if msg != "" {
t.Errorf("expected empty (negated), got %q", msg)
}
}
func TestExtractProactiveMessage_ContinueMarker(t *testing.T) {
thinker := &Thinker{platformFormats: defaultPlatformFormats()}
// 【继续思考】should NOT be extracted as proactive message.
content := "反思完成。【继续思考】"
msg, target := thinker.extractProactiveMessage(content)
if msg != "" {
t.Errorf("expected empty, got %q", msg)
}
if target != nil {
t.Errorf("expected nil target, got %+v", target)
}
}