11// Interim retry tests cover retry behavior for incomplete isolated cron runs.
2- import { describe , expect , it } from "vitest" ;
2+ import { describe , expect , it , vi } from "vitest" ;
3+ import { shouldSkipHeartbeatOnlyDelivery } from "../heartbeat-policy.js" ;
34import { makeIsolatedAgentParamsFixture } from "./job-fixtures.js" ;
45import { setupRunCronIsolatedAgentTurnSuite } from "./run.suite-helpers.js" ;
56import {
@@ -11,6 +12,7 @@ import {
1112 mockRunCronFallbackPassthrough ,
1213 pickLastNonEmptyTextFromPayloadsMock ,
1314 resolveCronDeliveryPlanMock ,
15+ resolveCronPayloadOutcomeMock ,
1416 runEmbeddedAgentMock ,
1517 runWithModelFallbackMock ,
1618} from "./run.test-harness.js" ;
@@ -129,6 +131,33 @@ describe("runCronIsolatedAgentTurn — interim ack retry", () => {
129131 await runTurnAndExpectOk ( 1 , 1 ) ;
130132 } ) ;
131133
134+ it ( "delivers a final result after an earlier heartbeat acknowledgement" , async ( ) => {
135+ const finalResult = "Critical deployment failure: database unavailable." ;
136+ const payloads = [ { text : "HEARTBEAT_OK" } , { text : finalResult } ] ;
137+ const { resolveCronPayloadOutcome } =
138+ await vi . importActual < typeof import ( "./helpers.js" ) > ( "./helpers.js" ) ;
139+ usePayloadTextExtraction ( ) ;
140+ resolveCronPayloadOutcomeMock . mockImplementation ( resolveCronPayloadOutcome ) ;
141+ isHeartbeatOnlyResponseMock . mockImplementation ( shouldSkipHeartbeatOnlyDelivery ) ;
142+ resolveCronDeliveryPlanMock . mockReturnValue ( {
143+ requested : true ,
144+ mode : "announce" ,
145+ channel : "messagechat" ,
146+ to : "123" ,
147+ } ) ;
148+ runEmbeddedAgentMock . mockResolvedValueOnce ( {
149+ payloads,
150+ meta : { agentMeta : { usage : { input : 10 , output : 20 } } } ,
151+ } ) ;
152+
153+ mockRunCronFallbackPassthrough ( ) ;
154+ const result = await runTurnAndExpectOk ( 1 , 1 ) ;
155+
156+ expect ( result . delivered ) . toBe ( true ) ;
157+ expect ( requireDeliveryRequest ( ) . skipHeartbeatDelivery ) . toBe ( false ) ;
158+ expect ( requireDeliveryRequest ( ) . deliveryPayloads ) . toEqual ( payloads ) ;
159+ } ) ;
160+
132161 it ( "does not retry over a fatal structured failure signal" , async ( ) => {
133162 usePayloadTextExtraction ( ) ;
134163 runEmbeddedAgentMock . mockResolvedValueOnce ( {
0 commit comments