@@ -1167,7 +1167,10 @@ describe("Slack live QA runtime helpers", () => {
11671167 ? [
11681168 {
11691169 blocks : storedPayload . blocks ,
1170- text : storedPayload . text ,
1170+ text :
1171+ typeof storedPayload . text === "string"
1172+ ? storedPayload . text . replace ( / \s + / gu, " " )
1173+ : storedPayload . text ,
11711174 ts : "2.000000" ,
11721175 user : "U999999999" ,
11731176 } ,
@@ -1203,17 +1206,59 @@ describe("Slack live QA runtime helpers", () => {
12031206 const fallbackText = typeof fallbackRequest ?. text === "string" ? fallbackRequest . text : "" ;
12041207 expect ( fallbackText . split ( "\n" ) ) . toContain ( probe . firstRowText ) ;
12051208 expect ( fallbackText . split ( "\n" ) ) . toContain ( probe . finalRowText ) ;
1206- expect ( result . message ) . toMatchObject ( {
1207- text : fallbackText ,
1208- ts : "2.000000" ,
1209- user : "U999999999" ,
1210- } ) ;
1209+ expect ( result . message ) . toMatchObject ( { ts : "2.000000" , user : "U999999999" } ) ;
1210+ expect ( result . message . text ) . toBe ( fallbackText . replace ( / \s + / gu, " " ) ) ;
12111211 expect ( result . details ) . toContain ( "first API failure=invalid_blocks" ) ;
12121212 expect ( result . details ) . toContain ( "fallback formatting disabled=true" ) ;
12131213 expect ( result . details ) . toContain ( "complete delivery=true" ) ;
12141214 expect ( sutWriteClient . chat . postMessage ) . toBe ( postMessage ) ;
12151215 } ) ;
12161216
1217+ it ( "bounds invalid_blocks readback diagnostics while showing the observed text" , async ( ) => {
1218+ const malformedReadback = `BROKEN-${ "x" . repeat ( 2_000 ) } ` ;
1219+ const postMessage = vi . fn ( async ( ) => ( {
1220+ channel : "C123456789" ,
1221+ ok : true ,
1222+ ts : "2.000000" ,
1223+ } ) ) ;
1224+ const sutWriteClient = { chat : { postMessage } } ;
1225+ const cfg = testing . buildSlackQaConfig (
1226+ { } ,
1227+ {
1228+ channelId : "C123456789" ,
1229+ driverBotUserId : "U111111111" ,
1230+ sutAccountId : "sut" ,
1231+ sutAppToken : "xapp-sut" ,
1232+ sutBotToken : "xoxb-sut" ,
1233+ } ,
1234+ ) ;
1235+
1236+ const error = await testing
1237+ . runSlackTableInvalidBlocksFallbackScenario ( {
1238+ cfg,
1239+ channelId : "C123456789" ,
1240+ sutAccountId : "sut" ,
1241+ sutIdentity : { userId : "U999999999" } ,
1242+ sutReadClient : {
1243+ conversations : {
1244+ history : vi . fn ( async ( ) => ( {
1245+ messages : [ { text : malformedReadback , ts : "2.000000" , user : "U999999999" } ] ,
1246+ } ) ) ,
1247+ } ,
1248+ } as never ,
1249+ sutWriteClient : sutWriteClient as never ,
1250+ timeoutMs : 0 ,
1251+ } )
1252+ . catch ( ( caught : unknown ) => caught ) ;
1253+
1254+ expect ( error ) . toBeInstanceOf ( Error ) ;
1255+ const message = ( error as Error ) . message ;
1256+ expect ( message ) . toContain ( `${ malformedReadback . length } characters` ) ;
1257+ expect ( message ) . toContain ( 'actual="BROKEN-' ) ;
1258+ expect ( message ) . toContain ( "…" ) ;
1259+ expect ( message . length ) . toBeLessThan ( 700 ) ;
1260+ } ) ;
1261+
12171262 it ( "reports the real Slack error when the fallback request fails" , async ( ) => {
12181263 const postMessage = vi . fn ( async ( ) => {
12191264 throw Object . assign ( new Error ( "do not persist this raw platform detail" ) , {
0 commit comments