]> git.giacomolli.uk - onechat/blobdiff - tools_test.go
Sync agent queue replacements before success
[onechat] / tools_test.go
index ed584387a10e5517f3e61009dcc20313bb800c6f..c03e7fc2277164f8cd00610e25863b152515f2dc 100644 (file)
@@ -29,6 +29,7 @@ func TestToolRunsAfterItsCallIsDurable(t *testing.T) {
                "flush, marker absent",
                "echo: done\n",
        }, log.Events())
+
        require.FileExists(t, filepath.Join(dir, "ran"))
 }
 
@@ -58,22 +59,22 @@ func TestShellRunsInTheWorkingDirectory(t *testing.T) {
                output  string
        }{
                {
-                       name:    "working directory",
+                       name:    "runs in the configured working directory",
                        command: "pwd",
                        output:  dir + "\n",
                },
                {
-                       name:    "error output and exit status",
+                       name:    "returns both streams and the failed exit status",
                        command: "echo out; echo err >&2; exit 3",
                        output:  "out\nerr\n\n[exit status 3]",
                },
                {
-                       name:    "no output",
+                       name:    "marks an empty successful output",
                        command: "true",
                        output:  "(no output)",
                },
                {
-                       name:    "no input",
+                       name:    "closes standard input without user input",
                        command: "cat",
                        output:  "(no output)",
                },
@@ -93,6 +94,7 @@ func TestShellInterruptKillsTheCommandAndItsChildren(t *testing.T) {
 
        start := time.Now()
        output := box.shell(ctx, "echo started; sleep 30 & sleep 30")
+
        require.Less(t, time.Since(start), 10*time.Second)
        require.Equal(t, "started\n\n[interrupted]", output)
 }
@@ -138,7 +140,7 @@ func TestZoomAndDateReadTheChat(t *testing.T) {
                output    string
        }{
                {
-                       name:      "one message whole",
+                       name:      "returns one message without shortening it",
                        arguments: `{"id":2,"n":1}`,
                        output:    "user: two",
                },
@@ -148,12 +150,12 @@ func TestZoomAndDateReadTheChat(t *testing.T) {
                        output:    "0+2|user: zero user: one\n2+2|user: two user: three",
                },
                {
-                       name:      "an id that is not a multiple of n",
+                       name:      "rejects an unaligned line ID",
                        arguments: `{"id":1,"n":2}`,
                        output:    "error: line 1+2 does not exist: n must be a power of 2 and id a multiple of n",
                },
                {
-                       name:      "a line past the last message",
+                       name:      "rejects a line beyond the chat",
                        arguments: `{"id":4,"n":4}`,
                        output:    "error: line 4+4 goes past the last message, 3",
                },
@@ -183,7 +185,7 @@ func TestZoomWithANameGivesTheWholeChatOfTheAgent(t *testing.T) {
        output := box.run(t.Context(), "zoom", `{"id":0,"n":1,"name":"`+subagent.name+`"}`)
        require.Equal(t, "0|note: subagent\n\n1|user: Count the files.", output)
 
-       require.Equal(t, "error: no agent BlueFox", box.run(t.Context(), "zoom", `{"id":0,"n":1,"name":"BlueFox"}`))
+       require.Equal(t, "error: open worker log: no agent BlueFox", box.run(t.Context(), "zoom", `{"id":0,"n":1,"name":"BlueFox"}`))
        require.Equal(t, "error: line 0+1 goes past the last message, -1", box.run(t.Context(), "zoom", `{"id":0,"n":1,"name":null}`))
 }
 
@@ -222,6 +224,33 @@ type ToolRecordingLog struct {
        events []string
 }
 
+// newTestToolbox returns a toolbox with log, an empty chat, and the working
+// directory dir.
+func newTestToolbox(t *testing.T, log ToolLog, dir string) *Toolbox {
+       t.Helper()
+
+       memory, err := openMemory(t.Context(), t.TempDir(), newTestClock().Now, newFakeSummarizer(), discardLog())
+       require.NoError(t, err)
+
+       t.Cleanup(func() {
+               require.NoError(t, memory.Close())
+       })
+
+       return &Toolbox{
+               log:       log,
+               chat:      memory,
+               subagents: newTestSubagents(t),
+               workdir:   dir,
+       }
+}
+
+func (r *ToolRecordingLog) Events() []string {
+       r.mutex.Lock()
+       defer r.mutex.Unlock()
+
+       return append([]string(nil), r.events...)
+}
+
 func (r *ToolRecordingLog) Append(kind, text string) (Message, error) {
        r.mutex.Lock()
        defer r.mutex.Unlock()
@@ -245,30 +274,3 @@ func (r *ToolRecordingLog) Flush(ctx context.Context) error {
 
        return ctx.Err()
 }
-
-func (r *ToolRecordingLog) Events() []string {
-       r.mutex.Lock()
-       defer r.mutex.Unlock()
-
-       return append([]string(nil), r.events...)
-}
-
-// newTestToolbox returns a toolbox with log, an empty chat, and the working
-// directory dir.
-func newTestToolbox(t *testing.T, log ToolLog, dir string) *Toolbox {
-       t.Helper()
-
-       memory, err := openMemory(t.Context(), t.TempDir(), newTestClock().Now, newFakeSummarizer(), discardLog())
-       require.NoError(t, err)
-
-       t.Cleanup(func() {
-               require.NoError(t, memory.Close())
-       })
-
-       return &Toolbox{
-               log:       log,
-               chat:      memory,
-               subagents: newTestSubagents(t),
-               workdir:   dir,
-       }
-}