]> git.giacomolli.uk - onechat/blobdiff - daemon_agent_test.go
Separate multiline Go statements
[onechat] / daemon_agent_test.go
index 7b1407b220e1586daf31d0c6b908a6e8a9fcd19a..5ee342a04018939c4b6d01ed1ea878038abbc3f2 100644 (file)
@@ -3,6 +3,7 @@ package main
 import (
        "context"
        "io"
 import (
        "context"
        "io"
+       "net/http"
        "os"
        "path/filepath"
        "strings"
        "os"
        "path/filepath"
        "strings"
@@ -25,9 +26,19 @@ func TestDaemonOpensAndRunsTheRootAndTwoChildren(t *testing.T) {
        t.Cleanup(func() {
                require.NoError(t, agents.Close())
        })
        t.Cleanup(func() {
                require.NoError(t, agents.Close())
        })
+
        require.Len(t, agents, 3)
        require.Equal(t, []string{"Garden", "Library"}, agents.ChildNames())
 
        require.Len(t, agents, 3)
        require.Equal(t, []string{"Garden", "Library"}, agents.ChildNames())
 
+       server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+               text := ""
+               if call.body["prompt_cache_key"] == agents[0].agent.CacheKey() {
+                       text = "The decision is recorded."
+               }
+
+               modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem(text)}, 100, 0, 5))
+       }
+
        for _, agent := range agents {
                at := clock.Now().Add(time.Minute).Format(scheduleAtLayout)
                _, err = agent.schedules.Set("Record the decision for "+agent.agent.config.Name, &at, nil)
        for _, agent := range agents {
                at := clock.Now().Add(time.Minute).Format(scheduleAtLayout)
                _, err = agent.schedules.Set("Record the decision for "+agent.agent.config.Name, &at, nil)
@@ -56,7 +67,13 @@ func TestDaemonOpensAndRunsTheRootAndTwoChildren(t *testing.T) {
 
        require.Eventually(t, func() bool {
                for _, agent := range agents {
 
        require.Eventually(t, func() bool {
                for _, agent := range agents {
-                       if agent.memory.Len() != 2 {
+                       count := 1
+                       if agent == agents[0] {
+                               count = 2
+                       }
+
+                       usage, err := os.ReadFile(filepath.Join(agent.agent.dir, "usage.jsonl"))
+                       if err != nil || !strings.HasSuffix(string(usage), "\n") || agent.memory.Len() != count {
                                return false
                        }
                }
                                return false
                        }
                }
@@ -237,6 +254,7 @@ func TestInvalidChildRelationshipsStopStartup(t *testing.T) {
                        cause: "must have its own name and ID",
                },
        }
                        cause: "must have its own name and ID",
                },
        }
+
        for _, tc := range testCases {
                t.Run(tc.name, func(t *testing.T) {
                        dir := t.TempDir()
        for _, tc := range testCases {
                t.Run(tc.name, func(t *testing.T) {
                        dir := t.TempDir()