Files
archie/internal/infrastructure/sessioncurator/adapter_test.go
T
sam c4871569ce feat(curator): session-memory curator reference implementation
Closes archie-core-1786637499114 (persistent session-memory curator),
the last open item in the curator engine epic.

docs/prds/session-memory-curator.md records the decisions this needed
before coding, most notably: Observation.Identity is the session ID,
not a user or cross-session identity. migration-decisions.md#5's
memory-scope mapping (global/agent-wide/user-wide/agent-user
relationship) is still explicitly open, and this issue has no business
deciding it unilaterally -- session-as-identity is the narrowest
unambiguous scope available today and is forward-compatible with a
later, properly-decided identity resolution.

curator gains ConversationSource (RecentSessions/Messages), gated in
Registry.validateDeclared/filter exactly like Skills/MemoryEngines, plus
Manifest.Conversations. internal/infrastructure/sessioncurator/adapter.go
adapts gateway.SessionStore's full CRUD/branch/search surface down to
those two read-only methods -- curator must not import gateway.Message,
so role derivation (message.From == botUser -> assistant) is copied from
gateway.compressTurnHistory's existing logic, not shared.

sessioncurator.go: Check is a cheap RecentSessions bool. Pass takes each
session's last 40 messages, asks the model for a JSON array of durable
facts (capped at 5/session), and writes each through
Registrar.MemoryEngines.Get(name) -- resolved by name at call time, the
same trust model every other curator capability already uses. A
response that fails to parse degrades to "nothing extracted" for that
session (not a Pass error); a real model-call failure propagates as one
(these were originally conflated into the same swallowed-error path --
caught by TestPassPropagatesALLMFailure, fixed by splitting the model
call from the parse step). PassInput.Since zero resolves to a 24h
lookback, not the beginning of time, so a cold-start first pass can't
read a session's entire history.

Manifest.OnInput = true wakes it via the existing WakeOnPrimaryInput
wiring (events.KindTurnCompleted), which already excludes every
curator-derived event kind from the forwarded set -- the trigger-
accounting invariant (archie-core-1786637489768) needed no new code to
hold here.

Wired into bootstrap.go:setupCurators via a new curatorLLMRunner adapter
(main.go) over the shared ai-sdk runtime, and sessioncurator.NewAdapter
over b.chatSessionStore/b.cfg.BotUser. Model resolves from
b.chatModels.ActiveModel() -- not b.defaultChatIdentity, which names a
task-routing identity, not a model reference (the same source
telegram_setup.go's sendChatTurn already uses for a real chat turn).

task check is green (full Go suite + dashboard tests).
2026-09-02 03:09:04 +10:00

73 lines
2.1 KiB
Go

package sessioncurator
import (
"context"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/gateway"
)
func newTestStore(t *testing.T) gateway.SessionStore {
t.Helper()
s := gateway.NewSessionStoreMemory()
t.Cleanup(func() { _ = s.Close() })
return s
}
func TestAdapterRecentSessionsFiltersByActivity(t *testing.T) {
t.Parallel()
store := newTestStore(t)
ctx := context.Background()
old := gateway.SessionContext{SessionID: "old", LastActiveAt: time.Unix(100, 0)}
recent := gateway.SessionContext{SessionID: "recent", LastActiveAt: time.Unix(2000, 0)}
if err := store.Save(ctx, old); err != nil {
t.Fatalf("Save(old) = %v", err)
}
if err := store.Save(ctx, recent); err != nil {
t.Fatalf("Save(recent) = %v", err)
}
a := NewAdapter(store, "archie")
got, err := a.RecentSessions(ctx, time.Unix(1000, 0))
if err != nil {
t.Fatalf("RecentSessions() = %v, want nil", err)
}
if len(got) != 1 || got[0].ID != "recent" {
t.Fatalf("RecentSessions() = %v, want only 'recent'", got)
}
}
func TestAdapterMessagesDerivesRoleFromBotUser(t *testing.T) {
t.Parallel()
store := newTestStore(t)
ctx := context.Background()
sess := gateway.SessionContext{SessionID: "s1", LastActiveAt: time.Unix(1000, 0)}
if err := store.Save(ctx, sess); err != nil {
t.Fatalf("Save() = %v", err)
}
if err := store.SaveMessage(ctx, "s1", gateway.Message{From: "user123", Text: "hello", At: time.Unix(1, 0)}); err != nil {
t.Fatalf("SaveMessage(user) = %v", err)
}
if err := store.SaveMessage(ctx, "s1", gateway.Message{From: "archie", Text: "hi there", At: time.Unix(2, 0)}); err != nil {
t.Fatalf("SaveMessage(bot) = %v", err)
}
a := NewAdapter(store, "archie")
got, err := a.Messages(ctx, "s1", 10)
if err != nil {
t.Fatalf("Messages() = %v, want nil", err)
}
if len(got) != 2 {
t.Fatalf("Messages() = %v, want 2", got)
}
if got[0].Role != "user" || got[0].Content != "hello" {
t.Errorf("Messages()[0] = %+v, want user/hello", got[0])
}
if got[1].Role != "assistant" || got[1].Content != "hi there" {
t.Errorf("Messages()[1] = %+v, want assistant/hi there", got[1])
}
}