Files
picoclaw/pkg/session/allocator_test.go
T

52 lines
1.3 KiB
Go

package session
import (
"testing"
"github.com/sipeed/picoclaw/pkg/routing"
)
func TestAllocateRouteSession_PerPeerDM(t *testing.T) {
allocation := AllocateRouteSession(AllocationInput{
AgentID: "main",
Channel: "telegram",
AccountID: "default",
Peer: &routing.RoutePeer{
Kind: "direct",
ID: "User123",
},
SessionPolicy: routing.SessionPolicy{
DMScope: routing.DMScopePerPeer,
},
})
if allocation.SessionKey != "agent:main:direct:user123" {
t.Fatalf("SessionKey = %q, want %q", allocation.SessionKey, "agent:main:direct:user123")
}
if allocation.MainSessionKey != "agent:main:main" {
t.Fatalf("MainSessionKey = %q, want %q", allocation.MainSessionKey, "agent:main:main")
}
}
func TestAllocateRouteSession_GroupPeer(t *testing.T) {
allocation := AllocateRouteSession(AllocationInput{
AgentID: "main",
Channel: "slack",
AccountID: "workspace-a",
Peer: &routing.RoutePeer{
Kind: "channel",
ID: "C001",
},
SessionPolicy: routing.SessionPolicy{
DMScope: routing.DMScopePerAccountChannelPeer,
},
})
if allocation.SessionKey != "agent:main:slack:channel:c001" {
t.Fatalf("SessionKey = %q, want %q", allocation.SessionKey, "agent:main:slack:channel:c001")
}
if allocation.MainSessionKey != "agent:main:main" {
t.Fatalf("MainSessionKey = %q, want %q", allocation.MainSessionKey, "agent:main:main")
}
}