Refine cron outbound fix with smaller implementation

This commit is contained in:
野生派Coder~
2026-03-02 22:49:20 +08:00
parent 798a3bd26e
commit e85bf4c5b8
2 changed files with 32 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import (
"path/filepath"
"sync"
"testing"
"time"
"clawgo/pkg/bus"
"clawgo/pkg/config"
@@ -107,6 +108,27 @@ func TestProcessSystemMessage_UsesOriginSessionKey(t *testing.T) {
}
}
func TestProcessInbound_SystemMessagePublishesToOriginChannel(t *testing.T) {
rp := &recordingProvider{}
loop := setupLoop(t, rp)
in := bus.InboundMessage{Channel: "system", SenderID: "cron", ChatID: "telegram:chat-1", Content: "system task"}
loop.processInbound(context.Background(), in)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
out, ok := loop.bus.SubscribeOutbound(ctx)
if !ok {
t.Fatalf("expected outbound message")
}
if out.Channel != "telegram" {
t.Fatalf("expected outbound channel telegram, got %q", out.Channel)
}
if out.ChatID != "chat-1" {
t.Fatalf("expected outbound chat_id chat-1, got %q", out.ChatID)
}
}
func summarizeUsers(msgs []providers.Message) []string {
out := []string{}
for _, m := range msgs {