@@ -361,5 +361,58 @@ describe("makeMcpAppHost", () => {
361361 expect ( sent . find ( ( m ) => m . id === 2 ) ?. result ) . toEqual ( { } ) ;
362362 expect ( sent . find ( ( m ) => m . id === 3 ) ?. result ) . toEqual ( { isError : true } ) ;
363363 expect ( sent . find ( ( m ) => m . id === 4 ) ?. error ) . toMatchObject ( { code : - 32602 } ) ;
364+
365+ const filenames = [
366+ [ "https://example.invalid/report.csv?version=2" , undefined , "report.csv" ] ,
367+ [ "https://example.invalid/report.csv#page=2" , undefined , "report.csv" ] ,
368+ [ "https://example.invalid/report.csv?next=/noise.json#page=3" , undefined , "report.csv" ] ,
369+ [ "urn:example:report.csv" , undefined , "urn-example-report.csv" ] ,
370+ [ "custom:report.csv" , undefined , "custom-report.csv" ] ,
371+ [ "https://example.invalid/report%20final.csv?version=2" , undefined , "report%20final.csv" ] ,
372+ [ "https://example.invalid/report.csv?version=2" , " chosen/name?.csv " , " chosen-name-.csv " ] ,
373+ [ "https://example.invalid/report.csv?version=2" , " " , "report.csv" ] ,
374+ [ "file:///report.csv" , "a" . repeat ( 201 ) , "a" . repeat ( 200 ) ] ,
375+ [ "" , undefined , "download" ] ,
376+ [ "file:///folder/" , undefined , "folder" ] ,
377+ ] as const ;
378+ for ( const [ index , [ uri , name , expectedName ] ] of filenames . entries ( ) ) {
379+ const id = `download-${ index } ` ;
380+ const downloadIndex = downloads . length ;
381+ host . receive ( {
382+ jsonrpc : "2.0" ,
383+ id,
384+ method : "ui/download-file" ,
385+ params : {
386+ contents : [
387+ {
388+ ...embedded ,
389+ resource : { ...embedded . resource , uri, ...( name === undefined ? { } : { name } ) } ,
390+ } ,
391+ ] ,
392+ } ,
393+ } ) ;
394+ await flush ( ) ;
395+ expect ( downloads [ downloadIndex ] ) . toEqual ( [
396+ {
397+ _tag : "embedded" ,
398+ name : expectedName ,
399+ mimeType : "text/csv" ,
400+ bytes : new TextEncoder ( ) . encode ( "a,b" ) ,
401+ } ,
402+ ] ) ;
403+ expect ( sent . find ( ( m ) => m . id === id ) ?. result ) . toEqual ( { } ) ;
404+ }
405+
406+ const linkUri = "https://example.invalid/report.csv?version=2#page=3" ;
407+ const downloadIndex = downloads . length ;
408+ host . receive ( {
409+ jsonrpc : "2.0" ,
410+ id : "download-link" ,
411+ method : "ui/download-file" ,
412+ params : { contents : [ { type : "resource_link" , uri : linkUri , name : "chosen.csv" } ] } ,
413+ } ) ;
414+ await flush ( ) ;
415+ expect ( downloads [ downloadIndex ] ) . toEqual ( [ { _tag : "link" , name : "chosen.csv" , uri : linkUri } ] ) ;
416+ expect ( sent . find ( ( m ) => m . id === "download-link" ) ?. result ) . toEqual ( { } ) ;
364417 } ) ;
365418} ) ;
0 commit comments