@@ -8,6 +8,7 @@ import type {
88} from "../channels/plugins/types.adapters.js" ;
99import type { CliDeps } from "../cli/deps.js" ;
1010import { clearRuntimeConfigSnapshot , setRuntimeConfigSnapshot } from "../config/config.js" ;
11+ import { callGateway } from "../gateway/call.js" ;
1112import { resolveOutboundSendDep } from "../infra/outbound/send-deps.js" ;
1213import { setActivePluginRegistry } from "../plugins/runtime.js" ;
1314import { createOutboundTestPlugin , createTestRegistry } from "../test-utils/channel-plugins.js" ;
@@ -72,13 +73,15 @@ async function runExplicitAnnounceTurn(params: {
7273 cfg : ReturnType < typeof makeCfg > ;
7374 deps : CliDeps ;
7475 channel : ChannelCase [ "channel" ] ;
76+ deleteAfterRun ?: boolean ;
7577 to : string ;
7678} ) {
7779 return await runCronIsolatedAgentTurn ( {
7880 cfg : params . cfg ,
7981 deps : params . deps ,
8082 job : {
8183 ...makeJob ( { kind : "agentTurn" , message : "do it" } ) ,
84+ ...( params . deleteAfterRun === true ? { deleteAfterRun : true } : { } ) ,
8285 delivery : {
8386 mode : "announce" ,
8487 channel : params . channel ,
@@ -119,6 +122,7 @@ function expectCoreChannelSendCall({
119122
120123async function expectCoreChannelAnnounceDelivery ( {
121124 assertSend,
125+ deleteAfterRun,
122126 meta,
123127 payloads,
124128 testCase,
@@ -127,6 +131,7 @@ async function expectCoreChannelAnnounceDelivery({
127131 meta ?: Parameters < typeof mockAgentPayloads > [ 1 ] ;
128132 payloads : Parameters < typeof mockAgentPayloads > [ 0 ] ;
129133 testCase : ChannelCase ;
134+ deleteAfterRun ?: boolean ;
130135} ) : Promise < void > {
131136 await withTempCronHome ( async ( home ) => {
132137 const storePath = await writeSessionStore ( home , { lastProvider : "webchat" , lastTo : "" } ) ;
@@ -142,6 +147,7 @@ async function expectCoreChannelAnnounceDelivery({
142147 cfg,
143148 deps,
144149 channel : testCase . channel ,
150+ deleteAfterRun,
145151 to : testCase . to ,
146152 } ) ;
147153
@@ -322,6 +328,33 @@ describe("runCronIsolatedAgentTurn core-channel direct delivery", () => {
322328 clearRuntimeConfigSnapshot ( ) ;
323329 } ) ;
324330
331+ it ( "delivers only the final Slack result after an earlier heartbeat acknowledgement" , async ( ) => {
332+ const slack = CASES [ 0 ] ;
333+ if ( ! slack ) {
334+ throw new Error ( "expected Slack channel case" ) ;
335+ }
336+ const finalResult = "Critical deployment failure: database unavailable." ;
337+ await expectCoreChannelAnnounceDelivery ( {
338+ testCase : slack ,
339+ deleteAfterRun : true ,
340+ payloads : [ { text : "HEARTBEAT_OK" } , { text : finalResult } ] ,
341+ meta : { meta : makeRunMeta ( finalResult ) } ,
342+ assertSend : ( sendFn , cfg ) => {
343+ expect ( sendFn ) . toHaveBeenCalledTimes ( 1 ) ;
344+ expectCoreChannelSendCall ( {
345+ cfg,
346+ expectedText : finalResult ,
347+ expectedTo : slack . expectedTo ,
348+ sendFn,
349+ sentAt : 0 ,
350+ } ) ;
351+ } ,
352+ } ) ;
353+ expect ( callGateway ) . toHaveBeenCalledWith (
354+ expect . objectContaining ( { method : "sessions.delete" } ) ,
355+ ) ;
356+ } ) ;
357+
325358 for ( const testCase of CASES ) {
326359 it ( `routes ${ testCase . name } text-only announce delivery through the outbound adapter` , async ( ) => {
327360 await expectCoreChannelAnnounceDelivery ( {
0 commit comments