Skip to content

Commit ab6d394

Browse files
authored
Merge pull request #2938 from hschne/fix/cron-command-action
fix(cron): add missing action arg for command job execution
2 parents d499cbe + 7af40d4 commit ab6d394

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

pkg/tools/cron.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ func (t *CronTool) ExecuteJob(ctx context.Context, job *cron.CronJob) string {
320320
}
321321

322322
args := map[string]any{
323+
"action": "run",
323324
"command": job.Payload.Command,
324325
"__channel": channel,
325326
"__chat_id": chatID,

pkg/tools/cron_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,31 @@ func TestCronTool_ExecuteJobSkipsWhenMessageToolAlreadySent(t *testing.T) {
329329
}
330330
}
331331

332+
func TestCronTool_ExecuteJobRunsCommand(t *testing.T) {
333+
tool := newTestCronToolWithConfig(t, config.DefaultConfig())
334+
job := &cron.CronJob{}
335+
job.Payload.Channel = "cli"
336+
job.Payload.To = "direct"
337+
job.Payload.Command = "echo cron-test-ok"
338+
339+
if got := tool.ExecuteJob(context.Background(), job); got != "ok" {
340+
t.Fatalf("ExecuteJob() = %q, want ok", got)
341+
}
342+
343+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
344+
defer cancel()
345+
346+
var msg bus.OutboundMessage
347+
select {
348+
case msg = <-tool.msgBus.OutboundChan():
349+
case <-ctx.Done():
350+
t.Fatal("timeout waiting for outbound message")
351+
}
352+
if !strings.Contains(msg.Content, "cron-test-ok") {
353+
t.Fatalf("expected command output containing 'cron-test-ok', got: %s", msg.Content)
354+
}
355+
}
356+
332357
func TestCronTool_ExecuteJobReturnsErrorWithoutPublish(t *testing.T) {
333358
executor := &stubJobExecutor{
334359
response: "this response must not be published",

0 commit comments

Comments
 (0)