47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package agentrun
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBoundHistory(t *testing.T) {
|
|
entries := []TranscriptEntry{
|
|
{Kind: TranscriptSystem, Text: "system"},
|
|
{Kind: TranscriptUser, Text: "mission"},
|
|
{Kind: TranscriptTool, Tool: "read", Output: strings.Repeat("a", 1000)},
|
|
{Kind: TranscriptTool, Tool: "read", Output: strings.Repeat("b", 1000)},
|
|
{Kind: TranscriptModel, Text: "newest"},
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
max int
|
|
wantTools []string
|
|
wantLen int
|
|
}{
|
|
{name: "fits", max: 1 << 20, wantTools: []string{strings.Repeat("a", 1000), strings.Repeat("b", 1000)}, wantLen: 3},
|
|
{name: "oldest output dropped first", max: 1100, wantTools: []string{droppedOutput, strings.Repeat("b", 1000)}, wantLen: 3},
|
|
{name: "then oldest entries", max: 10, wantLen: 1},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := BoundHistory(entries, tt.max)
|
|
if len(got) != tt.wantLen || got[len(got)-1].Text != "newest" {
|
|
t.Fatalf("got %d entries %+v, want %d ending in the newest", len(got), got, tt.wantLen)
|
|
}
|
|
var tools []string
|
|
for _, e := range got {
|
|
if e.Kind == TranscriptTool {
|
|
tools = append(tools, e.Output)
|
|
}
|
|
}
|
|
if strings.Join(tools, "|") != strings.Join(tt.wantTools, "|") {
|
|
t.Errorf("tool outputs = %v, want %v", tools, tt.wantTools)
|
|
}
|
|
})
|
|
}
|
|
if entries[2].Output != strings.Repeat("a", 1000) {
|
|
t.Error("input was modified")
|
|
}
|
|
}
|