X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/7088b82414bdf947a6f88918c0a7b2c7fb0c53ef..4c199e7d93b6a4529ed5956807911b5f6c5489a7:/telegram_test.go diff --git a/telegram_test.go b/telegram_test.go index 48e5503..f1a76b6 100644 --- a/telegram_test.go +++ b/telegram_test.go @@ -16,7 +16,7 @@ import ( func TestOwnerTalksToTheAgentThroughTelegram(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("Hello from the agent.")}, 100, 0, 5)) } @@ -100,7 +100,7 @@ func TestStopFromTelegramInterruptsTheTurn(t *testing.T) { close(release) }) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(_ http.ResponseWriter, _ ModelFakeCall) { close(arrived) <-release } @@ -200,7 +200,7 @@ func TestBotSkipsTheWorkOfWhatsAppAndTheSchedules(t *testing.T) { func TestBotStartsAtTheStoredOffset(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5)) } @@ -223,7 +223,7 @@ func TestBotStartsAtTheStoredOffset(t *testing.T) { terminal.WaitFor(t, "[connected to OneChat]") telegramWaitForSent(t, telegram, "ok") - require.Equal(t, float64(10), telegram.Calls()[0].params["offset"]) + require.InDelta(t, float64(10), telegram.Calls()[0].params["offset"], 0) require.NotContains(t, terminal.Output(), "handled before the restart") require.Eventually(t, func() bool { @@ -234,7 +234,7 @@ func TestBotStartsAtTheStoredOffset(t *testing.T) { func TestBotTriesAgainAfterFailures(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5)) } @@ -301,7 +301,7 @@ func TestDeliverTriesAgainAfterATimeout(t *testing.T) { func TestRepliesGoAsRichMessages(t *testing.T) { reply := "**Done.** The table:\n\n| Name | Size |\n|:-----|-----:|\n| `a.go` | 10 |\n\n- one\n- two\n\n```go\nx := 1\n```" server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem(reply)}, 100, 0, 5)) } @@ -322,6 +322,7 @@ func TestRepliesGoAsRichMessages(t *testing.T) { telegramWaitForSent(t, telegram, telegramTextOnly) var sends []TelegramFakeCall + for _, call := range telegram.Calls() { if call.method == "sendMessage" || call.method == "sendRichMessage" { sends = append(sends, call) @@ -433,6 +434,7 @@ func TestRichMessageFailures(t *testing.T) { }) var methods []string + for _, call := range telegram.Calls() { methods = append(methods, call.method) } @@ -551,6 +553,7 @@ func TestRefusedRichPartGoesWithTheTextAsWritten(t *testing.T) { }) var fallback, rich []string + for _, call := range telegram.Calls() { switch { case !call.ok: @@ -569,7 +572,7 @@ func TestRefusedRichPartGoesWithTheTextAsWritten(t *testing.T) { require.LessOrEqual(t, telegramUTF16Units(text), telegramMessageUnits) } - require.True(t, reply == strings.Join(fallback, "")+telegramUnescapeTags(rich[0]), "reply is not sent once and whole") + require.Equal(t, reply, strings.Join(fallback, "")+telegramUnescapeTags(rich[0]), "reply is not sent once and whole") } func TestRefusedEntitiesGoAgainAsPlainText(t *testing.T) { @@ -615,7 +618,7 @@ func TestBotLogsNoTokenWhenTheNetworkFails(t *testing.T) { func TestBotLogsAnOutageOnlyAtItsStartAndEnd(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5)) } @@ -640,6 +643,7 @@ func TestBotLogsAnOutageOnlyAtItsStartAndEnd(t *testing.T) { }) telegramWaitForSent(t, telegram, "ok") + lines := strings.Split(strings.TrimSuffix(logs.String(), "\n"), "\n") require.Len(t, lines, 2) require.Equal(t, "receive failed: 502 Bad Gateway (retry in 1ms)", lines[0])