]> git.giacomolli.uk - onechat/blob - turn_loop_helper_test.go
Name timeouts for the operations they limit
[onechat] / turn_loop_helper_test.go
1 package main
2
3 import (
4 "path/filepath"
5 "testing"
6 "time"
7
8 "github.com/stretchr/testify/require"
9 )
10
11 // newTestIdleTurnLoop opens a loop with no model calls or turn goroutine.
12 // Callers can test queued messages and events with synctest fake time.
13 func newTestIdleTurnLoop(t *testing.T, whatsapp *WhatsApp) (*TurnLoop, *TurnEventRecorder) {
14 t.Helper()
15
16 agent, err := openAgent(t.TempDir())
17 require.NoError(t, err)
18
19 memory, err := openMemory(t.Context(), agent.dir, time.Now, newFakeSummarizer(), discardLog())
20 require.NoError(t, err)
21 t.Cleanup(func() {
22 require.NoError(t, memory.Close())
23 })
24
25 events := &TurnEventRecorder{}
26 client := newModelClient("https://example.com", ModelAPIKey(modelTestKey), agent.CacheKey(), filepath.Join(agent.dir, "usage.jsonl"))
27 loop, err := newTurnLoop(agent, memory, newTestSubagents(t), whatsapp, newTestSchedules(t, time.Now), client, time.Now, discardLog(), events.Add)
28 require.NoError(t, err)
29
30 return loop, events
31 }