X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/09cde69fdffe2721434392036f98dc241177f5a1..6d1d9d9a7cf90b25a2e10af1c5bc56faee7e494c:/telegram_test.go?ds=sidebyside diff --git a/telegram_test.go b/telegram_test.go index 9111d13..2f944fa 100644 --- a/telegram_test.go +++ b/telegram_test.go @@ -14,9 +14,9 @@ import ( ) func TestOwnerTalksToTheAgentThroughTelegram(t *testing.T) { - server := newFakeResponses(t) - server.reply = func(w http.ResponseWriter, call fakeCall) { - writeEvents(w, completedEvent([]any{messageItem("Hello from the agent.")}, 100, 0, 5)) + server := newModelFake(t) + server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("Hello from the agent.")}, 100, 0, 5)) } telegram := newTelegramFake(t) @@ -43,7 +43,7 @@ func TestOwnerTalksToTheAgentThroughTelegram(t *testing.T) { func TestBotIgnoresEveryoneButTheOwner(t *testing.T) { telegram := newTelegramFake(t) bot, logs := telegramStartTestBot(t, telegram) - socket := startTestDaemonWithBot(t, newFakeResponses(t), bot) + socket := startTestDaemonWithBot(t, newModelFake(t), bot) terminal := startTestClient(t, socket) terminal.WaitFor(t, "[connected to OneChat]") @@ -81,7 +81,7 @@ func TestBotIgnoresEveryoneButTheOwner(t *testing.T) { func TestBotAnswersThatOnlyTextIsSupported(t *testing.T) { telegram := newTelegramFake(t) bot, _ := telegramStartTestBot(t, telegram) - startTestDaemonWithBot(t, newFakeResponses(t), bot) + startTestDaemonWithBot(t, newModelFake(t), bot) telegram.Add(TelegramUpdate{ UpdateID: 1, @@ -92,14 +92,14 @@ func TestBotAnswersThatOnlyTextIsSupported(t *testing.T) { } func TestStopFromTelegramInterruptsTheTurn(t *testing.T) { - server := newFakeResponses(t) + server := newModelFake(t) arrived := make(chan struct{}) release := make(chan struct{}) t.Cleanup(func() { close(release) }) - server.reply = func(w http.ResponseWriter, call fakeCall) { + server.reply = func(w http.ResponseWriter, call ModelFakeCall) { close(arrived) <-release } @@ -130,9 +130,9 @@ func TestStopFromTelegramInterruptsTheTurn(t *testing.T) { } func TestBotStartsAtTheStoredOffset(t *testing.T) { - server := newFakeResponses(t) - server.reply = func(w http.ResponseWriter, call fakeCall) { - writeEvents(w, completedEvent([]any{messageItem("ok")}, 100, 0, 5)) + server := newModelFake(t) + server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5)) } telegram := newTelegramFake(t) @@ -164,9 +164,9 @@ func TestBotStartsAtTheStoredOffset(t *testing.T) { } func TestBotTriesAgainAfterFailures(t *testing.T) { - server := newFakeResponses(t) - server.reply = func(w http.ResponseWriter, call fakeCall) { - writeEvents(w, completedEvent([]any{messageItem("ok")}, 100, 0, 5)) + server := newModelFake(t) + server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5)) } telegram := newTelegramFake(t) @@ -229,9 +229,9 @@ 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 := newFakeResponses(t) - server.reply = func(w http.ResponseWriter, call fakeCall) { - writeEvents(w, completedEvent([]any{messageItem(reply)}, 100, 0, 5)) + server := newModelFake(t) + server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem(reply)}, 100, 0, 5)) } telegram := newTelegramFake(t) @@ -423,7 +423,7 @@ func TestBotLogsNoTokenWhenTheNetworkFails(t *testing.T) { telegram.Close() bot, logs := telegramStartTestBot(t, telegram) - startTestDaemonWithBot(t, newFakeResponses(t), bot) + startTestDaemonWithBot(t, newModelFake(t), bot) require.Eventually(t, func() bool { return strings.Count(logs.String(), "no valid answer") >= 2