@@ -221,6 +221,8 @@ describe("AssetAccess", () => {
221221 [ "recording.webm" , "video/webm" ] ,
222222 [ "report.html" , "text/html" ] ,
223223 [ "report.pdf" , "application/pdf" ] ,
224+ [ "tone.wav" , "audio/wav" ] ,
225+ [ "tone.webm-audio" , "audio/webm" ] ,
224226 ] as const ) {
225227 const filePath = path . join ( outside , name ) ;
226228 yield * fs . writeFileString ( filePath , "media" ) ;
@@ -245,6 +247,65 @@ describe("AssetAccess", () => {
245247 } ) . pipe ( Effect . provide ( layerTest ) ) ,
246248 ) ;
247249
250+ it . effect ( "downloads any linked file with the same exact-file identity checks as media" , ( ) =>
251+ Effect . gen ( function * ( ) {
252+ const fs = yield * FileSystem . FileSystem ;
253+ const path = yield * Path . Path ;
254+ const root = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-download-root-" } ) ;
255+ const outside = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-download-outside-" } ) ;
256+ for ( const name of [
257+ "data.csv" ,
258+ "report.docx" ,
259+ "sheet.xlsx" ,
260+ "slides.pptx" ,
261+ "archive.zip" ,
262+ "no-extension" ,
263+ ] ) {
264+ for ( const directory of [ root , outside ] ) {
265+ const filePath = path . join ( directory , name ) ;
266+ yield * fs . writeFileString ( filePath , "shared file bytes" ) ;
267+ const resource = {
268+ _tag : "media-file" as const ,
269+ threadId : ThreadId . make ( "thread-1" ) ,
270+ path : directory === root ? name : filePath ,
271+ disposition : "attachment" as const ,
272+ } ;
273+ const result = yield * issueAssetUrl ( { resource, workspaceRoot : root } ) ;
274+ const suffix = result . relativeUrl . slice ( `${ ASSET_ROUTE_PREFIX } /` . length ) ;
275+ const separator = suffix . indexOf ( "/" ) ;
276+ const token = suffix . slice ( 0 , separator ) ;
277+ const asset = yield * resolveAsset ( token , suffix . slice ( separator + 1 ) ) ;
278+ expect ( asset ) . toMatchObject ( {
279+ kind : "file" ,
280+ download : true ,
281+ fileName : name ,
282+ mimeType : "application/octet-stream" ,
283+ } ) ;
284+ if ( asset ?. kind !== "file" ) throw new Error ( "Expected a downloadable file" ) ;
285+ const response = HttpServerResponse . toWeb ( yield * assetFileResponse ( asset ) ) ;
286+ expect ( response . headers . get ( "content-disposition" ) ) . toContain ( "attachment;" ) ;
287+ expect ( response . headers . get ( "content-type" ) ) . toBe ( "application/octet-stream" ) ;
288+ expect ( yield * Effect . promise ( ( ) => response . text ( ) ) ) . toBe ( "shared file bytes" ) ;
289+ expect ( yield * resolveAsset ( token , "sibling.docx" ) ) . toBeNull ( ) ;
290+ expect ( yield * resolveAsset ( token , `../${ name } ` ) ) . toBeNull ( ) ;
291+ expect ( yield * resolveAsset ( `${ token } tampered` , name ) ) . toBeNull ( ) ;
292+ yield * fs . rename ( filePath , `${ filePath } .original` ) ;
293+ yield * fs . writeFileString ( filePath , "replacement bytes" ) ;
294+ expect ( yield * resolveAsset ( token , name ) ) . toBeNull ( ) ;
295+ }
296+ }
297+ const directoryError = yield * issueAssetUrl ( {
298+ resource : {
299+ _tag : "media-file" ,
300+ threadId : ThreadId . make ( "thread-1" ) ,
301+ path : root ,
302+ disposition : "attachment" ,
303+ } ,
304+ } ) . pipe ( Effect . flip ) ;
305+ expect ( directoryError . _tag ) . toBe ( "AssetWorkspaceAssetNotFoundError" ) ;
306+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
307+ ) ;
308+
248309 it . effect ( "resolves relative media paths from the thread workspace, including outside it" , ( ) =>
249310 Effect . gen ( function * ( ) {
250311 const fs = yield * FileSystem . FileSystem ;
0 commit comments