@@ -2579,6 +2579,84 @@ describe("executePreparedCliRun supervisor output capture", () => {
25792579 ] ) ;
25802580 } ) ;
25812581
2582+ it . each ( [
2583+ {
2584+ label : "the exact source route" ,
2585+ accountId : "account-1" ,
2586+ target : "chat123" ,
2587+ threadId : "thread-1" ,
2588+ expected : true ,
2589+ } ,
2590+ {
2591+ label : "the same target in another account" ,
2592+ accountId : "account-2" ,
2593+ target : "chat123" ,
2594+ threadId : "thread-1" ,
2595+ expected : false ,
2596+ } ,
2597+ {
2598+ label : "the same target in another thread" ,
2599+ accountId : "account-1" ,
2600+ target : "chat123" ,
2601+ threadId : "thread-2" ,
2602+ expected : false ,
2603+ } ,
2604+ {
2605+ label : "another target" ,
2606+ accountId : "account-1" ,
2607+ target : "chat456" ,
2608+ threadId : "thread-1" ,
2609+ expected : false ,
2610+ } ,
2611+ ] ) ( "records explicit message sends only for $label" , async ( testCase ) => {
2612+ const context = buildPreparedCliRunContext ( { output : "text" , provider : "local-cli" } ) ;
2613+ context . mcpDeliveryCapture = true ;
2614+ context . params . sourceReplyDeliveryMode = "message_tool_only" ;
2615+ context . params . messageChannel = TEST_MESSAGE_CHANNEL ;
2616+ context . params . agentAccountId = "account-1" ;
2617+ context . params . currentChannelId = "chat123" ;
2618+ context . params . currentThreadTs = "thread-1" ;
2619+ supervisorSpawnMock . mockImplementationOnce ( async ( ...args : unknown [ ] ) => {
2620+ const input = args [ 0 ] as SupervisorSpawnInput ;
2621+ recordMcpLoopbackToolCallResult ( {
2622+ captureKey : input . env ?. OPENCLAW_MCP_CLI_CAPTURE_KEY ?? "" ,
2623+ toolName : "message" ,
2624+ args : {
2625+ action : "send" ,
2626+ channel : TEST_MESSAGE_CHANNEL ,
2627+ accountId : testCase . accountId ,
2628+ target : testCase . target ,
2629+ threadId : testCase . threadId ,
2630+ message : "explicit reply" ,
2631+ } ,
2632+ result : {
2633+ ok : true ,
2634+ details : {
2635+ deliveryStatus : "sent" ,
2636+ sourceReplySink : "internal-ui" ,
2637+ sourceReply : { text : "explicit reply" } ,
2638+ } ,
2639+ } ,
2640+ isError : false ,
2641+ } ) ;
2642+ input . onStdout ?.( "done" ) ;
2643+ return createManagedRun ( {
2644+ reason : "exit" ,
2645+ exitCode : 0 ,
2646+ exitSignal : null ,
2647+ durationMs : 50 ,
2648+ stdout : "" ,
2649+ stderr : "" ,
2650+ timedOut : false ,
2651+ noOutputTimedOut : false ,
2652+ } ) ;
2653+ } ) ;
2654+
2655+ const result = await executePreparedCliRun ( context ) ;
2656+
2657+ expect ( result . didDeliverSourceReplyViaMessageTool === true ) . toBe ( testCase . expected ) ;
2658+ } ) ;
2659+
25822660 it ( "retains confirmed delivery for long non-streaming message calls" , async ( ) => {
25832661 const context = buildPreparedCliRunContext ( { output : "text" , provider : "local-cli" } ) ;
25842662 context . mcpDeliveryCapture = true ;
0 commit comments