From 3a9d1fc6fd3687b91fb2356c29a3ce5225dc1f3a Mon Sep 17 00:00:00 2001 From: Hoshina Date: Wed, 1 Apr 2026 21:34:24 +0800 Subject: [PATCH] test(channels): update inbound context assertions --- pkg/channels/dingtalk/dingtalk_test.go | 13 ++++++---- pkg/channels/qq/qq_test.go | 20 +++++++------- pkg/channels/telegram/telegram_test.go | 36 +++++++------------------- pkg/channels/wecom/wecom_test.go | 8 +++--- 4 files changed, 32 insertions(+), 45 deletions(-) diff --git a/pkg/channels/dingtalk/dingtalk_test.go b/pkg/channels/dingtalk/dingtalk_test.go index 437616456..c9ab4c196 100644 --- a/pkg/channels/dingtalk/dingtalk_test.go +++ b/pkg/channels/dingtalk/dingtalk_test.go @@ -65,8 +65,8 @@ func TestOnChatBotMessageReceived_GroupMentionOnlyUsesIsInAtListAndStripsMention if inbound.ChatID != "group-abc" { t.Fatalf("chat_id=%q", inbound.ChatID) } - if inbound.Peer.Kind != "group" || inbound.Peer.ID != "group-abc" { - t.Fatalf("peer=%+v", inbound.Peer) + if inbound.Context.ChatType != "group" { + t.Fatalf("chat_type=%q", inbound.Context.ChatType) } if inbound.Content != "/help" { t.Fatalf("content=%q", inbound.Content) @@ -93,12 +93,15 @@ func TestOnChatBotMessageReceived_DirectFallbackSenderIDUsesConversationID(t *te if inbound.ChatID != "conv-direct-42" { t.Fatalf("chat_id=%q", inbound.ChatID) } - if inbound.Peer.Kind != "direct" || inbound.Peer.ID != "openid-user-42" { - t.Fatalf("peer=%+v", inbound.Peer) + if inbound.Context.ChatType != "direct" { + t.Fatalf("chat_type=%q", inbound.Context.ChatType) } - if inbound.SenderID != "dingtalk:openid-user-42" { + if inbound.SenderID != "openid-user-42" { t.Fatalf("sender_id=%q", inbound.SenderID) } + if inbound.Sender.CanonicalID != "dingtalk:openid-user-42" { + t.Fatalf("sender canonical_id=%q", inbound.Sender.CanonicalID) + } if _, ok := ch.sessionWebhooks.Load("conv-direct-42"); !ok { t.Fatal("expected session webhook keyed by conversation_id") diff --git a/pkg/channels/qq/qq_test.go b/pkg/channels/qq/qq_test.go index 83a912cd7..905532f01 100644 --- a/pkg/channels/qq/qq_test.go +++ b/pkg/channels/qq/qq_test.go @@ -50,15 +50,15 @@ func TestHandleC2CMessage_IncludesAccountIDMetadata(t *testing.T) { case <-ctx.Done(): t.Fatal("timeout waiting for inbound message") return - case inbound, ok := <-messageBus.InboundChan(): - if !ok { - t.Fatal("expected inbound message") + case inbound, ok := <-messageBus.InboundChan(): + if !ok { + t.Fatal("expected inbound message") + } + if inbound.Context.Raw["account_id"] != "7750283E123456" { + t.Fatalf("account_id raw = %q, want %q", inbound.Context.Raw["account_id"], "7750283E123456") + } + return } - if inbound.Metadata["account_id"] != "7750283E123456" { - t.Fatalf("account_id metadata = %q, want %q", inbound.Metadata["account_id"], "7750283E123456") - } - return - } } } @@ -165,8 +165,8 @@ func TestHandleGroupATMessage_AttachmentOnlyPublishesMedia(t *testing.T) { if !strings.HasPrefix(inbound.Media[0], "media://") { t.Fatalf("inbound.Media[0] = %q, want media:// ref", inbound.Media[0]) } - if inbound.Peer.Kind != "group" || inbound.Peer.ID != "group-1" { - t.Fatalf("inbound.Peer = %+v, want group/group-1", inbound.Peer) + if inbound.Context.ChatType != "group" { + t.Fatalf("inbound.Context.ChatType = %q, want group", inbound.Context.ChatType) } } diff --git a/pkg/channels/telegram/telegram_test.go b/pkg/channels/telegram/telegram_test.go index 4f7a2600b..0b5d21e2b 100644 --- a/pkg/channels/telegram/telegram_test.go +++ b/pkg/channels/telegram/telegram_test.go @@ -556,16 +556,10 @@ func TestHandleMessage_ForumTopic_SetsMetadata(t *testing.T) { inbound, ok := <-messageBus.InboundChan() require.True(t, ok, "expected inbound message") - // Composite chatID should include thread ID - assert.Equal(t, "-1001234567890/42", inbound.ChatID) - - // Peer ID should include thread ID for session key isolation - assert.Equal(t, "group", inbound.Peer.Kind) - assert.Equal(t, "-1001234567890/42", inbound.Peer.ID) - - // Parent peer metadata should be set for agent binding - assert.Equal(t, "topic", inbound.Metadata["parent_peer_kind"]) - assert.Equal(t, "42", inbound.Metadata["parent_peer_id"]) + // ChatID remains the parent chat; TopicID isolates the sub-conversation. + assert.Equal(t, "-1001234567890", inbound.ChatID) + assert.Equal(t, "group", inbound.Context.ChatType) + assert.Equal(t, "42", inbound.Context.TopicID) } func TestHandleMessage_NoForum_NoThreadMetadata(t *testing.T) { @@ -598,13 +592,8 @@ func TestHandleMessage_NoForum_NoThreadMetadata(t *testing.T) { // Plain chatID without thread suffix assert.Equal(t, "-100999", inbound.ChatID) - // Peer ID should be raw chat ID (no thread suffix) - assert.Equal(t, "group", inbound.Peer.Kind) - assert.Equal(t, "-100999", inbound.Peer.ID) - - // No parent peer metadata - assert.Empty(t, inbound.Metadata["parent_peer_kind"]) - assert.Empty(t, inbound.Metadata["parent_peer_id"]) + assert.Equal(t, "group", inbound.Context.ChatType) + assert.Empty(t, inbound.Context.TopicID) } func TestHandleMessage_ReplyThread_NonForum_NoIsolation(t *testing.T) { @@ -641,13 +630,8 @@ func TestHandleMessage_ReplyThread_NonForum_NoIsolation(t *testing.T) { // chatID should NOT include thread suffix for non-forum groups assert.Equal(t, "-100999", inbound.ChatID) - // Peer ID should be raw chat ID (shared session for whole group) - assert.Equal(t, "group", inbound.Peer.Kind) - assert.Equal(t, "-100999", inbound.Peer.ID) - - // No parent peer metadata - assert.Empty(t, inbound.Metadata["parent_peer_kind"]) - assert.Empty(t, inbound.Metadata["parent_peer_id"]) + assert.Equal(t, "group", inbound.Context.ChatType) + assert.Empty(t, inbound.Context.TopicID) } func assertHandleMessageQuotedUserReply( @@ -700,7 +684,7 @@ func assertHandleMessageQuotedUserReply( inbound, ok := <-messageBus.InboundChan() require.True(t, ok) - assert.Equal(t, strconv.Itoa(replyMessageID), inbound.Metadata["reply_to_message_id"]) + assert.Equal(t, strconv.Itoa(replyMessageID), inbound.Context.ReplyToMessageID) assert.Equal(t, expectedContent, inbound.Content) } @@ -786,7 +770,7 @@ func TestHandleMessage_ReplyToOwnBotMessage_UsesAssistantRole(t *testing.T) { inbound, ok := <-messageBus.InboundChan() require.True(t, ok) - assert.Equal(t, "101", inbound.Metadata["reply_to_message_id"]) + assert.Equal(t, "101", inbound.Context.ReplyToMessageID) assert.Equal( t, "[quoted assistant message from afjcjsbx_picoclaw_bot]: Fatto! Ho creato il file notizie_2026_03_28.md\n\nti ricordi questo file?", diff --git a/pkg/channels/wecom/wecom_test.go b/pkg/channels/wecom/wecom_test.go index b3a87e246..f71616fcb 100644 --- a/pkg/channels/wecom/wecom_test.go +++ b/pkg/channels/wecom/wecom_test.go @@ -50,11 +50,11 @@ func TestDispatchIncoming_UsesActualChatIDAndStoresReqIDRoute(t *testing.T) { if inbound.MessageID != "msg-1" { t.Fatalf("inbound MessageID = %q, want msg-1", inbound.MessageID) } - if inbound.Peer.ID != "chat-1" { - t.Fatalf("inbound Peer.ID = %q, want chat-1", inbound.Peer.ID) + if inbound.Context.ChatType != "direct" { + t.Fatalf("inbound Context.ChatType = %q, want direct", inbound.Context.ChatType) } - if inbound.Metadata["req_id"] != "req-1" { - t.Fatalf("inbound req_id = %q, want req-1", inbound.Metadata["req_id"]) + if inbound.Context.ReplyHandles["req_id"] != "req-1" { + t.Fatalf("inbound req_id = %q, want req-1", inbound.Context.ReplyHandles["req_id"]) } default: t.Fatal("expected inbound message to be published")