X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/56d959f2d573eef1be5c04d0bf1659fa30d36e7c..5b778ad04422dd456b7d673fb653f0353c47b0fe:/daemon_start_helper_test.go?ds=sidebyside diff --git a/daemon_start_helper_test.go b/daemon_start_helper_test.go index f90d2d7..0c25acc 100644 --- a/daemon_start_helper_test.go +++ b/daemon_start_helper_test.go @@ -2,8 +2,11 @@ package main import ( "context" + "io" + "log" "path/filepath" "testing" + "time" "github.com/stretchr/testify/require" ) @@ -24,13 +27,22 @@ func daemonStartTestWithBot(t *testing.T, server *ModelFake, bot *TelegramBot) s 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) socket := filepath.Join(dir, socketFileName) @@ -41,8 +53,8 @@ func daemonStartTestWithWhatsApp(t *testing.T, server *ModelFake, bot *TelegramB 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, log.New(io.Discard, "", 0), notify) }) }()