X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/0a98ccb67c3df55c0fe6d76b45afcbaa58c2eda1..87c59e9c7d6743cdd04c0d5e89d3baca173aad42:/compactor_test.go?ds=inline diff --git a/compactor_test.go b/compactor_test.go index 0d591ee..8c83594 100644 --- a/compactor_test.go +++ b/compactor_test.go @@ -28,7 +28,7 @@ func TestCompactorSendsThePromptToolsAndTask(t *testing.T) { require.Equal(t, 1, server.Calls()) body := server.Call(0).body - require.Equal(t, prompt("Ada", ""), body["instructions"]) + require.Equal(t, prompt("Ada", "/AGENT/instructions.md", ""), body["instructions"]) require.Equal(t, "gpt-test", body["model"]) require.Equal(t, map[string]any{"effort": "high"}, body["reasoning"]) require.Equal(t, "agent-key", body["prompt_cache_key"]) @@ -167,6 +167,7 @@ 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) @@ -174,6 +175,7 @@ func TestCompactorRetriesALongLineWithTheNewestNote(t *testing.T) { first := compactorInputTexts(t, server.Call(0)) require.Len(t, first, 2) + for n, want := range []string{long[0], long[1]} { call := server.Call(n + 1) texts := compactorInputTexts(t, call) @@ -209,15 +211,16 @@ func TestCompactorFailsWithoutALine(t *testing.T) { }{ { name: "failed call", - reply: func(w http.ResponseWriter, call ModelFakeCall) { + reply: func(w http.ResponseWriter, _ ModelFakeCall) { w.WriteHeader(http.StatusInternalServerError) + _, _ = io.WriteString(w, "down") }, want: "HTTP 500", }, { name: "tool call and no text", - reply: func(w http.ResponseWriter, call ModelFakeCall) { + reply: func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{map[string]any{"type": "function_call", "name": "zoom", "arguments": "{}"}}, 100, 0, 5)) }, want: "no line", @@ -249,13 +252,14 @@ func TestCompactorBuildsNodesInTheCore(t *testing.T) { server.reply = func(w http.ResponseWriter, call ModelFakeCall) { if call.number == 0 { w.WriteHeader(http.StatusServiceUnavailable) + return } modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("summary of the long output")}, 100, 0, 5)) } - memory, err := openMemory(t.Context(), t.TempDir(), newTestClock().Now, newTestCompactor(t, server)) + memory, err := openMemory(t.Context(), t.TempDir(), newTestClock().Now, newTestCompactor(t, server), discardLog()) require.NoError(t, err) defer func() { @@ -310,6 +314,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 } @@ -327,5 +332,5 @@ func compactorLeafTask() Task { // compactorAdaPrompt returns the prompt of the agent Ada, without instructions. func compactorAdaPrompt() (string, error) { - return prompt("Ada", ""), nil + return prompt("Ada", "/AGENT/instructions.md", ""), nil }