package memory import ( "context" "fmt" "strings" "testing" domainmemory "github.com/samcharles93/archie-core/internal/domain/memory" ) // A section at the size cap must keep accepting records by moving its oldest // ones to history, not fail the write and stop recording for good. func TestBuiltinEngineCreateRotatesFullSection(t *testing.T) { engine := NewBuiltinEngine(t.TempDir(), 4096) scope := domainmemory.Scope{Kind: domainmemory.ScopeAgentUser, Agent: "a", User: "u"} ctx := context.Background() var ids []domainmemory.RecordID for i := range 60 { rec, err := engine.Create(ctx, domainmemory.NewRecord{ Scope: scope, Kind: "note", Author: "test", Content: fmt.Sprintf("observation %02d %s", i, strings.Repeat("x", 80)), }) if err != nil { t.Fatalf("create %d: %v", i, err) } ids = append(ids, rec.ID) } if _, err := engine.Get(ctx, scope, ids[len(ids)-1]); err != nil { t.Fatalf("newest record not live: %v", err) } revisions, err := engine.Revisions(ctx, scope, ids[0]) if err != nil || len(revisions) == 0 { t.Fatalf("oldest record not retained in history: %v %v", revisions, err) } }