X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/ec230eee6b06580031637bc97c99ec6db7b41926..2501e78d10204fac2298db0dee84b3dce379e09b:/daemon_start_helper_test.go?ds=inline diff --git a/daemon_start_helper_test.go b/daemon_start_helper_test.go index cf1fbf6..6e4e328 100644 --- a/daemon_start_helper_test.go +++ b/daemon_start_helper_test.go @@ -4,25 +4,45 @@ import ( "context" "path/filepath" "testing" + "time" "github.com/stretchr/testify/require" ) -// daemonStartTestWithBot is daemonStartTest with bot, which can be nil. WhatsApp -// is not linked. +// daemonStartTestWithBot is daemonStartTest with bot, which can be nil. +// WhatsApp is not linked. func daemonStartTestWithBot(t *testing.T, server *ModelFake, bot *TelegramBot) string { t.Helper() + whatsapp, _, _ := whatsappStartTest(t, t.TempDir(), newTestClock()) + socket, _ := daemonStartTestWithWhatsApp(t, server, bot, whatsapp) + + return socket +} + +// daemonStartTestWithWhatsApp is daemonStartTestWithBot with whatsapp. It also +// returns the memory of the agent. +func daemonStartTestWithWhatsApp(t *testing.T, server *ModelFake, bot *TelegramBot, whatsapp *WhatsApp) (string, *Memory) { + t.Helper() + + clock := newTestClock() + + return daemonStartTestWithSchedules(t, server, bot, whatsapp, newTestSchedules(t, clock.Now), clock.Now) +} + +// daemonStartTestWithSchedules is daemonStartTestWithWhatsApp with schedules, +// and with clock for the memory and the turns. +func daemonStartTestWithSchedules(t *testing.T, server *ModelFake, bot *TelegramBot, whatsapp *WhatsApp, schedules *Schedules, clock func() time.Time) (string, *Memory) { + t.Helper() + dir := t.TempDir() agent, err := openAgent(filepath.Join(dir, daemonAgentDirName)) require.NoError(t, err) agent.config.Workdir = t.TempDir() - clock := newTestClock() - memory, err := openMemory(t.Context(), agent.dir, clock.Now, newFakeSummarizer()) + memory, err := openMemory(t.Context(), agent.dir, clock, newFakeSummarizer()) require.NoError(t, err) - whatsapp, _ := whatsappStartTest(t, dir) socket := filepath.Join(dir, socketFileName) listener, err := daemonListenSocket(socket) require.NoError(t, err) @@ -31,8 +51,8 @@ func daemonStartTestWithBot(t *testing.T, server *ModelFake, bot *TelegramBot) s ctx, cancel := context.WithCancel(t.Context()) done := make(chan error) go func() { - done <- daemonServe(ctx, listener, bot, whatsapp, func(notify func(Event)) (*TurnLoop, error) { - return newTurnLoop(agent, memory, newTestSubagents(t), client, clock.Now, notify) + done <- daemonServe(ctx, listener, bot, whatsapp, schedules, func(notify func(Event)) (*TurnLoop, error) { + return newTurnLoop(agent, memory, newTestSubagents(t), whatsapp, schedules, client, clock, notify) }) }() @@ -42,5 +62,5 @@ func daemonStartTestWithBot(t *testing.T, server *ModelFake, bot *TelegramBot) s require.NoError(t, memory.Close()) }) - return socket + return socket, memory }