fix(cron): add missing 'action' arg for command job execution

CronTool.ExecuteJob was calling ExecTool.Execute without setting
action='run' in the args map. ExecTool.Execute requires the action
field and returns ErrorResult('action is required') immediately when
it's missing. This caused all cron command jobs to silently fail.

Adds a test covering the command execution happy path.
This commit is contained in:
hschne
2026-05-24 20:05:03 +02:00
parent d499cbece4
commit 7af40d49eb
2 changed files with 26 additions and 0 deletions
+1
View File
@@ -320,6 +320,7 @@ func (t *CronTool) ExecuteJob(ctx context.Context, job *cron.CronJob) string {
}
args := map[string]any{
"action": "run",
"command": job.Payload.Command,
"__channel": channel,
"__chat_id": chatID,
+25
View File
@@ -329,6 +329,31 @@ func TestCronTool_ExecuteJobSkipsWhenMessageToolAlreadySent(t *testing.T) {
}
}
func TestCronTool_ExecuteJobRunsCommand(t *testing.T) {
tool := newTestCronToolWithConfig(t, config.DefaultConfig())
job := &cron.CronJob{}
job.Payload.Channel = "cli"
job.Payload.To = "direct"
job.Payload.Command = "echo cron-test-ok"
if got := tool.ExecuteJob(context.Background(), job); got != "ok" {
t.Fatalf("ExecuteJob() = %q, want ok", got)
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
var msg bus.OutboundMessage
select {
case msg = <-tool.msgBus.OutboundChan():
case <-ctx.Done():
t.Fatal("timeout waiting for outbound message")
}
if !strings.Contains(msg.Content, "cron-test-ok") {
t.Fatalf("expected command output containing 'cron-test-ok', got: %s", msg.Content)
}
}
func TestCronTool_ExecuteJobReturnsErrorWithoutPublish(t *testing.T) {
executor := &stubJobExecutor{
response: "this response must not be published",