@@ -94,14 +94,24 @@ vi.mock("../../channels/plugins/message-action-dispatch.js", () => ({
9494const TEST_AGENT_WORKSPACE = "/tmp/openclaw-test-workspace" ;
9595let sendHandlers : typeof import ( "./send.js" ) . sendHandlers ;
9696
97- function resolveAgentIdFromSessionKeyForTests ( params : { sessionKey ?: string } ) : string {
97+ function resolveAgentIdFromSessionKeyForTests ( params : {
98+ sessionKey ?: string ;
99+ agentId ?: string ;
100+ } ) : string {
101+ const explicitAgentId = params . agentId ?. trim ( ) . toLowerCase ( ) ;
98102 if ( typeof params . sessionKey === "string" ) {
99103 const match = params . sessionKey . match ( / ^ a g e n t : ( [ ^ : ] + ) / i) ;
100104 if ( match ?. [ 1 ] ) {
101- return match [ 1 ] ;
105+ const sessionAgentId = match [ 1 ] . toLowerCase ( ) ;
106+ if ( explicitAgentId && explicitAgentId !== sessionAgentId ) {
107+ throw new Error (
108+ `agent "${ explicitAgentId } " does not match session key agent "${ sessionAgentId } "` ,
109+ ) ;
110+ }
111+ return sessionAgentId ;
102112 }
103113 }
104- return "main" ;
114+ return explicitAgentId ?? "main" ;
105115}
106116
107117function messageActionContextFromSessionKeyForTests ( sessionKey : string ) : {
@@ -139,11 +149,12 @@ vi.mock("../../agents/agent-scope.js", async (importOriginal) => ({
139149 ...( await importOriginal < typeof import ( "../../agents/agent-scope.js" ) > ( ) ) ,
140150 resolveSessionAgentId : ( {
141151 sessionKey,
152+ agentId,
142153 } : {
143154 sessionKey ?: string ;
144155 config ?: unknown ;
145156 agentId ?: string ;
146- } ) => resolveAgentIdFromSessionKeyForTests ( { sessionKey } ) ,
157+ } ) => resolveAgentIdFromSessionKeyForTests ( { sessionKey, agentId } ) ,
147158 resolveAgentConfig : ( ) => undefined ,
148159 resolveDefaultAgentId : ( ) => "main" ,
149160 resolveAgentWorkspaceDir : ( ) => TEST_AGENT_WORKSPACE ,
0 commit comments