One Router serves every channel and named itself "web", so Source.Platform -- the FIRST component of the session natural key, and the platform GetByChannel filters on -- was a constant, true of no channel but the dashboard. Two consequences followed: the per-user identity policy was real code that no production call site reached with a real channel name, and a curator pass's write to agent-user memory could not be read back by the turn that wrote it, because that turn resolved no UserID. The channel now travels with the message. Frontends name the channel they carry (pb.Message.platform: telegram, email, webhook, web), and the Gateway stamps the session from it, falling back to its own name when a sender names none -- which is what every existing row holds and what a frontend that does not participate keeps doing. Identity resolution reads the platform off the inbound rather than closing over a channel name, so carriesPersonIdentity finally decides something in production: telegram and email resolve a person, the dashboard and a webhook resolve nothing, and an unknown platform fails closed. Deliberately NOT changed, because it is where this could quietly widen scope: TurnRunnerConfig.Channel still keys tool availability, so no channel gains or loses a tool here. Only session lookup and identity follow the message's platform. Consequence the maintainer accepted: a chat whose active session came from /new or /branch re-resolves once, since GetByChannel now filters on the channel's name. A chat with no /new re-resolves onto the same deterministic session id and heals silently. Verified: gateway, archied, gatewayrpc, messaging, webui, channels and cmd suites, go vet ./..., go build ./..., golangci-lint run ./... (0 issues), docs:check. New contracts: TestResolveSessionKeyStampsTheMessagesPlatform, the per-platform identity table, and the transport-context wire round trip.
70 lines
2.6 KiB
Go
70 lines
2.6 KiB
Go
package archied
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
|
)
|
|
|
|
// TestWebhookUserIdentityNeverReturnsTheRoutePath guards
|
|
// docs/prds/memory-engine-unification.md §3 and §4's specific webhook
|
|
// requirement: internal/channels/webhook/webhook.go carries the configured route
|
|
// path in Inbound.BudgetKey, never in SenderID, and no platform may turn one into
|
|
// a user identity however plausible it looks as one.
|
|
func TestWebhookUserIdentityNeverReturnsTheRoutePath(t *testing.T) {
|
|
resolver := userIdentityResolver()
|
|
id, ok := resolver(messaging.Inbound{
|
|
Platform: "webhook",
|
|
Message: messaging.Message{SenderID: "/github", Sender: "webhook"},
|
|
})
|
|
if ok || id != "" {
|
|
t.Fatalf("webhook resolver = (%q, %v), want (\"\", false)", id, ok)
|
|
}
|
|
}
|
|
|
|
// TestUserIdentityResolverPerPlatform documents the composition's per-platform
|
|
// choice: telegram and email carry a native sender id, the dashboard ("web") and
|
|
// webhook do not, and a platform nobody has decided about fails closed.
|
|
//
|
|
// It is keyed on the message's platform rather than a resolver per channel,
|
|
// because one Gateway Router serves every channel: closing over a channel name
|
|
// resolved every turn as "web" (archie-core-c1qx).
|
|
func TestUserIdentityResolverPerPlatform(t *testing.T) {
|
|
tests := []struct {
|
|
platform string
|
|
senderID string
|
|
wantOK bool
|
|
}{
|
|
{"telegram", "12345", true},
|
|
{"email", "person@example.com", true},
|
|
{"web", "anything", false},
|
|
{"webhook", "/github", false},
|
|
{"unknown-future-channel", "anything", false},
|
|
{"", "anything", false},
|
|
}
|
|
resolver := userIdentityResolver()
|
|
for _, tt := range tests {
|
|
t.Run(tt.platform, func(t *testing.T) {
|
|
id, ok := resolver(messaging.Inbound{Platform: tt.platform, Message: messaging.Message{SenderID: tt.senderID}})
|
|
if ok != tt.wantOK {
|
|
t.Fatalf("%s resolver ok = %v, want %v", tt.platform, ok, tt.wantOK)
|
|
}
|
|
if ok && string(id) != tt.senderID {
|
|
t.Fatalf("%s resolver id = %q, want %q", tt.platform, id, tt.senderID)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestUserIdentityResolverFailsClosedOnEmptySenderID guards §3's "fail closed":
|
|
// an empty SenderID (a channel that carries no per-caller id for this particular
|
|
// message) must resolve to no identity, never an empty-string identity that
|
|
// Subject would treat as present.
|
|
func TestUserIdentityResolverFailsClosedOnEmptySenderID(t *testing.T) {
|
|
resolver := userIdentityResolver()
|
|
id, ok := resolver(messaging.Inbound{Platform: "telegram", Message: messaging.Message{SenderID: ""}})
|
|
if ok || id != "" {
|
|
t.Fatalf("telegram resolver with no sender id = (%q, %v), want (\"\", false)", id, ok)
|
|
}
|
|
}
|