@@ -425,6 +425,49 @@ describe("sendMessageIrc cfg threading", () => {
425425 expect ( client . quit ) . toHaveBeenCalledOnce ( ) ;
426426 } ) ;
427427
428+ it ( "stops before recording another chunk after the connection closes" , async ( ) => {
429+ const providedCfg = {
430+ channels : {
431+ irc : {
432+ host : "irc.example.com" ,
433+ nick : "openclaw" ,
434+ } ,
435+ } ,
436+ } as unknown as CoreConfig ;
437+ let ready = true ;
438+ const client = {
439+ isReady : vi . fn ( ( ) => ready ) ,
440+ join : vi . fn ( ) ,
441+ sendPrivmsg : vi . fn ( ) ,
442+ quit : vi . fn ( ) ,
443+ } as unknown as IrcClient & {
444+ join : ReturnType < typeof vi . fn > ;
445+ sendPrivmsg : ReturnType < typeof vi . fn > ;
446+ quit : ReturnType < typeof vi . fn > ;
447+ } ;
448+ hoisted . connectIrcClient . mockResolvedValue ( client ) ;
449+ const onDeliveryResult = vi . fn ( ( ) => {
450+ ready = false ;
451+ } ) ;
452+ const onPlatformSendDispatch = vi . fn ( ) ;
453+ const text = Array . from ( { length : 80 } , ( _ , index ) => `word-${ index } ` ) . join ( " " ) ;
454+
455+ await expect (
456+ sendFormattedIrcText ( {
457+ cfg : providedCfg ,
458+ to : "#room" ,
459+ text,
460+ onDeliveryResult,
461+ onPlatformSendDispatch,
462+ } ) ,
463+ ) . rejects . toThrow ( "IRC connection closed before send" ) ;
464+
465+ expect ( client . sendPrivmsg ) . toHaveBeenCalledOnce ( ) ;
466+ expect ( onPlatformSendDispatch ) . toHaveBeenCalledOnce ( ) ;
467+ expect ( onDeliveryResult ) . toHaveBeenCalledOnce ( ) ;
468+ expect ( client . quit ) . toHaveBeenCalledOnce ( ) ;
469+ } ) ;
470+
428471 it ( "declares message adapter durable text, media, and reply with receipt proofs" , async ( ) => {
429472 const providedCfg = {
430473 channels : {
0 commit comments