})
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) {