Store session history, preferences, and dated records in one database per home. Commit complete turns, checkpoint tool batches, and compact history by prefix. Add memory search and writes, with previews for ambiguous corrections. Review conversations in the background and support SQLite backup and restore.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/providers"
|
|
)
|
|
|
|
func TestTrimHistoryToFitContextWindow_WithProtectedTurnTailKeepsActiveTurn(t *testing.T) {
|
|
current := strings.Repeat("current turn ", 80)
|
|
history := []providers.Message{
|
|
{Role: "user", Content: strings.Repeat("old turn ", 60)},
|
|
{Role: "assistant", Content: strings.Repeat("old reply ", 60)},
|
|
{Role: "user", Content: current},
|
|
}
|
|
|
|
stable, protected := history[:2], history[2:]
|
|
trimmedStable, messages, fit := trimHistoryToFitContextWindow(
|
|
stable,
|
|
func(trimmedHistory []providers.Message) []providers.Message {
|
|
return append(append([]providers.Message(nil), trimmedHistory...), protected...)
|
|
},
|
|
120,
|
|
nil,
|
|
0,
|
|
)
|
|
|
|
if fit {
|
|
t.Fatal("expected protected active turn alone to remain over budget")
|
|
}
|
|
if len(trimmedStable) != 0 {
|
|
t.Fatalf("trimmed stable history len = %d, want 0", len(trimmedStable))
|
|
}
|
|
if len(messages) != 1 {
|
|
t.Fatalf("messages len = %d, want 1 protected active-turn message", len(messages))
|
|
}
|
|
if messages[0].Content != current {
|
|
t.Fatalf("messages[0].Content = %q, want protected current turn", messages[0].Content)
|
|
}
|
|
}
|