From 4736b03c2c6d89e9ee9ca44fff508649ce6cb126 Mon Sep 17 00:00:00 2001 From: Alix-007 <267018309+Alix-007@users.noreply.github.com> Date: Sun, 29 Mar 2026 15:35:46 +0800 Subject: [PATCH] fix(cron): keep deliver=false job responses silent --- pkg/tools/cron.go | 3 ++- pkg/tools/cron_test.go | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/pkg/tools/cron.go b/pkg/tools/cron.go index 60d9d5e5a..89d09e4a2 100644 --- a/pkg/tools/cron.go +++ b/pkg/tools/cron.go @@ -411,7 +411,8 @@ func (t *CronTool) ExecuteJob(ctx context.Context, job *cron.CronJob) string { return fmt.Sprintf("Error: %v", err) } - if response != "" { + // deliver=false should execute silently: no outbound publish path. + if job.Payload.Deliver && response != "" { t.executor.PublishResponseIfNeeded(ctx, channel, chatID, response) } return "ok" diff --git a/pkg/tools/cron_test.go b/pkg/tools/cron_test.go index 186c6a75e..06852e0bc 100644 --- a/pkg/tools/cron_test.go +++ b/pkg/tools/cron_test.go @@ -280,7 +280,7 @@ func TestCronTool_ExecuteJobPublishesErrorWhenExecDisabled(t *testing.T) { } } -func TestCronTool_ExecuteJobPublishesAgentResponse(t *testing.T) { +func TestCronTool_ExecuteJobDeliverFalseRunsAgentSilently(t *testing.T) { executor := &stubJobExecutor{response: "generated reply"} tool := newTestCronToolWithExecutorAndConfig(t, executor, config.DefaultConfig()) @@ -302,11 +302,8 @@ func TestCronTool_ExecuteJobPublishesAgentResponse(t *testing.T) { if executor.lastPrompt != "send me a poem" { t.Fatalf("prompt = %q, want original message", executor.lastPrompt) } - if executor.publishedResp != "generated reply" { - t.Fatalf("published response = %q, want generated reply", executor.publishedResp) - } - if executor.publishedChan != "telegram" || executor.publishedChatID != "chat-1" { - t.Fatalf("published target = %s/%s, want telegram/chat-1", executor.publishedChan, executor.publishedChatID) + if executor.publishedResp != "" { + t.Fatalf("expected no published response for deliver=false, got %q", executor.publishedResp) } } @@ -365,8 +362,8 @@ func TestCronTool_ExecuteJobDirectiveAddsPromptPrefix(t *testing.T) { if executor.lastPrompt != wantPrompt { t.Fatalf("prompt = %q, want exact %q", executor.lastPrompt, wantPrompt) } - if executor.publishedResp != "directive result" { - t.Fatalf("published response = %q, want %q", executor.publishedResp, "directive result") + if executor.publishedResp != "" { + t.Fatalf("expected no published response for deliver=false directive job, got %q", executor.publishedResp) } } @@ -403,6 +400,29 @@ func TestCronTool_ExecuteJobDirectiveWithDeliverRoutesToAgent(t *testing.T) { } } +func TestCronTool_ExecuteJobDirectiveWithDeliverFalseStaysSilent(t *testing.T) { + executor := &stubJobExecutor{response: "agent processed"} + tool := newTestCronToolWithExecutorAndConfig(t, executor, config.DefaultConfig()) + + job := &cron.CronJob{ID: "job-dir-silent"} + job.Payload.Channel = "telegram" + job.Payload.To = "chat-1" + job.Payload.Message = "generate daily report" + job.Payload.Type = "directive" + job.Payload.Deliver = false + + if got := tool.ExecuteJob(context.Background(), job); got != "ok" { + t.Fatalf("ExecuteJob() = %q, want ok", got) + } + + if executor.lastPrompt == "" { + t.Fatal("expected agent to be called for directive+deliver=false, but ProcessDirectWithChannel was not invoked") + } + if executor.publishedResp != "" { + t.Fatalf("expected no published response for deliver=false directive job, got %q", executor.publishedResp) + } +} + func TestCronTool_ExecuteJobDeliverMessageDirectlyToBus(t *testing.T) { executor := &stubJobExecutor{response: "should not be called"} tool := newTestCronToolWithExecutorAndConfig(t, executor, config.DefaultConfig())