@@ -3,6 +3,41 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
33import { resolveBoundAgentIdForSession } from "./session-agent-binding.js" ;
44
55describe ( "resolveBoundAgentIdForSession" , ( ) => {
6+ const multiAgentConfig = {
7+ agents : { entries : { main : { } , research : { } } } ,
8+ } satisfies OpenClawConfig ;
9+ const singleAgentConfig = {
10+ agents : { entries : { main : { } } } ,
11+ } satisfies OpenClawConfig ;
12+
13+ it . each ( [
14+ {
15+ name : "an explicit agent id" ,
16+ params : { config : multiAgentConfig , agentId : "research" , sessionKey : "legacy-session" } ,
17+ expected : "research" ,
18+ } ,
19+ {
20+ name : "an agent-scoped key" ,
21+ params : { config : multiAgentConfig , sessionKey : "agent:research:session:abc" } ,
22+ expected : "research" ,
23+ } ,
24+ {
25+ name : "the canonical main key" ,
26+ params : { config : singleAgentConfig , sessionKey : "main" } ,
27+ expected : "main" ,
28+ } ,
29+ {
30+ name : "the configured main alias" ,
31+ params : {
32+ config : { ...singleAgentConfig , session : { mainKey : "inbox" } } ,
33+ sessionKey : "inbox" ,
34+ } ,
35+ expected : "main" ,
36+ } ,
37+ ] ) ( "binds $name" , ( { params, expected } ) => {
38+ expect ( resolveBoundAgentIdForSession ( params ) ) . toBe ( expected ) ;
39+ } ) ;
40+
641 it ( "binds a bare global key to the persisted fixed-store owner" , ( ) => {
742 const config = {
843 agents : {
@@ -15,4 +50,13 @@ describe("resolveBoundAgentIdForSession", () => {
1550
1651 expect ( resolveBoundAgentIdForSession ( { config, sessionKey : "global" } ) ) . toBe ( "ops" ) ;
1752 } ) ;
53+
54+ it ( "does not grant default-agent authority to an arbitrary unscoped key" , ( ) => {
55+ expect (
56+ resolveBoundAgentIdForSession ( { config : singleAgentConfig , sessionKey : "legacy-session" } ) ,
57+ ) . toBeUndefined ( ) ;
58+ expect (
59+ resolveBoundAgentIdForSession ( { config : multiAgentConfig , sessionKey : "legacy-session" } ) ,
60+ ) . toBeUndefined ( ) ;
61+ } ) ;
1862} ) ;
0 commit comments