From 70e8cf07252c24567666c3990018971d5adf3c53 Mon Sep 17 00:00:00 2001 From: Hoshina Date: Thu, 26 Mar 2026 11:07:03 +0800 Subject: [PATCH] feat(agent): update requeueInboundMessage to publish back to inbound bus and add corresponding tests --- pkg/agent/loop.go | 6 +----- pkg/agent/loop_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index c9efb318b..857610a72 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -1393,11 +1393,7 @@ func (al *AgentLoop) requeueInboundMessage(msg bus.InboundMessage) error { } pubCtx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - return al.bus.PublishOutbound(pubCtx, bus.OutboundMessage{ - Channel: msg.Channel, - ChatID: msg.ChatID, - Content: msg.Content, - }) + return al.bus.PublishInbound(pubCtx, msg) } func (al *AgentLoop) processSystemMessage( diff --git a/pkg/agent/loop_test.go b/pkg/agent/loop_test.go index 341d15a2f..af89003cb 100644 --- a/pkg/agent/loop_test.go +++ b/pkg/agent/loop_test.go @@ -225,6 +225,42 @@ func TestProcessMessage_UseCommandLoadsRequestedSkill(t *testing.T) { } } +func TestRequeueInboundMessage_PublishesBackToInboundBus(t *testing.T) { + msgBus := bus.NewMessageBus() + al := &AgentLoop{bus: msgBus} + + original := bus.InboundMessage{ + Channel: "feishu", + SenderID: "feishu:user-1", + ChatID: "chat-1", + Content: "follow-up message", + MessageID: "msg-1", + } + + if err := al.requeueInboundMessage(original); err != nil { + t.Fatalf("requeueInboundMessage() error = %v", err) + } + + select { + case got := <-msgBus.InboundChan(): + if got.Channel != original.Channel || + got.SenderID != original.SenderID || + got.ChatID != original.ChatID || + got.Content != original.Content || + got.MessageID != original.MessageID { + t.Fatalf("requeued message = %+v, want %+v", got, original) + } + case <-time.After(2 * time.Second): + t.Fatal("timeout waiting for requeued inbound message") + } + + select { + case outbound := <-msgBus.OutboundChan(): + t.Fatalf("unexpected outbound message after requeue: %+v", outbound) + default: + } +} + func TestHandleCommand_UseCommandRejectsUnknownSkill(t *testing.T) { tmpDir := t.TempDir() cfg := &config.Config{