@@ -97,4 +97,44 @@ describe("dispatchReplyFromConfig terminal visible admission recovery", () => {
9797 expect ( replyResolver ) . toHaveBeenCalledTimes ( 1 ) ;
9898 expect ( dispatchParams . dispatcher . sendFinalReply ) . toHaveBeenCalledTimes ( 1 ) ;
9999 } ) ;
100+
101+ it ( "records a failed reply operation when recovering a visible partial" , async ( ) => {
102+ const resolverError = new Error ( "provider failed after partial" ) ;
103+ let replyOperation : ReturnType < typeof createReplyOperation > | undefined ;
104+ const replyResolver : NonNullable < DispatchFromConfigParams [ "replyResolver" ] > = async (
105+ _ctx ,
106+ options ,
107+ ) => {
108+ if ( ! options ) {
109+ throw new Error ( "reply options required for partial recovery" ) ;
110+ }
111+ replyOperation = options . replyOperation ;
112+ await options . onPartialReply ?.( { text : "partial telegram reply" } ) ;
113+ throw resolverError ;
114+ } ;
115+ const dispatchParams = {
116+ ...createVisibleDispatchParams ( replyResolver ) ,
117+ replyOptions : {
118+ onPartialReply : vi . fn ( async ( ) => undefined ) ,
119+ } ,
120+ } ;
121+
122+ const result = await dispatchReplyFromConfig ( dispatchParams ) ;
123+
124+ expect ( replyOperation ?. result ) . toEqual ( {
125+ kind : "failed" ,
126+ code : "run_failed" ,
127+ cause : resolverError ,
128+ } ) ;
129+ expect ( result ) . toMatchObject ( {
130+ queuedFinal : true ,
131+ counts : { tool : 0 , block : 0 , final : 0 } ,
132+ } ) ;
133+ expect ( dispatchParams . replyOptions . onPartialReply ) . toHaveBeenCalledWith ( {
134+ text : "partial telegram reply" ,
135+ } ) ;
136+ expect ( dispatchParams . dispatcher . sendFinalReply ) . toHaveBeenCalledWith (
137+ expect . objectContaining ( { text : expect . stringContaining ( "Something went wrong" ) } ) ,
138+ ) ;
139+ } ) ;
100140} ) ;
0 commit comments