feat: add DingTalk picture agent QA

This commit is contained in:
姚章浩
2026-07-20 17:49:03 +08:00
parent ea262551c0
commit ea54b229ee
17 changed files with 1345 additions and 71 deletions
+111
View File
@@ -142,6 +142,117 @@ func TestBotCallbackFromSDK(t *testing.T) {
})
}
func TestBotCallbackFromSDKPicture(t *testing.T) {
t.Parallel()
t.Run("extracts downloadCode from picture content", func(t *testing.T) {
t.Parallel()
data := &chatbot.BotCallbackDataModel{
ConversationType: "1",
Msgtype: "picture",
MsgId: "msg-pic-1",
Content: map[string]interface{}{
"downloadCode": " abc123 ",
},
}
cb, err := BotCallbackFromSDK(data)
if err != nil {
t.Fatalf("BotCallbackFromSDK() error = %v", err)
}
if cb.Msgtype != "picture" {
t.Fatalf("Msgtype = %q, want picture", cb.Msgtype)
}
if cb.DownloadCode != "abc123" {
t.Fatalf("DownloadCode = %q, want trimmed abc123", cb.DownloadCode)
}
if cb.Text != "" {
t.Fatalf("Text = %q, want empty for picture", cb.Text)
}
})
t.Run("malformed content keeps picture with empty downloadCode", func(t *testing.T) {
t.Parallel()
data := &chatbot.BotCallbackDataModel{
ConversationType: "1",
Msgtype: "picture",
MsgId: "msg-pic-2",
Content: "not-a-map",
}
cb, err := BotCallbackFromSDK(data)
if err != nil {
t.Fatalf("BotCallbackFromSDK() error = %v", err)
}
if cb.Msgtype != "picture" {
t.Fatalf("Msgtype = %q, want picture (never downgrade)", cb.Msgtype)
}
if cb.DownloadCode != "" {
t.Fatalf("DownloadCode = %q, want empty", cb.DownloadCode)
}
})
t.Run("missing downloadCode keeps picture", func(t *testing.T) {
t.Parallel()
data := &chatbot.BotCallbackDataModel{
ConversationType: "1",
Msgtype: "picture",
MsgId: "msg-pic-3",
Content: map[string]interface{}{
"content": map[string]interface{}{},
},
}
cb, err := BotCallbackFromSDK(data)
if err != nil {
t.Fatalf("BotCallbackFromSDK() error = %v", err)
}
if cb.Msgtype != "picture" {
t.Fatalf("Msgtype = %q, want picture", cb.Msgtype)
}
if cb.DownloadCode != "" {
t.Fatalf("DownloadCode = %q, want empty", cb.DownloadCode)
}
})
t.Run("text regression: Msgtype normalized", func(t *testing.T) {
t.Parallel()
data := &chatbot.BotCallbackDataModel{
ConversationType: "1",
Msgtype: " TEXT ",
MsgId: "msg-t-1",
Text: chatbot.BotCallbackDataTextModel{Content: "hello"},
}
cb, err := BotCallbackFromSDK(data)
if err != nil {
t.Fatalf("BotCallbackFromSDK() error = %v", err)
}
if cb.Msgtype != "text" {
t.Fatalf("Msgtype = %q, want normalized text", cb.Msgtype)
}
if cb.Text != "hello" {
t.Fatalf("Text = %q, want hello", cb.Text)
}
})
t.Run("nil content keeps picture", func(t *testing.T) {
t.Parallel()
data := &chatbot.BotCallbackDataModel{
ConversationType: "1",
Msgtype: "picture",
MsgId: "msg-pic-4",
Content: nil,
}
cb, err := BotCallbackFromSDK(data)
if err != nil {
t.Fatalf("BotCallbackFromSDK() error = %v", err)
}
if cb.Msgtype != "picture" {
t.Fatalf("Msgtype = %q, want picture", cb.Msgtype)
}
if cb.DownloadCode != "" {
t.Fatalf("DownloadCode = %q, want empty", cb.DownloadCode)
}
})
}
func mustTestHandler(t *testing.T) *Handler {
t.Helper()
return newTestHandler(t, &fakeQA{}, &fakeReply{})