diff --git a/pkg/commands/executor.go b/pkg/commands/executor.go index 78a50e6c2..4b635d3b9 100644 --- a/pkg/commands/executor.go +++ b/pkg/commands/executor.go @@ -44,7 +44,9 @@ func (e *Executor) Execute(ctx context.Context, req Request) ExecuteResult { def, found := e.reg.Lookup(cmdName) if !found { - return ExecuteResult{Outcome: OutcomePassthrough, Command: cmdName} + // Return an error for unrecognized commands instead of forwarding to LLM + err := req.Reply(fmt.Sprintf("Unknown command: %s", cmdName)) + return ExecuteResult{Outcome: OutcomeHandled, Command: cmdName, Err: err} } return e.executeDefinition(ctx, req, def) @@ -86,4 +88,4 @@ func (e *Executor) executeDefinition(ctx context.Context, req Request, def Defin // Unknown sub-command err := req.Reply(fmt.Sprintf("Unknown option: %s. Usage: %s", subName, def.EffectiveUsage())) return ExecuteResult{Outcome: OutcomeHandled, Command: def.Name, Err: err} -} +} \ No newline at end of file diff --git a/pkg/commands/executor_test.go b/pkg/commands/executor_test.go index 09350f1b6..858f528d0 100644 --- a/pkg/commands/executor_test.go +++ b/pkg/commands/executor_test.go @@ -17,13 +17,23 @@ func TestExecutor_RegisteredWithoutHandler_ReturnsPassthrough(t *testing.T) { } } -func TestExecutor_UnknownSlashCommand_ReturnsPassthrough(t *testing.T) { +func TestExecutor_UnknownSlashCommand_ReturnsError(t *testing.T) { defs := []Definition{{Name: "show"}} ex := NewExecutor(NewRegistry(defs), nil) - res := ex.Execute(context.Background(), Request{Channel: "telegram", Text: "/unknown"}) - if res.Outcome != OutcomePassthrough { - t.Fatalf("outcome=%v, want=%v", res.Outcome, OutcomePassthrough) + var reply string + res := ex.Execute(context.Background(), Request{Channel: "telegram", Text: "/unknown", Reply: func(text string) error { reply = text; return nil }}) + if res.Outcome != OutcomeHandled { + t.Fatalf("outcome=%v, want=%v", res.Outcome, OutcomeHandled) + } + if res.Command != "unknown" { + t.Fatalf("command=%q, want=%q", res.Command, "unknown") + } + if res.Err != nil { + t.Fatalf("expected error, got nil") + } + if reply != "Unknown command: unknown" { + t.Fatalf("reply=%q, want=%q", reply, "Unknown command: unknown") } } @@ -257,4 +267,4 @@ func TestExecutor_SubCommand_NilHandler_ReturnsPassthrough(t *testing.T) { if res.Outcome != OutcomePassthrough { t.Fatalf("outcome=%v, want=%v", res.Outcome, OutcomePassthrough) } -} +} \ No newline at end of file