Files
archie/internal/gateway/chat_local_test.go
T
sam 7c8f625f0e feat(gateway): flip channel boundary onto messaging.Message
Replaced gateway.Message as the currency at the channel-facing boundary
with the canonical internal/domain/messaging.Message. Channel adapters
now build the record directly (RoleUser, ConversationID, Sender) and the
Router hands it back unchanged, so nothing converts between two shapes in
process. gateway.Message is deleted; the dashboard route that had no home
in the record lives in a new Inbound envelope (Message + transport-only
Page), which reaches the system prompt and is never persisted.

Role is now set at construction instead of derived at the store boundary,
and the assistant reply is a direct messaging.Message (RoleAssistant,
Sender=botUser). The gRPC proto is unchanged: pb.Message still carries no
role, and both sides keep deriving it from the owning session's bot
identity via gateway.RoleForSender (ToStoredMessage/FromStoredMessage are
deleted).

Adds tests that the old shape could not express: Page reaches the system
prompt but not the persisted record, and a channel-built Inbound round-trips
with the Role the channel set.

Refs: archie-core-9g5e
2026-09-09 01:05:36 +10:00

39 lines
1.1 KiB
Go

package gateway
import (
"context"
"testing"
)
func TestLocalChatSnapshotAndStream(t *testing.T) {
ctx := t.Context()
sessions := NewSessionStoreMemory()
t.Cleanup(func() { _ = sessions.Close() })
router := NewRouter(nil, nil, "web")
router.InitSessions(sessions)
chat := &LocalChatAdapter{Router: router, Sessions: sessions}
snapshot, err := chat.Snapshot(ctx)
if err != nil || snapshot.CancellationAvailable || snapshot.PersonasAvailable {
t.Fatalf("snapshot = %+v, %v", snapshot, err)
}
if _, found, err := chat.GetSession(ctx, "absent"); err != nil || found {
t.Fatalf("missing session = %v, %v", found, err)
}
events, err := chat.Stream(ctx, inboundFrom("browser", "web", "/help"))
if err != nil {
t.Fatal(err)
}
var got []ChatEvent
for event := range events {
got = append(got, event)
}
if len(got) < 2 || got[0].Kind != "started" || got[len(got)-1].Kind != "done" || got[len(got)-1].Text == "" {
t.Fatalf("events = %+v", got)
}
cancelCtx, cancel := context.WithCancel(ctx)
cancel()
if _, err := chat.Stream(cancelCtx, inbound("", "")); err == nil {
t.Fatal("cancelled context accepted")
}
}