Files
archie/internal/gateway/session_test.go
T
sam 0314955587 feat: wire memory, guardrails, and tool registry into daemon agent loop
Memory:
- MemoryManager created in main.go with built-in file-backed provider
- SystemPromptBlock() injected into every agent stage request via ExtraRules
- memoryPrompt() helper on Daemon, threaded through TaskContext.SystemPrompt

Guardrails:
- GuardrailEngine created from DefaultGuardrailConfig in main.go
- RecordSuccess/RecordFailure called after every agent stage run
- Threaded through TaskContext.Guardrails for per-task guardrail enforcement

Tool registry:
- NewRegistry() created at startup, MCP servers started from config
- Passed to Daemon.ToolRegistry for dynamic tool discovery

Daemon changes:
- Memory, Guardrails, ToolRegistry fields added (nil-safe, backward compat)
- TaskContext gains SystemPrompt + Guardrails fields
- Agent stage injects memory context into ExtraRules
- Agent stage records guardrail state after each run

Telegram LLM routing deferred (TODO comment) — gateway commands work.
All 38 packages pass with -race.
2026-07-26 10:25:07 +10:00

117 lines
3.2 KiB
Go

package gateway
import (
"testing"
"time"
)
func TestSessionSource_Fields(t *testing.T) {
ss := SessionSource{
Platform: "telegram",
BotUser: "archie",
ChannelID: "chat-42",
}
if ss.Platform != "telegram" {
t.Errorf("expected Platform telegram, got %s", ss.Platform)
}
if ss.BotUser != "archie" {
t.Errorf("expected BotUser archie, got %s", ss.BotUser)
}
if ss.ChannelID != "chat-42" {
t.Errorf("expected ChannelID chat-42, got %s", ss.ChannelID)
}
}
func TestSessionSource_DistinctBots(t *testing.T) {
// Same platform and channel, different bots → distinct sessions.
a := SessionSource{Platform: "discord", BotUser: "archie", ChannelID: "general"}
b := SessionSource{Platform: "discord", BotUser: "winter", ChannelID: "general"}
if a.Platform != b.Platform {
t.Error("platforms should match")
}
if a.BotUser == b.BotUser {
t.Error("bot users should differ")
}
}
func TestSessionContext_Fields(t *testing.T) {
now := time.Now()
sc := SessionContext{
SessionID: "sess-abc",
Source: SessionSource{
Platform: "web",
BotUser: "archie",
ChannelID: "ui-1",
},
CreatedAt: now,
LastActiveAt: now,
}
if sc.SessionID != "sess-abc" {
t.Errorf("expected SessionID sess-abc, got %s", sc.SessionID)
}
if sc.Source.Platform != "web" {
t.Errorf("expected Source.Platform web, got %s", sc.Source.Platform)
}
if sc.CreatedAt.IsZero() {
t.Error("expected non-zero CreatedAt")
}
if sc.LastActiveAt.IsZero() {
t.Error("expected non-zero LastActiveAt")
}
}
func TestSessionContext_ZeroValue(t *testing.T) {
var sc SessionContext
if sc.SessionID != "" {
t.Error("expected empty SessionID on zero value")
}
if !sc.CreatedAt.IsZero() {
t.Error("expected zero CreatedAt on zero value")
}
if !sc.LastActiveAt.IsZero() {
t.Error("expected zero LastActiveAt on zero value")
}
if sc.Source.Platform != "" {
t.Error("expected empty Source.Platform on zero value")
}
if sc.Source.BotUser != "" {
t.Error("expected empty Source.BotUser on zero value")
}
if sc.Source.ChannelID != "" {
t.Error("expected empty Source.ChannelID on zero value")
}
if sc.Source.ThreadID != "" {
t.Error("expected empty Source.ThreadID on zero value")
}
}
func TestSessionSource_DistinctThreads(t *testing.T) {
// Same platform, bot, and channel, different threads → distinct sessions.
a := SessionSource{Platform: "telegram", BotUser: "archie", ChannelID: "-100123", ThreadID: "5"}
b := SessionSource{Platform: "telegram", BotUser: "archie", ChannelID: "-100123", ThreadID: "8"}
if a.Platform != b.Platform {
t.Error("platforms should match")
}
if a.ChannelID != b.ChannelID {
t.Error("channel IDs should match")
}
if a.ThreadID == b.ThreadID {
t.Error("thread IDs should differ")
}
// ThreadID empty for flat chats (General topic).
c := SessionSource{Platform: "telegram", BotUser: "archie", ChannelID: "-100123"}
if c.ThreadID != "" {
t.Errorf("expected empty ThreadID for flat chat, got %q", c.ThreadID)
}
// A thread session and a flat-chat session on the same channel
// must be distinguishable.
d := SessionSource{Platform: "telegram", BotUser: "archie", ChannelID: "-100123", ThreadID: "5"}
if d.ThreadID != "5" {
t.Errorf("expected ThreadID 5, got %q", d.ThreadID)
}
}