@@ -266,6 +266,8 @@ describe("AssetAccess", () => {
266266 [ "recording.webm" , "video/webm" ] ,
267267 [ "report.html" , "text/html" ] ,
268268 [ "report.pdf" , "application/pdf" ] ,
269+ [ "tone.wav" , "audio/wav" ] ,
270+ [ "tone.webm-audio" , "audio/webm" ] ,
269271 ] as const ) {
270272 const filePath = path . join ( outside , name ) ;
271273 yield * fs . writeFileString ( filePath , "media" ) ;
@@ -290,6 +292,65 @@ describe("AssetAccess", () => {
290292 } ) . pipe ( Effect . provide ( layerTest ) ) ,
291293 ) ;
292294
295+ it . effect ( "downloads any linked file with the same exact-file identity checks as media" , ( ) =>
296+ Effect . gen ( function * ( ) {
297+ const fs = yield * FileSystem . FileSystem ;
298+ const path = yield * Path . Path ;
299+ const root = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-download-root-" } ) ;
300+ const outside = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-download-outside-" } ) ;
301+ for ( const name of [
302+ "data.csv" ,
303+ "report.docx" ,
304+ "sheet.xlsx" ,
305+ "slides.pptx" ,
306+ "archive.zip" ,
307+ "no-extension" ,
308+ ] ) {
309+ for ( const directory of [ root , outside ] ) {
310+ const filePath = path . join ( directory , name ) ;
311+ yield * fs . writeFileString ( filePath , "shared file bytes" ) ;
312+ const resource = {
313+ _tag : "media-file" as const ,
314+ threadId : ThreadId . make ( "thread-1" ) ,
315+ path : directory === root ? name : filePath ,
316+ disposition : "attachment" as const ,
317+ } ;
318+ const result = yield * issueAssetUrl ( { resource, workspaceRoot : root } ) ;
319+ const suffix = result . relativeUrl . slice ( `${ ASSET_ROUTE_PREFIX } /` . length ) ;
320+ const separator = suffix . indexOf ( "/" ) ;
321+ const token = suffix . slice ( 0 , separator ) ;
322+ const asset = yield * resolveAsset ( token , suffix . slice ( separator + 1 ) ) ;
323+ expect ( asset ) . toMatchObject ( {
324+ kind : "file" ,
325+ download : true ,
326+ fileName : name ,
327+ mimeType : "application/octet-stream" ,
328+ } ) ;
329+ if ( asset ?. kind !== "file" ) throw new Error ( "Expected a downloadable file" ) ;
330+ const response = HttpServerResponse . toWeb ( yield * assetFileResponse ( asset ) ) ;
331+ expect ( response . headers . get ( "content-disposition" ) ) . toContain ( "attachment;" ) ;
332+ expect ( response . headers . get ( "content-type" ) ) . toBe ( "application/octet-stream" ) ;
333+ expect ( yield * Effect . promise ( ( ) => response . text ( ) ) ) . toBe ( "shared file bytes" ) ;
334+ expect ( yield * resolveAsset ( token , "sibling.docx" ) ) . toBeNull ( ) ;
335+ expect ( yield * resolveAsset ( token , `../${ name } ` ) ) . toBeNull ( ) ;
336+ expect ( yield * resolveAsset ( `${ token } tampered` , name ) ) . toBeNull ( ) ;
337+ yield * fs . rename ( filePath , `${ filePath } .original` ) ;
338+ yield * fs . writeFileString ( filePath , "replacement bytes" ) ;
339+ expect ( yield * resolveAsset ( token , name ) ) . toBeNull ( ) ;
340+ }
341+ }
342+ const directoryError = yield * issueAssetUrl ( {
343+ resource : {
344+ _tag : "media-file" ,
345+ threadId : ThreadId . make ( "thread-1" ) ,
346+ path : root ,
347+ disposition : "attachment" ,
348+ } ,
349+ } ) . pipe ( Effect . flip ) ;
350+ expect ( directoryError . _tag ) . toBe ( "AssetWorkspaceAssetNotFoundError" ) ;
351+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
352+ ) ;
353+
293354 it . effect ( "reports pixel dimensions from an image header and nothing for other files" , ( ) =>
294355 Effect . gen ( function * ( ) {
295356 const fs = yield * FileSystem . FileSystem ;
0 commit comments