]> git.giacomolli.uk - onechat/blobdiff - daemon_start_helper_test.go
Separate multiline Go statements
[onechat] / daemon_start_helper_test.go
index 0c25acc01dff4b8fa93cddd9c43f7d799d3a4a6e..b09c11be0679f2e2b1457e08622c98fa4ab26b24 100644 (file)
@@ -2,8 +2,7 @@ package main
 
 import (
        "context"
 
 import (
        "context"
-       "io"
-       "log"
+       "os"
        "path/filepath"
        "testing"
        "time"
        "path/filepath"
        "testing"
        "time"
@@ -37,12 +36,12 @@ func daemonStartTestWithWhatsApp(t *testing.T, server *ModelFake, bot *TelegramB
 func daemonStartTestWithSchedules(t *testing.T, server *ModelFake, bot *TelegramBot, whatsapp *WhatsApp, schedules *Schedules, clock func() time.Time) (string, *Memory) {
        t.Helper()
 
 func daemonStartTestWithSchedules(t *testing.T, server *ModelFake, bot *TelegramBot, whatsapp *WhatsApp, schedules *Schedules, clock func() time.Time) (string, *Memory) {
        t.Helper()
 
-       dir := t.TempDir()
+       dir := socketTestDir(t)
        agent, err := openAgent(filepath.Join(dir, daemonAgentDirName))
        require.NoError(t, err)
 
        agent.config.Workdir = t.TempDir()
        agent, err := openAgent(filepath.Join(dir, daemonAgentDirName))
        require.NoError(t, err)
 
        agent.config.Workdir = t.TempDir()
-       memory, err := openMemory(t.Context(), agent.dir, clock, newFakeSummarizer())
+       memory, err := openMemory(t.Context(), agent.dir, clock, newFakeSummarizer(), discardLog())
        require.NoError(t, err)
 
        socket := filepath.Join(dir, socketFileName)
        require.NoError(t, err)
 
        socket := filepath.Join(dir, socketFileName)
@@ -52,9 +51,10 @@ func daemonStartTestWithSchedules(t *testing.T, server *ModelFake, bot *Telegram
        client := newModelClient(server.URL, ModelAPIKey(modelTestKey), agent.CacheKey(), filepath.Join(agent.dir, "usage.jsonl"))
        ctx, cancel := context.WithCancel(t.Context())
        done := make(chan error)
        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, schedules, func(notify func(Event)) (*TurnLoop, error) {
        go func() {
                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)
+                       return newTurnLoop(agent, memory, subagents, whatsapp, schedules, client, clock, discardLog(), notify)
                })
        }()
 
                })
        }()
 
@@ -66,3 +66,19 @@ func daemonStartTestWithSchedules(t *testing.T, server *ModelFake, bot *Telegram
 
        return socket, memory
 }
 
        return socket, memory
 }
+
+// socketTestDir returns a new short directory under /tmp for data that holds a
+// daemon socket. t.TempDir holds the test name and the TMPDIR of the shell, so
+// its paths can pass the 107-byte limit of a Unix socket path.
+func socketTestDir(t *testing.T) string {
+       t.Helper()
+
+       dir, err := os.MkdirTemp("/tmp", "onechat-")
+       require.NoError(t, err)
+
+       t.Cleanup(func() {
+               require.NoError(t, os.RemoveAll(dir))
+       })
+
+       return dir
+}