@@ -658,4 +658,110 @@ describe("dispatchOutbound", () => {
658658 expect ( finalized ?. Surface ) . toBe ( "qqbot" ) ;
659659 expect ( finalized ?. ChatType ) . toBe ( "direct" ) ;
660660 } ) ;
661+
662+ it ( "keeps markdown table chunks self-contained across block deliveries" , async ( ) => {
663+ const runtime = makeRuntime ( {
664+ onDispatch : async ( { deliver } ) => {
665+ await deliver (
666+ {
667+ text : [ "| Id | Value |" , "|---:|---|" , "| 1 | alpha |" ] . join ( "\n" ) ,
668+ } ,
669+ { kind : "block" } ,
670+ ) ;
671+ await deliver ( { text : [ "| 2 | beta |" , "| 3 | gamma |" ] . join ( "\n" ) } , { kind : "block" } ) ;
672+ } ,
673+ } ) ;
674+
675+ await dispatchOutbound ( makeInbound ( ) , {
676+ runtime,
677+ cfg : { } ,
678+ account,
679+ } ) ;
680+
681+ expect ( sendTextMock ) . toHaveBeenCalledTimes ( 2 ) ;
682+ expect ( sendTextMock . mock . calls [ 0 ] ?. [ 1 ] ) . toBe (
683+ [ "| Id | Value |" , "|---:|---|" , "| 1 | alpha |" ] . join ( "\n" ) ,
684+ ) ;
685+ expect ( sendTextMock . mock . calls [ 1 ] ?. [ 1 ] ) . toBe (
686+ [ "| Id | Value |" , "|---:|---|" , "| 2 | beta |" , "| 3 | gamma |" ] . join ( "\n" ) ,
687+ ) ;
688+ } ) ;
689+
690+ it ( "waits for a table separator when a block ends after the header" , async ( ) => {
691+ const runtime = makeRuntime ( {
692+ onDispatch : async ( { deliver } ) => {
693+ await deliver ( { text : "| Id | Value |" } , { kind : "block" } ) ;
694+ await deliver ( { text : [ "|---:|---|" , "| 1 | alpha |" ] . join ( "\n" ) } , { kind : "block" } ) ;
695+ } ,
696+ } ) ;
697+
698+ await dispatchOutbound ( makeInbound ( ) , {
699+ runtime,
700+ cfg : { } ,
701+ account,
702+ } ) ;
703+
704+ expect ( sendTextMock . mock . calls . map ( ( call ) => call [ 1 ] ) ) . toEqual ( [
705+ [ "| Id | Value |" , "|---:|---|" , "| 1 | alpha |" ] . join ( "\n" ) ,
706+ ] ) ;
707+ } ) ;
708+
709+ it ( "flushes unfinished markdown table row fragments as plain text fields" , async ( ) => {
710+ const runtime = makeRuntime ( {
711+ onDispatch : async ( { deliver } ) => {
712+ await deliver (
713+ {
714+ text : [ "| Id | Function | Status |" , "|---:|---|---|" , "| 1 | auth | ok |" ] . join ( "\n" ) ,
715+ } ,
716+ { kind : "block" } ,
717+ ) ;
718+ await deliver ( { text : "| 10 | analyzeerror_patterns | 无需重试" } , { kind : "block" } ) ;
719+ } ,
720+ } ) ;
721+
722+ await dispatchOutbound ( makeInbound ( ) , {
723+ runtime,
724+ cfg : { } ,
725+ account,
726+ } ) ;
727+
728+ expect ( sendTextMock . mock . calls . map ( ( call ) => call [ 1 ] ) ) . toEqual ( [
729+ [ "| Id | Function | Status |" , "|---:|---|---|" , "| 1 | auth | ok |" ] . join ( "\n" ) ,
730+ [ "Id: 10" , "Function: analyzeerror_patterns" , "Status: 无需重试" ] . join ( "\n" ) ,
731+ ] ) ;
732+ } ) ;
733+
734+ it ( "holds short table rows until a following block completes the columns" , async ( ) => {
735+ const runtime = makeRuntime ( {
736+ onDispatch : async ( { deliver } ) => {
737+ await deliver (
738+ {
739+ text : [
740+ "| Id | Time | Owner | Note |" ,
741+ "|---:|---|---|---|" ,
742+ "| 16 | 40ms | He | ok |" ,
743+ "| 17 | 100ms |" ,
744+ ] . join ( "\n" ) ,
745+ } ,
746+ { kind : "block" } ,
747+ ) ;
748+ await deliver ( { text : "Lin | daily cap |" } , { kind : "block" } ) ;
749+ } ,
750+ } ) ;
751+
752+ await dispatchOutbound ( makeInbound ( ) , {
753+ runtime,
754+ cfg : { } ,
755+ account,
756+ } ) ;
757+
758+ expect ( sendTextMock . mock . calls . map ( ( call ) => call [ 1 ] ) ) . toEqual ( [
759+ [ "| Id | Time | Owner | Note |" , "|---:|---|---|---|" , "| 16 | 40ms | He | ok |" ] . join ( "\n" ) ,
760+ [
761+ "| Id | Time | Owner | Note |" ,
762+ "|---:|---|---|---|" ,
763+ "| 17 | 100ms | Lin | daily cap |" ,
764+ ] . join ( "\n" ) ,
765+ ] ) ;
766+ } ) ;
661767} ) ;
0 commit comments