mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
test(message): cover slack and feishu media fallbacks
This commit is contained in:
@@ -52,6 +52,8 @@ type FeishuChannel struct {
|
||||
|
||||
progress *channels.ToolFeedbackAnimator
|
||||
deleteMessageFn func(context.Context, string, string) error
|
||||
sendMediaPartFn func(context.Context, string, bus.MediaPart, media.MediaStore) error
|
||||
sendTextFn func(context.Context, string, string) (string, error)
|
||||
}
|
||||
|
||||
type cachedMessage struct {
|
||||
@@ -78,6 +80,8 @@ func NewFeishuChannel(bc *config.Channel, cfg *config.FeishuSettings, bus *bus.M
|
||||
client: lark.NewClient(cfg.AppID, cfg.AppSecret.String(), opts...),
|
||||
}
|
||||
ch.deleteMessageFn = ch.deleteMessageAPI
|
||||
ch.sendMediaPartFn = ch.sendMediaPart
|
||||
ch.sendTextFn = ch.sendText
|
||||
ch.progress = channels.NewToolFeedbackAnimator(ch.EditMessage)
|
||||
ch.SetOwner(ch)
|
||||
return ch, nil
|
||||
@@ -500,13 +504,13 @@ func (c *FeishuChannel) SendMedia(ctx context.Context, msg bus.OutboundMediaMess
|
||||
caption := firstMediaCaption(msg.Parts)
|
||||
sentAny := false
|
||||
for _, part := range msg.Parts {
|
||||
if err := c.sendMediaPart(ctx, msg.ChatID, part, store); err != nil {
|
||||
if err := c.sendMediaPartFn(ctx, msg.ChatID, part, store); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sentAny = true
|
||||
}
|
||||
if sentAny && caption != "" {
|
||||
if _, err := c.sendText(ctx, msg.ChatID, caption); err != nil {
|
||||
if _, err := c.sendTextFn(ctx, msg.ChatID, caption); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ import (
|
||||
|
||||
larkim "github.com/larksuite/oapi-sdk-go/v3/service/im/v1"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/bus"
|
||||
"github.com/sipeed/picoclaw/pkg/channels"
|
||||
"github.com/sipeed/picoclaw/pkg/media"
|
||||
)
|
||||
|
||||
func TestExtractContent(t *testing.T) {
|
||||
@@ -319,6 +321,43 @@ func TestFinalizeTrackedToolFeedbackMessage_ClearAfterSuccessfulEdit(t *testing.
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendMedia_SendsCaptionFallbackAfterMedia(t *testing.T) {
|
||||
ch := &FeishuChannel{
|
||||
BaseChannel: channels.NewBaseChannel("feishu", nil, nil, nil),
|
||||
progress: channels.NewToolFeedbackAnimator(nil),
|
||||
}
|
||||
ch.SetRunning(true)
|
||||
ch.SetMediaStore(media.NewFileMediaStore())
|
||||
|
||||
var mediaOrder []string
|
||||
var textCalls []string
|
||||
ch.sendMediaPartFn = func(ctx context.Context, chatID string, part bus.MediaPart, store media.MediaStore) error {
|
||||
mediaOrder = append(mediaOrder, part.Type)
|
||||
return nil
|
||||
}
|
||||
ch.sendTextFn = func(ctx context.Context, chatID, text string) (string, error) {
|
||||
textCalls = append(textCalls, chatID+"|"+text)
|
||||
return "msg-1", nil
|
||||
}
|
||||
|
||||
_, err := ch.SendMedia(context.Background(), bus.OutboundMediaMessage{
|
||||
ChatID: "oc_123",
|
||||
Parts: []bus.MediaPart{
|
||||
{Type: "image", Caption: "shared caption"},
|
||||
{Type: "file"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("SendMedia() error = %v", err)
|
||||
}
|
||||
if len(mediaOrder) != 2 {
|
||||
t.Fatalf("media sends = %v, want 2 sends", mediaOrder)
|
||||
}
|
||||
if len(textCalls) != 1 || textCalls[0] != "oc_123|shared caption" {
|
||||
t.Fatalf("textCalls = %v, want [oc_123|shared caption]", textCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFinalizeTrackedToolFeedbackMessage_StopsTrackingBeforeEdit(t *testing.T) {
|
||||
ch := &FeishuChannel{
|
||||
progress: channels.NewToolFeedbackAnimator(nil),
|
||||
|
||||
Reference in New Issue
Block a user