X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/087d725b5ab41ad34ffd24938482d45a8b99a080..b2fc2d6a737dd5bab25e57ba822dd07258de93e6:/compactor_test.go
diff --git a/compactor_test.go b/compactor_test.go
index f4c51f4..baa7f57 100644
--- a/compactor_test.go
+++ b/compactor_test.go
@@ -50,90 +50,6 @@ func TestCompactorSendsThePromptToolsAndTask(t *testing.T) {
}, texts)
}
-func TestCompactorSendsEachWholeBlockOfTheViewAsAMessage(t *testing.T) {
- testCases := []struct {
- name string
- context string
- want []string
- }{
- {
- name: "empty view goes with the task",
- context: "\n",
- want: []string{"\n\nTASK"},
- },
- {
- name: "lines short of a block go with the task",
- context: "\n0+1|a\n1+1|b\n2+1|c\n",
- want: []string{"\n0+1|a\n1+1|b\n2+1|c\n\nTASK"},
- },
- {
- name: "one whole block and the task",
- context: "\n0+1|a\n1+1|b\n2+1|c\n3+1|d\n",
- want: []string{"\n0+1|a\n1+1|b\n2+1|c\n3+1|d\n", "\nTASK"},
- },
- {
- name: "two whole blocks and the rest with the task",
- context: "\n0+2|a\n2+1|b\n3+1|c\n4+1|d\n5+1|e\n6+1|f\n7+1|g\n8+1|h\n9+1|i\n",
- want: []string{
- "\n0+2|a\n2+1|b\n3+1|c\n4+1|d\n",
- "5+1|e\n6+1|f\n7+1|g\n8+1|h\n",
- "9+1|i\n\nTASK",
- },
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- server := newModelFake(t)
- task := compactorLeafTask()
- task.Context = tc.context
-
- _, err := newTestCompactor(t, server).Summarize(t.Context(), task)
- require.NoError(t, err)
-
- text, err := compactorTask(task)
- require.NoError(t, err)
-
- want := make([]string, len(tc.want))
- for n, message := range tc.want {
- want[n] = strings.Replace(message, "TASK", text, 1)
- }
-
- texts := compactorInputTexts(t, server.Call(0))
- require.Equal(t, want, texts)
- require.Equal(t, tc.context+"\n"+text, strings.Join(texts, ""))
- })
- }
-}
-
-func TestCompactorSendsTheSameBlocksForViewsWithTheSameFirstLines(t *testing.T) {
- shared := "\n0+4|a\n4+1|b\n5+1|c\n6+1|d\n7+1|e\n8+1|f\n9+1|g\n10+1|h\n"
- server := newModelFake(t)
- compactor := newTestCompactor(t, server)
- _, err := compactor.Summarize(t.Context(), Task{
- Level: 0,
- Index: 11,
- Context: shared + "11+1|i\n",
- Input: []string{"user: eleven"},
- })
- require.NoError(t, err)
-
- _, err = compactor.Summarize(t.Context(), Task{
- Level: 1,
- Index: 5,
- Context: shared + "11+1|j\n12+1|k\n",
- Input: []string{"left line", "right line"},
- })
- require.NoError(t, err)
-
- first := compactorInputTexts(t, server.Call(0))
- second := compactorInputTexts(t, server.Call(1))
- require.Len(t, first, 3)
- require.Len(t, second, 3)
- require.Equal(t, first[:2], second[:2])
- require.NotEqual(t, first[2], second[2])
-}
-
func TestCompactorWritesTheMergeTask(t *testing.T) {
text, err := compactorTask(Task{
Level: 2,
@@ -167,22 +83,27 @@ func TestCompactorRetriesALongLineWithTheNewestNote(t *testing.T) {
records := modelReadUsage(t, compactor.client.usage.path)
require.Len(t, records, 3)
+
for n, record := range records {
require.Equal(t, &[2]int{0, 0}, record.Node)
require.Equal(t, len(long[n]), record.TextBytes)
}
+ text, err := compactorTask(task)
+ require.NoError(t, err)
+
first := compactorInputTexts(t, server.Call(0))
- require.Len(t, first, 2)
+ require.Equal(t, []string{task.Context + "\n" + text}, first)
+
for n, want := range []string{long[0], long[1]} {
call := server.Call(n + 1)
texts := compactorInputTexts(t, call)
- require.Equal(t, first, texts[:2])
- require.Equal(t, []string{compactorTooLong(want)}, texts[2:])
- require.Contains(t, texts[2], "was "+strconv.Itoa(len(want))+" bytes,")
- require.Contains(t, texts[2], "\n"+want[:512]+"| <- LIMIT")
+ require.Equal(t, first, texts[:1])
+ require.Equal(t, []string{compactorTooLong(want)}, texts[1:])
+ require.Contains(t, texts[1], "was "+strconv.Itoa(len(want))+" bytes,")
+ require.Contains(t, texts[1], "\n"+want[:512]+"| <- LIMIT")
- note, err := json.Marshal(modelUserMessage(texts[2]))
+ note, err := json.Marshal(modelUserMessage(texts[1]))
require.NoError(t, err)
require.LessOrEqual(t, len(call.raw), len(server.Call(0).raw)+len(",")+len(note))
}
@@ -211,6 +132,7 @@ func TestCompactorFailsWithoutALine(t *testing.T) {
name: "failed call",
reply: func(w http.ResponseWriter, _ ModelFakeCall) {
w.WriteHeader(http.StatusInternalServerError)
+
_, _ = io.WriteString(w, "down")
},
want: "HTTP 500",
@@ -249,6 +171,7 @@ func TestCompactorBuildsNodesInTheCore(t *testing.T) {
server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
if call.number == 0 {
w.WriteHeader(http.StatusServiceUnavailable)
+
return
}
@@ -285,7 +208,7 @@ func newTestCompactor(t *testing.T, server *ModelFake) *Compactor {
return newCompactor(client, compactorAdaPrompt, ModelConfig{
Model: "gpt-test",
Effort: "high",
- })
+ }, promptTools(), &ImageStore{dir: t.TempDir()})
}
// compactorInputTexts returns the text of each user message of call. Each
@@ -310,6 +233,7 @@ func compactorInputTexts(t *testing.T, call ModelFakeCall) []string {
require.Equal(t, "user", message.Role)
require.Len(t, message.Content, 1)
require.Equal(t, "input_text", message.Content[0].Type)
+
texts[n] = message.Content[0].Text
}