mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-11 03:13:24 +00:00
82 lines
2.7 KiB
Go
82 lines
2.7 KiB
Go
package channels
|
|
|
|
import "testing"
|
|
|
|
func TestCopyRoutingMeta_PreservesPancakeCommentRouting(t *testing.T) {
|
|
src := map[string]string{
|
|
"pancake_mode": "comment",
|
|
"reply_to_comment_id": "msg-123",
|
|
"sender_id": "user-123",
|
|
}
|
|
|
|
got := copyRoutingMeta(src)
|
|
|
|
for key, want := range map[string]string{
|
|
"pancake_mode": "comment",
|
|
"reply_to_comment_id": "msg-123",
|
|
"sender_id": "user-123",
|
|
} {
|
|
if got[key] != want {
|
|
t.Fatalf("copyRoutingMeta()[%q] = %q, want %q", key, got[key], want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCopyFinalRoutingMeta_PreservesPlaceholderAndPancakeMode(t *testing.T) {
|
|
src := map[string]string{
|
|
"placeholder_key": "placeholder-123",
|
|
"pancake_mode": "comment",
|
|
}
|
|
|
|
got := CopyFinalRoutingMeta(src)
|
|
|
|
if got["placeholder_key"] != "placeholder-123" {
|
|
t.Fatalf("CopyFinalRoutingMeta()[%q] = %q, want %q", "placeholder_key", got["placeholder_key"], "placeholder-123")
|
|
}
|
|
if got["pancake_mode"] != "comment" {
|
|
t.Fatalf("CopyFinalRoutingMeta()[%q] = %q, want %q", "pancake_mode", got["pancake_mode"], "comment")
|
|
}
|
|
}
|
|
|
|
// TestCopyRoutingMeta_PreservesPancakePrivateReplyKeys verifies the metadata
|
|
// keys used by the private_reply DM (post_id, display_name, sender_id)
|
|
// survive inbound→outbound copy.
|
|
func TestCopyRoutingMeta_PreservesPancakePrivateReplyKeys(t *testing.T) {
|
|
src := map[string]string{
|
|
"post_id": "post-42",
|
|
"display_name": "Tuấn",
|
|
"sender_id": "user-1",
|
|
}
|
|
|
|
got := copyRoutingMeta(src)
|
|
for k, want := range src {
|
|
if got[k] != want {
|
|
t.Fatalf("copyRoutingMeta()[%q] = %q, want %q", k, got[k], want)
|
|
}
|
|
}
|
|
|
|
final := CopyFinalRoutingMeta(src)
|
|
for k, want := range src {
|
|
if final[k] != want {
|
|
t.Fatalf("CopyFinalRoutingMeta()[%q] = %q, want %q", k, final[k], want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestCopyRoutingMeta_PreservesBitrixVisibility guards the whisper-leak
|
|
// regression: intermediate replies (quick-ack, progress, reasoning bubbles,
|
|
// block replies) must carry bitrix_visibility so a whisper-mode turn does not
|
|
// leak its FIRST (intermediate) message to the external connector while only
|
|
// the final answer is whispered. copyRoutingMeta is the path used by every
|
|
// intermediate publish site; CopyFinalRoutingMeta must keep it too.
|
|
func TestCopyRoutingMeta_PreservesBitrixVisibility(t *testing.T) {
|
|
src := map[string]string{"bitrix_visibility": "whisper"}
|
|
|
|
if got := copyRoutingMeta(src); got["bitrix_visibility"] != "whisper" {
|
|
t.Fatalf("copyRoutingMeta()[%q] = %q, want %q", "bitrix_visibility", got["bitrix_visibility"], "whisper")
|
|
}
|
|
if got := CopyFinalRoutingMeta(src); got["bitrix_visibility"] != "whisper" {
|
|
t.Fatalf("CopyFinalRoutingMeta()[%q] = %q, want %q", "bitrix_visibility", got["bitrix_visibility"], "whisper")
|
|
}
|
|
}
|