mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
refactor(routing): move session allocation out of router
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user