@@ -1638,7 +1638,14 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
16381638 . deliver ( { text } , { kind : "final" } )
16391639 . catch ( ( caught : unknown ) => caught ) ;
16401640
1641- expect ( isChannelPartialDeliveryError ( error ) ) . toBe ( true ) ;
1641+ expect ( error ) . toMatchObject ( {
1642+ code : "CHANNEL_PARTIAL_DELIVERY" ,
1643+ deliveryResult : {
1644+ content : text ,
1645+ messageIds : [ ] ,
1646+ visibleReplySent : true ,
1647+ } ,
1648+ } ) ;
16421649 expect ( provider ) . toHaveBeenCalledOnce ( ) ;
16431650 await Promise . resolve ( options . onError ?.( error , { kind : "final" } ) ) ;
16441651 expect ( result . getVisibleReplyState ( ) . visibleReplySent ) . toBe ( true ) ;
@@ -1650,6 +1657,50 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
16501657 } ,
16511658 ) ;
16521659
1660+ it . each ( [
1661+ { kind : "text" , provider : sendMessageFeishuMock , acceptedBeforeReceiptLoss : 0 } ,
1662+ { kind : "text" , provider : sendMessageFeishuMock , acceptedBeforeReceiptLoss : 1 } ,
1663+ { kind : "card" , provider : sendStructuredCardFeishuMock , acceptedBeforeReceiptLoss : 0 } ,
1664+ { kind : "card" , provider : sendStructuredCardFeishuMock , acceptedBeforeReceiptLoss : 1 } ,
1665+ ] ) (
1666+ "retains accepted $kind chunk content after receipt loss with $acceptedBeforeReceiptLoss prior receipts" ,
1667+ async ( { kind, provider, acceptedBeforeReceiptLoss } ) => {
1668+ useNonStreamingAutoAccount ( ) ;
1669+ const runtime = getFeishuRuntimeMock ( ) ;
1670+ runtime . channel . text . resolveTextChunkLimit . mockReturnValue ( 6 ) ;
1671+ runtime . channel . text . chunkMarkdownTextWithMode . mockReturnValue ( [ "first" , "second" , "third" ] ) ;
1672+
1673+ if ( acceptedBeforeReceiptLoss > 0 ) {
1674+ provider . mockResolvedValueOnce ( { messageId : "om-first" } ) ;
1675+ }
1676+ provider . mockRejectedValueOnce (
1677+ createChannelPartialDeliveryError (
1678+ new Error ( "Feishu reply failed: no message_id returned" ) ,
1679+ {
1680+ messageIds : [ ] ,
1681+ visibleReplySent : true ,
1682+ } ,
1683+ ) ,
1684+ ) ;
1685+ const { options } = createDispatcherHarness ( ) ;
1686+ const text = kind === "card" ? "| first | second |\n| - | - |" : "firstsecondthird" ;
1687+
1688+ const error = await options
1689+ . deliver ( { text } , { kind : "final" } )
1690+ . catch ( ( caught : unknown ) => caught ) ;
1691+
1692+ expect ( error ) . toMatchObject ( {
1693+ code : "CHANNEL_PARTIAL_DELIVERY" ,
1694+ deliveryResult : {
1695+ content : acceptedBeforeReceiptLoss > 0 ? "firstsecond" : "first" ,
1696+ messageIds : acceptedBeforeReceiptLoss > 0 ? [ "om-first" ] : [ ] ,
1697+ visibleReplySent : true ,
1698+ } ,
1699+ } ) ;
1700+ expect ( provider ) . toHaveBeenCalledTimes ( acceptedBeforeReceiptLoss + 1 ) ;
1701+ } ,
1702+ ) ;
1703+
16531704 it ( "retains the finalized streaming card when companion media never dispatches" , async ( ) => {
16541705 const marker = Object . assign (
16551706 new Error ( "media load failed" , { cause : new Error ( "blocked local load" ) } ) ,
0 commit comments