@@ -10,6 +10,7 @@ import {
1010 type LineAutoReplyDeps ,
1111} from "./auto-reply-delivery.test-helpers.js" ;
1212import { buildLineMediaMessage } from "./outbound-media.js" ;
13+ import { createFlexMessage as createProviderFlexMessage } from "./send.js" ;
1314
1415describe ( "deliverLineAutoReply" , ( ) => {
1516 it ( "sends text and rich messages on one reply token instead of pushing the rich bubble" , async ( ) => {
@@ -249,13 +250,47 @@ describe("deliverLineAutoReply", () => {
249250 } ) ;
250251 } ) ;
251252
252- it ( "truncates flex altText on a surrogate boundary" , async ( ) => {
253- // The emoji's surrogate pair straddles LINE's 400-char altText cap; a raw
254- // slice used to send a lone high surrogate to the LINE API.
253+ it . each ( [
254+ { label : "explicit card" , extracted : false } ,
255+ { label : "extracted Markdown card" , extracted : true } ,
256+ ] ) ( "preserves provider-valid $label alternative text in auto-replies" , async ( { extracted } ) => {
257+ const altText = "a" . repeat ( 1200 ) ;
258+ const lineData = extracted ? { } : { flexMessage : { altText, contents : { type : "bubble" } } } ;
259+ const { deps, replyMessageLine } = createDeps ( {
260+ ...( extracted
261+ ? {
262+ processLineMessage : ( text ) => ( {
263+ text,
264+ flexMessages : [ { type : "flex" , altText, contents : { type : "bubble" } } ] ,
265+ } ) ,
266+ }
267+ : { } ) ,
268+ createFlexMessage : createProviderFlexMessage ,
269+ } ) ;
270+
271+ await deliverLineAutoReply ( {
272+ ...baseDeliveryParams ,
273+ payload : { text : "hello" , channelData : { line : lineData } } ,
274+ lineData,
275+ deps,
276+ } ) ;
277+
278+ expect ( replyMessageLine ) . toHaveBeenCalledExactlyOnceWith (
279+ "token" ,
280+ [
281+ { type : "text" , text : "hello" } ,
282+ { type : "flex" , altText, contents : { type : "bubble" } } ,
283+ ] ,
284+ { cfg : LINE_TEST_CFG , accountId : "acc" } ,
285+ ) ;
286+ } ) ;
287+
288+ it ( "bounds Flex alternative text without splitting a Unicode surrogate pair" , async ( ) => {
289+ // The emoji crosses the real provider's 1500-character alternative-text boundary.
255290 const lineData = {
256- flexMessage : { altText : `${ "a" . repeat ( 399 ) } 😀 overflow` , contents : { type : "bubble" } } ,
291+ flexMessage : { altText : `${ "a" . repeat ( 1499 ) } 😀 overflow` , contents : { type : "bubble" } } ,
257292 } ;
258- const createFlexMessageSpy = vi . fn ( createFlexMessage ) ;
293+ const createFlexMessageSpy = vi . fn ( createProviderFlexMessage ) ;
259294 const { deps } = createDeps ( {
260295 createFlexMessage : createFlexMessageSpy as LineAutoReplyDeps [ "createFlexMessage" ] ,
261296 } ) ;
@@ -267,8 +302,8 @@ describe("deliverLineAutoReply", () => {
267302 deps,
268303 } ) ;
269304
270- const sentAltText = createFlexMessageSpy . mock . calls [ 0 ] ?. [ 0 ] ?? "" ;
271- expect ( sentAltText . length ) . toBeLessThanOrEqual ( 400 ) ;
305+ const sentAltText = createFlexMessageSpy . mock . results [ 0 ] ?. value . altText ?? "" ;
306+ expect ( sentAltText ) . toBe ( "a" . repeat ( 1499 ) ) ;
272307 expect (
273308 / [ \uD800 - \uDBFF ] (? ! [ \uDC00 - \uDFFF ] ) | (?< ! [ \uD800 - \uDBFF ] ) [ \uDC00 - \uDFFF ] / . test ( sentAltText ) ,
274309 ) . toBe ( false ) ;
0 commit comments