X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/1e7f78e7b12d3881a6c345d191dfef6e42d9b01f..36229ef68a30c5a117599037d79fa1fc708fbfef:/tools_test.go?ds=sidebyside diff --git a/tools_test.go b/tools_test.go index 8960b8f..487a5fc 100644 --- a/tools_test.go +++ b/tools_test.go @@ -93,6 +93,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) } @@ -107,13 +108,13 @@ func TestFileTools(t *testing.T) { require.Equal(t, "error: old occurs 2 times in "+path+", not once", box.run(t.Context(), "edit", `{"path":"notes/a.txt","old":"two","new":"2"}`)) require.Equal(t, "edited "+path, box.run(t.Context(), "edit", `{"path":"notes/a.txt","old":"one","new":"1"}`)) require.Equal(t, "1 two two\n", box.run(t.Context(), "read", `{"path":"notes/a.txt"}`)) - require.Contains(t, box.run(t.Context(), "read", `{"path":"missing.txt"}`), "error: open "+filepath.Join(dir, "missing.txt")) + require.Contains(t, box.run(t.Context(), "read", `{"path":"missing.txt"}`), "error: open tool file: open "+filepath.Join(dir, "missing.txt")) require.Equal(t, `error: arguments: json: unknown field "file"`, box.run(t.Context(), "read", `{"file":"a.txt"}`)) require.Equal(t, `error: unknown tool "grep"`, box.run(t.Context(), "grep", `{}`)) } func TestZoomAndDateReadTheChat(t *testing.T) { - memory, err := openMemory(t.Context(), t.TempDir(), newTestClock().Now, newFakeSummarizer()) + memory, err := openMemory(t.Context(), t.TempDir(), newTestClock().Now, newFakeSummarizer(), discardLog()) require.NoError(t, err) defer func() { @@ -126,9 +127,10 @@ func TestZoomAndDateReadTheChat(t *testing.T) { } box := &Toolbox{ - log: memory, - chat: memory, - workdir: t.TempDir(), + log: memory, + chat: memory, + subagents: newTestSubagents(t), + workdir: t.TempDir(), } testCases := []struct { @@ -169,6 +171,23 @@ func TestZoomAndDateReadTheChat(t *testing.T) { require.Equal(t, "error: message 4 does not exist", box.run(t.Context(), "date", `{"id":4}`)) } +func TestZoomWithANameGivesTheWholeChatOfTheAgent(t *testing.T) { + box := newTestToolbox(t, &ToolRecordingLog{}, t.TempDir()) + subagent, err := box.subagents.Create(t.Context()) + require.NoError(t, err) + + for _, message := range [][2]string{{"note", "subagent"}, {"user", "Count the files."}} { + _, err = subagent.Append(message[0], message[1]) + require.NoError(t, err) + } + + 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: line 0+1 goes past the last message, -1", box.run(t.Context(), "zoom", `{"id":0,"n":1,"name":null}`)) +} + func TestClipKeepsTheHeadAndTheTail(t *testing.T) { short := strings.Repeat("a", toolClipCharacters) require.Equal(t, short, toolClip(short)) @@ -193,7 +212,7 @@ func TestHeadTailKeepsTheEndsOfALongOutput(t *testing.T) { require.True(t, strings.HasPrefix(text, "0000xxx")) require.True(t, strings.HasSuffix(text, "0999"+strings.Repeat("x", 995)+"\n")) require.Contains(t, text, fmt.Sprintf("\n[... %d bytes cut ...]\n", 1000*1000-toolClipCharacters)) - require.Equal(t, toolClipCharacters+len(fmt.Sprintf("\n[... %d bytes cut ...]\n", 1000*1000-toolClipCharacters)), len(text)) + require.Len(t, text, toolClipCharacters+len(fmt.Sprintf("\n[... %d bytes cut ...]\n", 1000*1000-toolClipCharacters))) } // ToolRecordingLog is a chat log that records each append and flush. The flush @@ -240,7 +259,7 @@ func (r *ToolRecordingLog) Events() []string { func newTestToolbox(t *testing.T, log ToolLog, dir string) *Toolbox { t.Helper() - memory, err := openMemory(t.Context(), t.TempDir(), newTestClock().Now, newFakeSummarizer()) + memory, err := openMemory(t.Context(), t.TempDir(), newTestClock().Now, newFakeSummarizer(), discardLog()) require.NoError(t, err) t.Cleanup(func() { @@ -248,8 +267,9 @@ func newTestToolbox(t *testing.T, log ToolLog, dir string) *Toolbox { }) return &Toolbox{ - log: log, - chat: memory, - workdir: dir, + log: log, + chat: memory, + subagents: newTestSubagents(t), + workdir: dir, } }