Files
archie/internal/gateway/session_test.go
T
sam bc1caf67aa feat: BasePlatformAdapter interface + Session types (16.3, 16.5, 16.9, 16.10, 16.11)
adapter.go — SendResult struct (success, message_id, error, retryable,
retry_after, continuation_message_ids, error_kind), ChatInfo struct
(name, type, chat_id, thread_id), BasePlatformAdapter interface
(Connect, Disconnect, Send, ChatInfo).

session.go — SessionSource (platform, chat_id/name/type, user_id/name,
thread_id, guild_id, scope_id, profile, is_bot, metadata) with Key()
for deterministic session key. SessionContext wrapping source with
connected_platforms, home_channels, session_key/id, timestamps.

session_store.go — SessionStore interface (GetOrCreate, Get, Reset,
List, GetByChannel, Touch, Delete, Close) + nellSessionStore backed
by nell.DocDB with mutex-guarded Save/Delete for race safety.

Verification: 4 findings fixed (gofmt alignment, race on mutex,
!= true anti-pattern, missing zero-value assertions). 58 tests pass
(incl -race), go vet + gofmt + golangci-lint clean.

Closes: archie-core-abg.16.3, 16.5, 16.9, 16.10, 16.11
2026-07-26 01:29:36 +10:00

85 lines
2.1 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")
}
}