Files
archie/internal/gateway/web_parity_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

75 lines
3.3 KiB
Go

package gateway
import (
"context"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/releaseupdate"
)
type parityUpdateStub struct{}
func (parityUpdateStub) Check(context.Context, int64) (releaseupdate.Snapshot, error) {
return releaseupdate.Snapshot{Components: []releaseupdate.Component{{ID: "gateway", Label: "THE GATEWAY", Installed: "v1", Available: "v2"}}}, nil
}
func (parityUpdateStub) Defer(context.Context, int64, releaseupdate.Snapshot) error { return nil }
func (parityUpdateStub) Install(context.Context, releaseupdate.Snapshot, releaseupdate.InstallMeta, func(string)) (releaseupdate.Result, error) {
return releaseupdate.Result{}, nil
}
func (parityUpdateStub) CanInstall() bool { return true }
type parityDangerousStub struct{ decisions []string }
func (s *parityDangerousStub) Decide(_ context.Context, id, decision string) (string, error) {
s.decisions = append(s.decisions, id+":"+decision)
return "dangerous decision applied", nil
}
func TestSharedRouterWebParityCommands(t *testing.T) {
t.Parallel()
r := NewRouter(nil, nil, "web")
r.Version = "Archie\nGateway: test\nRuntime: test"
restarted := false
r.Restart = func(context.Context) error { restarted = true; return nil }
r.Updates = parityUpdateStub{}
dangerous := &parityDangerousStub{}
r.Dangerous = dangerous
r.Personas = NewPersonaRegistry(DefaultPersonas())
sessions := NewSessionStoreMemory()
t.Cleanup(func() { _ = sessions.Close() })
r.InitSessions(sessions)
reply, err := r.Route(context.Background(), inbound("browser", "/version"))
if err != nil || reply != r.Version {
t.Fatalf("/version = %q, %v", reply, err)
}
reply, err = r.Route(context.Background(), inbound("browser", "/personality concise"))
if err != nil || !strings.Contains(reply, `"concise"`) {
t.Fatalf("/personality concise = %q, %v", reply, err)
}
reply, err = r.Route(context.Background(), inbound("browser", "/help"))
if err != nil || !strings.Contains(reply, "/personality") || !strings.Contains(reply, "/resume") {
t.Fatalf("/help = %q, %v", reply, err)
}
reply, err = r.Route(context.Background(), inbound("browser", "/restart"))
if err != nil || !restarted || !strings.Contains(reply, "reload requested") {
t.Fatalf("/restart = %q, restarted=%v, err=%v", reply, restarted, err)
}
reply, err = r.Route(context.Background(), inbound("browser", "/update"))
if err != nil || !strings.Contains(reply, "v2 available") {
t.Fatalf("/update = %q, err=%v", reply, err)
}
reply, err = r.Route(context.Background(), inbound("browser", "/approve action-1"))
if err != nil || !strings.Contains(reply, "decision applied") || len(dangerous.decisions) != 1 || dangerous.decisions[0] != "action-1:approve" {
t.Fatalf("typed /approve = %q, decisions=%v, err=%v", reply, dangerous.decisions, err)
}
_, err = r.Route(context.Background(), inbound("browser", "/approve permanent action-2"))
if err != nil || len(dangerous.decisions) != 2 || dangerous.decisions[1] != "action-2:permanent" {
t.Fatalf("permanent /approve decisions=%v, err=%v", dangerous.decisions, err)
}
_, err = r.Route(context.Background(), inbound("browser", "/deny action-3"))
if err != nil || len(dangerous.decisions) != 3 || dangerous.decisions[2] != "action-3:deny" {
t.Fatalf("/deny decisions=%v, err=%v", dangerous.decisions, err)
}
}