X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/56129a5fcbcbe51a7ac7d6b009d4551ed9f71109..4b9b22619008f0829b7f5a8685e7b1d2a9aeb6bb:/compactor_test.go?ds=sidebyside
diff --git a/compactor_test.go b/compactor_test.go
index cc99f33..20862c7 100644
--- a/compactor_test.go
+++ b/compactor_test.go
@@ -44,34 +44,34 @@ func TestCompactorSendsThePromptToolsAndTask(t *testing.T) {
require.Equal(t, []string{
"\n",
"0+4|a\n4+1|b\n5+1|c\n6+1|d\n",
- "7+1|e\n\n",
- "Compaction: compress message 7 into one line of at most 512 bytes\n" +
+ "7+1|e\n\n" +
+ "Compaction: compress message 7 into one line of at most 512 bytes\n" +
"(about 70 words), the length of this ruler:\n" +
strings.Repeat("-", 512) + "\n" +
"\nuser: " + strings.Repeat("x", 600) + "\n",
}, parts)
}
-func TestViewPartsSendWholeBlocksOfLines(t *testing.T) {
+func TestCompactionPartsEndWithTheRestAndTheTask(t *testing.T) {
testCases := []struct {
name string
context string
want []string
}{
{
- name: "empty view has the tags only",
+ name: "empty view has the opening tag and the last part",
context: "\n",
- want: []string{"\n", "\n"},
+ want: []string{"\n", "\nTASK"},
},
{
- name: "lines short of a block go with the closing tag",
+ name: "lines short of a block go into the last part",
context: "\n0+1|a\n1+1|b\n2+1|c\n",
- want: []string{"\n", "0+1|a\n1+1|b\n2+1|c\n\n"},
+ want: []string{"\n", "0+1|a\n1+1|b\n2+1|c\n\nTASK"},
},
{
name: "one whole block",
context: "\n0+1|a\n1+1|b\n2+1|c\n3+1|d\n",
- want: []string{"\n", "0+1|a\n1+1|b\n2+1|c\n3+1|d\n", "\n"},
+ want: []string{"\n", "0+1|a\n1+1|b\n2+1|c\n3+1|d\n", "\nTASK"},
},
{
name: "two whole blocks and a rest",
@@ -80,23 +80,24 @@ func TestViewPartsSendWholeBlocksOfLines(t *testing.T) {
"\n",
"0+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\n",
+ "9+1|i\n\nTASK",
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
- parts := viewParts(tc.context)
+ parts := compactionParts(tc.context, "TASK")
require.Equal(t, tc.want, parts)
- require.Equal(t, tc.context+"\n", strings.Join(parts, ""))
+ require.Equal(t, tc.context+"\nTASK", strings.Join(parts, ""))
})
}
}
-func TestViewPartsKeepTheBlocksOfAShorterView(t *testing.T) {
- shorter := viewParts("\n0+1|a\n1+1|b\n2+1|c\n3+1|d\n4+1|e\n")
- longer := viewParts("\n0+1|a\n1+1|b\n2+1|c\n3+1|d\n4+1|e\n5+1|f\n6+1|g\n7+1|h\n")
+func TestCompactionPartsOfALongerViewBeginWithTheBlocksOfAShorterOne(t *testing.T) {
+ shorter := compactionParts("\n0+1|a\n1+1|b\n2+1|c\n3+1|d\n4+1|e\n", "task 5")
+ longer := compactionParts("\n0+1|a\n1+1|b\n2+1|c\n3+1|d\n4+1|e\n5+1|f\n6+1|g\n7+1|h\n", "task 8")
+ require.Len(t, shorter, 3)
require.Equal(t, shorter[:2], longer[:2])
require.NotEqual(t, shorter[2], longer[2])
}
@@ -137,18 +138,18 @@ func TestCompactorRetriesALongLineWithTheNewestNote(t *testing.T) {
}
first := inputParts(t, server.Call(0))
- require.Len(t, first, 3)
+ require.Len(t, first, 2)
for n, want := range []string{long[0], long[1]} {
call := server.Call(n + 1)
parts := inputParts(t, call)
- require.Equal(t, first, parts[:3])
- require.Equal(t, []string{tooLong(want)}, parts[3:])
- require.Contains(t, parts[3], "was "+strconv.Itoa(len(want))+" bytes,")
- require.Contains(t, parts[3], "\n"+want[:512]+"| <- LIMIT")
+ require.Equal(t, first, parts[:2])
+ require.Equal(t, []string{tooLong(want)}, parts[2:])
+ require.Contains(t, parts[2], "was "+strconv.Itoa(len(want))+" bytes,")
+ require.Contains(t, parts[2], "\n"+want[:512]+"| <- LIMIT")
note, err := json.Marshal(map[string]string{
"type": "input_text",
- "text": parts[3],
+ "text": parts[2],
})
require.NoError(t, err)
require.LessOrEqual(t, len(call.raw), len(server.Call(0).raw)+len(",")+len(note))