mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(cron): propagate sessionKey to prevent duplicate tool responses
This commit is contained in:
+1
-1
@@ -357,7 +357,7 @@ func (t *CronTool) ExecuteJob(ctx context.Context, job *cron.CronJob) string {
|
||||
}
|
||||
|
||||
if response != "" {
|
||||
t.executor.PublishResponseIfNeeded(ctx, channel, chatID, "", response)
|
||||
t.executor.PublishResponseIfNeeded(ctx, channel, chatID, sessionKey, response)
|
||||
}
|
||||
return "ok"
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ type stubJobExecutor struct {
|
||||
publishedResp string
|
||||
publishedChan string
|
||||
publishedChatID string
|
||||
publishedKey string
|
||||
}
|
||||
|
||||
func (s *stubJobExecutor) ProcessDirectWithChannel(
|
||||
@@ -47,6 +48,7 @@ func (s *stubJobExecutor) PublishResponseIfNeeded(
|
||||
s.publishedResp = response
|
||||
s.publishedChan = channel
|
||||
s.publishedChatID = chatID
|
||||
s.publishedKey = sessionKey
|
||||
}
|
||||
|
||||
func newTestCronToolWithExecutorAndConfig(t *testing.T, executor JobExecutor, cfg *config.Config) *CronTool {
|
||||
@@ -283,6 +285,9 @@ func TestCronTool_ExecuteJobPublishesAgentResponse(t *testing.T) {
|
||||
if executor.publishedResp != "generated reply" {
|
||||
t.Fatalf("published response = %q, want generated reply", executor.publishedResp)
|
||||
}
|
||||
if executor.publishedKey != executor.lastKey {
|
||||
t.Fatalf("published sessionKey = %q, want %q", executor.publishedKey, executor.lastKey)
|
||||
}
|
||||
if executor.publishedChan != "telegram" || executor.publishedChatID != "chat-1" {
|
||||
t.Fatalf("published target = %s/%s, want telegram/chat-1", executor.publishedChan, executor.publishedChatID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user