]> git.giacomolli.uk - onechat/blobdiff - daemon_agent_test.go
Manage source routes with root tools
[onechat] / daemon_agent_test.go
index 7b1407b220e1586daf31d0c6b908a6e8a9fcd19a..3fceb34ecea885f349b7bbf2e8690faafea95a22 100644 (file)
@@ -3,6 +3,7 @@ package main
 import (
        "context"
        "io"
 import (
        "context"
        "io"
+       "net/http"
        "os"
        "path/filepath"
        "strings"
        "os"
        "path/filepath"
        "strings"
@@ -28,6 +29,15 @@ func TestDaemonOpensAndRunsTheRootAndTwoChildren(t *testing.T) {
        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 +66,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
                        }
                }