Files
archie/internal/domain/agentrun/history_test.go
T
sam dc2c3b983f
deploy / plan (push) Successful in 7s
deploy / gate (push) Successful in 8m12s
deploy / agent-image (push) Successful in 28s
deploy / dist-zip (push) Skipped
deploy / archied-image (push) Successful in 2m11s
feat(workflow): a budget continuation resumes at the stopped step with its conversation (#1832)
2026-11-09 12:44:01 +11:00

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")
}
}