X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/5bb22ac2fc501bad7327c119f1d3ac514e3d5398..3f61d7080bc1cb14988a65ac433cbc5959857c16:/telegram_test.go?ds=sidebyside diff --git a/telegram_test.go b/telegram_test.go index 81e6e18..66a5f47 100644 --- a/telegram_test.go +++ b/telegram_test.go @@ -127,6 +127,74 @@ func TestStopFromTelegramInterruptsTheTurn(t *testing.T) { }) telegramWaitForSent(t, telegram, "Error: interrupted", "No turn runs.") + + telegram.Add(TelegramUpdate{ + UpdateID: 4, + Message: telegramOwnerMessage(stopCommand + " BlueFox"), + }) + + telegramWaitForSent(t, telegram, "No turn runs.", "No subagent BlueFox runs.") +} + +func TestBotShowsOnlyTheStartAndTheEndOfASubagent(t *testing.T) { + telegram := newTelegramFake(t) + server := newModelFake(t) + server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + last := subagentTestLastItem(call) + switch { + case subagentTestCall(call): + // The report comes after the reply of the turn of the spawn. + require.Eventually(t, func() bool { + return slices.Contains(telegram.Sent(), "Started.") + }, 10*time.Second, time.Millisecond) + modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("There are 3 files.")}, 100, 0, 5)) + case last["type"] == "function_call_output": + modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("Started.")}, 100, 0, 5)) + case strings.HasPrefix(subagentTestText(last), "["): + modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("It counted 3 files.")}, 100, 0, 5)) + default: + modelWriteEvents(w, modelCompletedEvent([]any{modelFunctionCallItem("fc_1", "call_1", "spawn", `{"tasks":["Count the files."],"effort":null}`)}, 100, 0, 5)) + } + } + + bot, _ := telegramStartTestBot(t, telegram) + daemonStartTestWithBot(t, server, bot) + telegram.Add(TelegramUpdate{ + UpdateID: 1, + Message: telegramOwnerMessage("Count the files in a subagent."), + }) + + require.Eventually(t, func() bool { + return slices.Contains(telegram.Sent(), "It counted 3 files.") + }, 10*time.Second, time.Millisecond) + + sent := telegram.Sent() + name := strings.TrimSuffix(strings.TrimPrefix(sent[0], "["), "] started") + require.True(t, subagentNameValid(name), sent[0]) + require.Equal(t, []string{ + "[" + name + "] started", + "Started.", + "[" + name + "] finished", + "It counted 3 files.", + }, sent) +} + +func TestBotSkipsTheWorkOfWhatsAppAndTheSchedules(t *testing.T) { + bot := &TelegramBot{ + ready: make(chan struct{}, 1), + } + + bot.Notify(Event{ + Kind: "work", + Source: whatsappSource, + Text: "[WhatsApp] Ana Souza", + }) + bot.Notify(Event{ + Kind: "work", + Source: scheduleSource, + Text: "[Schedule 1] Sunday 2026-11-08 20:05 -03:00, once", + }) + require.Empty(t, bot.queue) } func TestBotStartsAtTheStoredOffset(t *testing.T) {