@@ -947,8 +947,42 @@ describe("sendMessageTelegram", () => {
947947 } ) ;
948948 } ) ;
949949
950- it ( "keeps markdown media syntax on the text-only rich path " , async ( ) => {
950+ it ( "preserves rich markdown line breaks outside fenced code " , async ( ) => {
951951 botApi . sendMessage . mockResolvedValue ( { message_id : 47 , chat : { id : "123" } } ) ;
952+ const markdown = [
953+ "Status: ok | mode" ,
954+ "Models: ready" ,
955+ "" ,
956+ "```" ,
957+ "a" ,
958+ "b" ,
959+ "```" ,
960+ "Tail" ,
961+ ] . join ( "\n" ) ;
962+ const expectedMarkdown = [
963+ "Status: ok | mode " ,
964+ "Models: ready" ,
965+ "" ,
966+ "```" ,
967+ "a" ,
968+ "b" ,
969+ "```" ,
970+ "Tail" ,
971+ ] . join ( "\n" ) ;
972+
973+ await sendMessageTelegram ( "123" , markdown , {
974+ cfg : TELEGRAM_TEST_CFG ,
975+ token : "tok" ,
976+ } ) ;
977+
978+ expect ( botRawApi . sendRichMessage ) . toHaveBeenCalledWith ( {
979+ chat_id : "123" ,
980+ rich_message : { markdown : expectedMarkdown } ,
981+ } ) ;
982+ } ) ;
983+
984+ it ( "keeps markdown media syntax on the text-only rich path" , async ( ) => {
985+ botApi . sendMessage . mockResolvedValue ( { message_id : 48 , chat : { id : "123" } } ) ;
952986
953987 await sendMessageTelegram ( "123" , "See " , {
954988 cfg : TELEGRAM_TEST_CFG ,
@@ -962,7 +996,7 @@ describe("sendMessageTelegram", () => {
962996 } ) ;
963997
964998 it ( "escapes HTML media tags on the text-only rich path" , async ( ) => {
965- botApi . sendMessage . mockResolvedValue ( { message_id : 48 , chat : { id : "123" } } ) ;
999+ botApi . sendMessage . mockResolvedValue ( { message_id : 49 , chat : { id : "123" } } ) ;
9661000
9671001 await sendMessageTelegram ( "123" , '<b>See</b><img src="https://example.com/diagram.png">' , {
9681002 cfg : TELEGRAM_TEST_CFG ,
@@ -979,7 +1013,7 @@ describe("sendMessageTelegram", () => {
9791013 } ) ;
9801014
9811015 it ( "keeps native rich markdown tables within Telegram's column limit" , async ( ) => {
982- botApi . sendMessage . mockResolvedValue ( { message_id : 49 , chat : { id : "123" } } ) ;
1016+ botApi . sendMessage . mockResolvedValue ( { message_id : 50 , chat : { id : "123" } } ) ;
9831017 const markdown = markdownTable ( 20 ) ;
9841018
9851019 await sendMessageTelegram ( "123" , markdown , {
@@ -994,7 +1028,7 @@ describe("sendMessageTelegram", () => {
9941028 } ) ;
9951029
9961030 it ( "wraps wide rich markdown tables that exceed Telegram's column limit" , async ( ) => {
997- botApi . sendMessage . mockResolvedValue ( { message_id : 50 , chat : { id : "123" } } ) ;
1031+ botApi . sendMessage . mockResolvedValue ( { message_id : 51 , chat : { id : "123" } } ) ;
9981032 const markdown = markdownTable ( 21 ) ;
9991033
10001034 await sendMessageTelegram ( "123" , markdown , {
@@ -1009,7 +1043,7 @@ describe("sendMessageTelegram", () => {
10091043 } ) ;
10101044
10111045 it ( "leaves wide rich markdown tables alone inside fences" , async ( ) => {
1012- botApi . sendMessage . mockResolvedValue ( { message_id : 51 , chat : { id : "123" } } ) ;
1046+ botApi . sendMessage . mockResolvedValue ( { message_id : 52 , chat : { id : "123" } } ) ;
10131047 const markdown = `~~~\n${ markdownTable ( 25 ) } \n~~~` ;
10141048
10151049 await sendMessageTelegram ( "123" , markdown , {
@@ -1046,7 +1080,9 @@ describe("sendMessageTelegram", () => {
10461080
10471081 it ( "sends long rich markdown as one message" , async ( ) => {
10481082 botApi . sendMessage . mockResolvedValue ( { message_id : 53 , chat : { id : "123" } } ) ;
1049- const markdown = `# Long\n\n${ "**section** with _style_ and `code`\n" . repeat ( 800 ) } ` ;
1083+ const line = "**section** with _style_ and `code`" ;
1084+ const markdown = `# Long\n\n${ `${ line } \n` . repeat ( 800 ) } ` ;
1085+ const expectedMarkdown = `# Long\n\n${ `${ line } \n` . repeat ( 799 ) } ${ line } \n` ;
10501086
10511087 await sendMessageTelegram ( "123" , markdown , {
10521088 cfg : TELEGRAM_TEST_CFG ,
@@ -1056,7 +1092,7 @@ describe("sendMessageTelegram", () => {
10561092 expect ( botRawApi . sendRichMessage ) . toHaveBeenCalledTimes ( 1 ) ;
10571093 expect ( botRawApi . sendRichMessage ) . toHaveBeenCalledWith ( {
10581094 chat_id : "123" ,
1059- rich_message : { markdown } ,
1095+ rich_message : { markdown : expectedMarkdown } ,
10601096 } ) ;
10611097 } ) ;
10621098
0 commit comments