@@ -284,5 +284,67 @@ describe("channels:get-message command", () => {
284284 expect ( error ) . toBeDefined ( ) ;
285285 expect ( error ?. message ) . toContain ( "Message not found" ) ;
286286 } ) ;
287+
288+ it ( "enriches 40400 errors with the mutableMessages hint" , async ( ) => {
289+ const mock = getMockAblyRest ( ) ;
290+ const channel = mock . channels . _getChannel ( "test-channel" ) ;
291+ const notFound = Object . assign ( new Error ( "Message not found" ) , {
292+ code : 40400 ,
293+ statusCode : 404 ,
294+ } ) ;
295+ channel . getMessage . mockRejectedValue ( notFound ) ;
296+
297+ const { error } = await runCommand (
298+ [ COMMAND , "test-channel" , "serial-001" ] ,
299+ import . meta. url ,
300+ ) ;
301+
302+ expect ( error ) . toBeDefined ( ) ;
303+ expect ( error ?. message ) . toContain ( "Message not found" ) ;
304+ expect ( error ?. message ) . toContain ( "mutableMessages" ) ;
305+ expect ( error ?. message ) . toContain ( "ably apps rules list" ) ;
306+ } ) ;
307+
308+ it ( "does NOT enrich non-40400 errors with the mutableMessages hint" , async ( ) => {
309+ const mock = getMockAblyRest ( ) ;
310+ const channel = mock . channels . _getChannel ( "test-channel" ) ;
311+ const otherErr = Object . assign ( new Error ( "Some other error" ) , {
312+ code : 50000 ,
313+ statusCode : 500 ,
314+ } ) ;
315+ channel . getMessage . mockRejectedValue ( otherErr ) ;
316+
317+ const { error } = await runCommand (
318+ [ COMMAND , "test-channel" , "serial-001" ] ,
319+ import . meta. url ,
320+ ) ;
321+
322+ expect ( error ) . toBeDefined ( ) ;
323+ expect ( error ?. message ) . toContain ( "Some other error" ) ;
324+ expect ( error ?. message ) . not . toContain ( "mutableMessages" ) ;
325+ } ) ;
326+
327+ it ( "includes the mutableMessages hint in JSON error envelope for 40400" , async ( ) => {
328+ const mock = getMockAblyRest ( ) ;
329+ const channel = mock . channels . _getChannel ( "test-channel" ) ;
330+ const notFound = Object . assign ( new Error ( "Message not found" ) , {
331+ code : 40400 ,
332+ statusCode : 404 ,
333+ } ) ;
334+ channel . getMessage . mockRejectedValue ( notFound ) ;
335+
336+ const { stdout } = await runCommand (
337+ [ COMMAND , "test-channel" , "serial-001" , "--json" ] ,
338+ import . meta. url ,
339+ ) ;
340+
341+ const records = parseNdjsonLines ( stdout ) ;
342+ const errorRecord = records . find ( ( r ) => r . type === "error" ) as
343+ | { error : { message : string ; code : number } }
344+ | undefined ;
345+ expect ( errorRecord ) . toBeDefined ( ) ;
346+ expect ( errorRecord ! . error . message ) . toContain ( "mutableMessages" ) ;
347+ expect ( errorRecord ! . error . code ) . toBe ( 40400 ) ;
348+ } ) ;
287349 } ) ;
288350} ) ;
0 commit comments