@@ -1215,6 +1215,56 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
12151215 ) ;
12161216 } ) ;
12171217
1218+ it ( "directly delivers direct-message subagent text when the announce agent omits the result" , async ( ) => {
1219+ const callGateway = createGatewayMock ( {
1220+ result : {
1221+ payloads : [ { text : "TG88042_NO_REOUTPUT" } ] ,
1222+ } ,
1223+ } ) ;
1224+ const sendMessage = createSendMessageMock ( ) ;
1225+
1226+ const result = await deliverDiscordDirectMessageCompletion ( {
1227+ callGateway,
1228+ sendMessage,
1229+ internalEvents : [
1230+ {
1231+ type : "task_completion" ,
1232+ source : "subagent" ,
1233+ childSessionKey : "agent:worker:subagent:child" ,
1234+ childSessionId : "child-session-id" ,
1235+ announceType : "subagent task" ,
1236+ taskLabel : "direct completion smoke" ,
1237+ status : "ok" ,
1238+ statusLabel : "completed successfully" ,
1239+ result : "TG88042_CHILD" ,
1240+ replyInstruction : "Summarize the result." ,
1241+ } ,
1242+ ] ,
1243+ } ) ;
1244+
1245+ expectRecordFields ( result , {
1246+ delivered : true ,
1247+ path : "direct" ,
1248+ } ) ;
1249+ expect ( sendMessage ) . toHaveBeenCalledWith (
1250+ expect . objectContaining ( {
1251+ channel : "discord" ,
1252+ accountId : "acct-1" ,
1253+ to : "dm:U123" ,
1254+ content : "TG88042_CHILD" ,
1255+ idempotencyKey : "announce-dm-fallback-empty:text-direct" ,
1256+ } ) ,
1257+ ) ;
1258+ expectGatewayAgentParams ( callGateway , {
1259+ deliver : false ,
1260+ channel : "discord" ,
1261+ accountId : "acct-1" ,
1262+ to : "dm:U123" ,
1263+ threadId : undefined ,
1264+ sourceReplyDeliveryMode : "message_tool_only" ,
1265+ } ) ;
1266+ } ) ;
1267+
12181268 it ( "does not directly deliver failed subagent placeholder output" , async ( ) => {
12191269 const callGateway = createGatewayMock ( {
12201270 result : {
@@ -4176,14 +4226,18 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
41764226 } ) ;
41774227 } ) ;
41784228
4179- it ( "keeps automatic final delivery for direct subagent completions" , async ( ) => {
4229+ it ( "requires message-tool delivery for direct subagent completions" , async ( ) => {
41804230 const callGateway = createGatewayMock ( {
41814231 result : {
4182- payloads : [ { text : "The subagent is done." } ] ,
4232+ payloads : [ { text : "The subagent is done: child completion output" } ] ,
4233+ didSendViaMessagingTool : true ,
4234+ messagingToolSentTexts : [ "The subagent is done: child completion output" ] ,
41834235 } ,
41844236 } ) ;
4237+ const sendMessage = createSendMessageMock ( ) ;
41854238 const result = await deliverDiscordDirectMessageCompletion ( {
41864239 callGateway,
4240+ sendMessage,
41874241 sourceTool : "subagent_announce" ,
41884242 internalEvents : [
41894243 {
@@ -4206,12 +4260,14 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
42064260 path : "direct" ,
42074261 } ) ;
42084262 expectGatewayAgentParams ( callGateway , {
4209- deliver : true ,
4263+ deliver : false ,
42104264 channel : "discord" ,
42114265 accountId : "acct-1" ,
42124266 to : "dm:U123" ,
42134267 threadId : undefined ,
4268+ sourceReplyDeliveryMode : "message_tool_only" ,
42144269 } ) ;
4270+ expect ( sendMessage ) . not . toHaveBeenCalled ( ) ;
42154271 } ) ;
42164272
42174273 it ( "falls back to the external requester route when completion origin is internal" , async ( ) => {
0 commit comments