]> git.giacomolli.uk - onechat/blobdiff - daemon_start_helper_test.go
Reflow comments over the reflow width
[onechat] / daemon_start_helper_test.go
index baa527b9d7637851d0db2e0ebc67698a678bd6d1..c43ff9cb58989ab31141e837388205a835f959a2 100644 (file)
@@ -4,6 +4,7 @@ import (
        "context"
        "path/filepath"
        "testing"
+       "time"
 
        "github.com/stretchr/testify/require"
 )
@@ -24,13 +25,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()
 
-       dir := t.TempDir()
+       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 := socketTestDir(t)
        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(), discardLog())
        require.NoError(t, err)
 
        socket := filepath.Join(dir, socketFileName)
@@ -40,9 +50,10 @@ func daemonStartTestWithWhatsApp(t *testing.T, server *ModelFake, bot *TelegramB
        client := newModelClient(server.URL, ModelAPIKey(modelTestKey), agent.CacheKey(), filepath.Join(agent.dir, "usage.jsonl"))
        ctx, cancel := context.WithCancel(t.Context())
        done := make(chan error)
+       subagents := newTestSubagents(t)
        go func() {
-               done <- daemonServe(ctx, listener, bot, whatsapp, func(notify func(Event)) (*TurnLoop, error) {
-                       return newTurnLoop(agent, memory, newTestSubagents(t), whatsapp, client, clock.Now, notify)
+               done <- daemonServe(ctx, listener, bot, whatsapp, schedules, func(notify func(Event)) (*TurnLoop, error) {
+                       return newTurnLoop(agent, memory, subagents, whatsapp, schedules, client, clock, discardLog(), notify)
                })
        }()