Files
Agent-System/internal/server/session_cap_test.go
T
weichenandCursor d4041a4f0c fix(coordinator): use the caller name and reject non-decimal user ids
Ambiguous consult only redirects on low confidence, and the testing template greets the signed-in user instead of a hardcoded name. Session tokens no longer parse as user id 0. Live chat sessions now evict the oldest entry at a hard cap.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-19 09:19:36 +00:00

34 lines
815 B
Go

package server
import (
"fmt"
"testing"
"time"
"chat-agent-system/internal/chat"
)
func TestEnforceSessionCapEvictsOldest(t *testing.T) {
s := &Server{sessions: map[string]*chat.Session{}}
oldest := chat.NewSession("oldest", nil, nil, nil)
oldest.TouchLastAccessed()
s.sessions[oldest.ID] = oldest
time.Sleep(5 * time.Millisecond)
for i := 0; i < maxLiveSessions-1; i++ {
id := fmt.Sprintf("s%d", i)
sess := chat.NewSession(id, nil, nil, nil)
sess.TouchLastAccessed()
s.sessions[id] = sess
}
if len(s.sessions) != maxLiveSessions {
t.Fatalf("setup len=%d", len(s.sessions))
}
s.enforceSessionCapLocked()
if _, ok := s.sessions["oldest"]; ok {
t.Fatal("oldest session must be evicted at the cap")
}
if len(s.sessions) != maxLiveSessions-1 {
t.Fatalf("len=%d", len(s.sessions))
}
}