X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/30fbeb13a74942c6d515cc2a51eab7407a78c325..4c0da6d82252e096269ff840160618318a457d53:/compactor_test.go?ds=sidebyside diff --git a/compactor_test.go b/compactor_test.go index 7813c77..4573fdd 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", ""), 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"]) @@ -72,11 +72,19 @@ func TestCompactorRetriesALongLineWithTheNewestNote(t *testing.T) { writeEvents(w, completedEvent([]any{messageItem(long[call.number])}, 100, 0, 5)) } - line, err := newTestCompactor(t, server).Summarize(t.Context(), leafTask()) + compactor := newTestCompactor(t, server) + line, err := compactor.Summarize(t.Context(), leafTask()) require.NoError(t, err) require.Equal(t, long[2], line) require.Equal(t, 3, server.Calls()) + records := readUsage(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) + } + first := inputParts(t, server.Call(0)) require.Len(t, first, 2) for n, want := range []string{long[0], long[1]} { @@ -85,7 +93,7 @@ func TestCompactorRetriesALongLineWithTheNewestNote(t *testing.T) { 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") + require.Contains(t, parts[2], "\n"+want[:512]+"| <- LIMIT") note, err := json.Marshal(map[string]string{ "type": "input_text", @@ -190,12 +198,17 @@ func newTestCompactor(t *testing.T, server *fakeResponses) *Compactor { client := newClient(server.URL, apiKey(testKey), "agent-key", filepath.Join(t.TempDir(), "usage.jsonl")) - return newCompactor(client, "Ada", ModelConfig{ + return newCompactor(client, adaPrompt, ModelConfig{ Model: "gpt-test", Effort: "high", }) } +// adaPrompt returns the prompt of the agent Ada, without instructions. +func adaPrompt() (string, error) { + return prompt("Ada", ""), nil +} + func leafTask() Task { return Task{ Level: 0,