@@ -1186,27 +1186,21 @@ describe("Slack live QA runtime helpers", () => {
11861186 expect ( probe . fallbackText . split ( "\n" ) ) . toContain ( probe . finalRowText ) ;
11871187 } ) ;
11881188
1189- it ( "proves the public Slack send path stores one complete formatting-disabled fallback" , async ( ) => {
1189+ it ( "proves the public Slack send path stores complete ordered fallback chunks " , async ( ) => {
11901190 const probe = testing . buildSlackInvalidBlocksTableProbe ( ) ;
1191- let storedPayload : Record < string , unknown > | undefined ;
1191+ const storedPayloads : Array < Record < string , unknown > & { ts : string } > = [ ] ;
11921192 const postMessage = vi . fn ( async ( payload : Record < string , unknown > ) => {
1193- storedPayload = payload ;
1194- return { channel : "C123456789" , ok : true , ts : "2.000000" } ;
1193+ const ts = `2.${ String ( storedPayloads . length + 1 ) . padStart ( 6 , "0" ) } ` ;
1194+ storedPayloads . push ( { ...payload , ts } ) ;
1195+ return { channel : "C123456789" , ok : true , ts } ;
11951196 } ) ;
11961197 const history = vi . fn ( async ( ) => ( {
1197- messages : storedPayload
1198- ? [
1199- {
1200- blocks : storedPayload . blocks ,
1201- text :
1202- typeof storedPayload . text === "string"
1203- ? storedPayload . text . replace ( / \s + / gu, " " )
1204- : storedPayload . text ,
1205- ts : "2.000000" ,
1206- user : "U999999999" ,
1207- } ,
1208- ]
1209- : [ ] ,
1198+ messages : storedPayloads . toReversed ( ) . map ( ( payload ) => ( {
1199+ blocks : payload . blocks ,
1200+ text : typeof payload . text === "string" ? payload . text . replace ( / \s + / gu, " " ) : payload . text ,
1201+ ts : payload . ts ,
1202+ user : "U999999999" ,
1203+ } ) ) ,
12101204 } ) ) ;
12111205 const sutWriteClient = { chat : { postMessage } } ;
12121206 const cfg = testing . buildSlackQaConfig (
@@ -1230,28 +1224,48 @@ describe("Slack live QA runtime helpers", () => {
12301224 timeoutMs : 0 ,
12311225 } ) ;
12321226
1233- expect ( postMessage ) . toHaveBeenCalledTimes ( 1 ) ;
1234- const [ fallbackRequest ] = postMessage . mock . calls [ 0 ] ?? [ ] ;
1235- expect ( fallbackRequest ) . not . toHaveProperty ( "blocks" ) ;
1236- expect ( fallbackRequest ) . toMatchObject ( { mrkdwn : false } ) ;
1237- const fallbackText = typeof fallbackRequest ?. text === "string" ? fallbackRequest . text : "" ;
1227+ expect ( postMessage ) . toHaveBeenCalledTimes ( 3 ) ;
1228+ const fallbackRequests = postMessage . mock . calls . map ( ( [ request ] ) => request ) ;
1229+ expect ( fallbackRequests . every ( ( request ) => ! Object . hasOwn ( request , "blocks" ) ) ) . toBe ( true ) ;
1230+ expect ( fallbackRequests . every ( ( request ) => request . mrkdwn === false ) ) . toBe ( true ) ;
1231+ const fallbackText = fallbackRequests . map ( ( request ) => request . text ) . join ( "" ) ;
1232+ expect ( fallbackText ) . toHaveLength ( probe . fallbackText . length ) ;
12381233 expect ( fallbackText . split ( "\n" ) ) . toContain ( probe . firstRowText ) ;
12391234 expect ( fallbackText . split ( "\n" ) ) . toContain ( probe . finalRowText ) ;
1240- expect ( result . message ) . toMatchObject ( { ts : "2.000000" , user : "U999999999" } ) ;
1241- expect ( result . message . text ) . toBe ( fallbackText . replace ( / \s + / gu, " " ) ) ;
1235+ expect ( storedPayloads . map ( ( payload ) => payload . ts ) ) . toEqual ( [
1236+ "2.000001" ,
1237+ "2.000002" ,
1238+ "2.000003" ,
1239+ ] ) ;
1240+ expect (
1241+ storedPayloads
1242+ . map ( ( payload ) =>
1243+ typeof payload . text === "string" ? payload . text . replace ( / \s + / gu, " " ) : "" ,
1244+ )
1245+ . join ( "" ) ,
1246+ ) . toBe ( fallbackText . replace ( / \s + / gu, " " ) ) ;
1247+ expect ( result . message ) . toMatchObject ( { ts : "2.000003" , user : "U999999999" } ) ;
12421248 expect ( result . details ) . toContain ( "first API failure=invalid_blocks" ) ;
1249+ expect ( result . details ) . toContain ( "API attempts=4" ) ;
12431250 expect ( result . details ) . toContain ( "fallback formatting disabled=true" ) ;
1251+ expect ( result . details ) . toContain ( "fallback chunks=3" ) ;
1252+ expect ( result . details ) . toContain ( "first row=present" ) ;
1253+ expect ( result . details ) . toContain ( "final row=present" ) ;
12441254 expect ( result . details ) . toContain ( "complete delivery=true" ) ;
12451255 expect ( sutWriteClient . chat . postMessage ) . toBe ( postMessage ) ;
12461256 } ) ;
12471257
12481258 it ( "bounds invalid_blocks readback diagnostics while showing the observed text" , async ( ) => {
12491259 const malformedReadback = `BROKEN-${ "x" . repeat ( 2_000 ) } ` ;
1250- const postMessage = vi . fn ( async ( ) => ( {
1251- channel : "C123456789" ,
1252- ok : true ,
1253- ts : "2.000000" ,
1254- } ) ) ;
1260+ let postCount = 0 ;
1261+ const postMessage = vi . fn ( async ( ) => {
1262+ postCount += 1 ;
1263+ return {
1264+ channel : "C123456789" ,
1265+ ok : true ,
1266+ ts : `2.${ String ( postCount ) . padStart ( 6 , "0" ) } ` ,
1267+ } ;
1268+ } ) ;
12551269 const sutWriteClient = { chat : { postMessage } } ;
12561270 const cfg = testing . buildSlackQaConfig (
12571271 { } ,
@@ -1273,7 +1287,11 @@ describe("Slack live QA runtime helpers", () => {
12731287 sutReadClient : {
12741288 conversations : {
12751289 history : vi . fn ( async ( ) => ( {
1276- messages : [ { text : malformedReadback , ts : "2.000000" , user : "U999999999" } ] ,
1290+ messages : [
1291+ { text : "" , ts : "2.000003" , user : "U999999999" } ,
1292+ { text : "" , ts : "2.000002" , user : "U999999999" } ,
1293+ { text : malformedReadback , ts : "2.000001" , user : "U999999999" } ,
1294+ ] ,
12771295 } ) ) ,
12781296 } ,
12791297 } as never ,
@@ -1318,7 +1336,9 @@ describe("Slack live QA runtime helpers", () => {
13181336 sutWriteClient : sutWriteClient as never ,
13191337 timeoutMs : 0 ,
13201338 } ) ,
1321- ) . rejects . toThrow ( "Slack fallback failed after invalid_blocks; observed invalid_arguments" ) ;
1339+ ) . rejects . toThrow (
1340+ "Slack fallback part 1 failed after invalid_blocks; observed invalid_arguments" ,
1341+ ) ;
13221342 expect ( sutWriteClient . chat . postMessage ) . toBe ( postMessage ) ;
13231343 } ) ;
13241344
@@ -1351,8 +1371,46 @@ describe("Slack live QA runtime helpers", () => {
13511371 timeoutMs : 0 ,
13521372 } ) ,
13531373 ) . rejects . toThrow (
1354- "Slack fallback failed after invalid_blocks; observed no fallback API failure code" ,
1374+ "Slack fallback part 1 failed after invalid_blocks; observed no fallback API failure code" ,
1375+ ) ;
1376+ expect ( sutWriteClient . chat . postMessage ) . toBe ( postMessage ) ;
1377+ } ) ;
1378+
1379+ it ( "reports a later Slack fallback chunk failure" , async ( ) => {
1380+ const postMessage = vi
1381+ . fn ( )
1382+ . mockResolvedValueOnce ( { channel : "C123456789" , ok : true , ts : "2.000001" } )
1383+ . mockRejectedValueOnce (
1384+ Object . assign ( new Error ( "do not persist this raw platform detail" ) , {
1385+ data : { error : "invalid_arguments" , ok : false } ,
1386+ } ) ,
1387+ ) ;
1388+ const sutWriteClient = { chat : { postMessage } } ;
1389+ const cfg = testing . buildSlackQaConfig (
1390+ { } ,
1391+ {
1392+ channelId : "C123456789" ,
1393+ driverBotUserId : "U111111111" ,
1394+ sutAccountId : "sut" ,
1395+ sutAppToken : "xapp-sut" ,
1396+ sutBotToken : "xoxb-sut" ,
1397+ } ,
1398+ ) ;
1399+
1400+ await expect (
1401+ testing . runSlackTableInvalidBlocksFallbackScenario ( {
1402+ cfg,
1403+ channelId : "C123456789" ,
1404+ sutAccountId : "sut" ,
1405+ sutIdentity : { userId : "U999999999" } ,
1406+ sutReadClient : { conversations : { history : vi . fn ( ) } } as never ,
1407+ sutWriteClient : sutWriteClient as never ,
1408+ timeoutMs : 0 ,
1409+ } ) ,
1410+ ) . rejects . toThrow (
1411+ "Slack fallback part 2 failed after invalid_blocks; observed invalid_arguments" ,
13551412 ) ;
1413+ expect ( postMessage ) . toHaveBeenCalledTimes ( 2 ) ;
13561414 expect ( sutWriteClient . chat . postMessage ) . toBe ( postMessage ) ;
13571415 } ) ;
13581416
0 commit comments