]> git.giacomolli.uk - onechat/blobdiff - turn_test.go
Say that the agent can change its instructions
[onechat] / turn_test.go
index b0417cfc7469781f3460fd021aeec49b4ad8f6e7..9bb0e995d5b66393d8c5b46fdeb2480e50e8a233 100644 (file)
@@ -4,6 +4,7 @@ import (
        "context"
        "encoding/json"
        "errors"
+       "log"
        "net/http"
        "path/filepath"
        "strings"
@@ -203,6 +204,7 @@ func TestInterruptEndsTheTurn(t *testing.T) {
        require.NoError(t, err)
        test.events.WaitFor(t, "idle", 2)
        require.Equal(t, "reply: answer", test.Log(t)[2])
+       require.Empty(t, test.logs.String())
 }
 
 func TestFailedCallEndsTheTurnWithoutARetry(t *testing.T) {
@@ -219,6 +221,10 @@ func TestFailedCallEndsTheTurnWithoutARetry(t *testing.T) {
        time.Sleep(50 * time.Millisecond)
        require.Equal(t, 1, server.Calls())
        require.Contains(t, test.events.Last("error"), "HTTP 503")
+       require.Equal(t, 1, strings.Count(test.logs.String(), "\n"))
+       require.Contains(t, test.logs.String(), "turn failed: ")
+       require.Contains(t, test.logs.String(), "HTTP 503")
+       require.NotContains(t, test.logs.String(), "hello")
 }
 
 func TestViewMessagesOnlyGrowBetweenTurns(t *testing.T) {
@@ -250,6 +256,7 @@ type TurnTestLoop struct {
        memory    *Memory
        loop      *TurnLoop
        events    *TurnEventRecorder
+       logs      *SyncBuffer
        usagePath string
 }
 
@@ -380,18 +387,20 @@ func newTestTurnLoopWith(t *testing.T, server *ModelFake, summarizer Summarizer)
 
        agent.config.Workdir = t.TempDir()
        clock := newTestClock()
-       memory, err := openMemory(t.Context(), t.TempDir(), clock.Now, summarizer)
+       memory, err := openMemory(t.Context(), t.TempDir(), clock.Now, summarizer, discardLog())
        require.NoError(t, err)
 
        test := &TurnTestLoop{
                agent:     agent,
                memory:    memory,
                events:    &TurnEventRecorder{},
+               logs:      &SyncBuffer{},
                usagePath: filepath.Join(t.TempDir(), "usage.jsonl"),
        }
 
        client := newModelClient(server.URL, ModelAPIKey(modelTestKey), agent.CacheKey(), test.usagePath)
-       test.loop, err = newTurnLoop(agent, memory, newTestSubagents(t), client, clock.Now, test.events.Add)
+       whatsapp, _, _ := whatsappStartTest(t, t.TempDir(), clock)
+       test.loop, err = newTurnLoop(agent, memory, newTestSubagents(t), whatsapp, newTestSchedules(t, clock.Now), client, clock.Now, log.New(test.logs, "", 0), test.events.Add)
        require.NoError(t, err)
        ctx, cancel := context.WithCancel(t.Context())
        done := make(chan error)