@@ -915,9 +915,49 @@ describe("AssetAccess", () => {
915915 kind : "file" ,
916916 path : canonicalCssPath ,
917917 } ) ;
918+ for ( const extension of [ "otf" , "ttf" , "woff" , "woff2" ] ) {
919+ const fontName = `preview.${ extension } ` ;
920+ const fontPath = path . join ( root , fontName ) ;
921+ yield * fileSystem . writeFileString ( fontPath , "font bytes" ) ;
922+ const canonicalFontPath = yield * fileSystem . realPath ( fontPath ) ;
923+ for ( const resource of [
924+ { _tag : "workspace-file" as const , threadId : ThreadId . make ( "thread-1" ) , path : htmlPath } ,
925+ { _tag : "draft-workspace-file" as const , cwd : root , path : "report.html" } ,
926+ ] ) {
927+ const url = yield * issueAssetUrl ( { resource, workspaceRoot : root } ) ;
928+ const suffix = url . relativeUrl . slice ( `${ ASSET_ROUTE_PREFIX } /` . length ) ;
929+ expect ( yield * resolveAsset ( suffix . slice ( 0 , suffix . indexOf ( "/" ) ) , fontName ) ) . toEqual ( {
930+ kind : "file" ,
931+ path : canonicalFontPath ,
932+ } ) ;
933+ }
934+ }
918935 expect ( yield * resolveAsset ( token , "../secret.txt" ) ) . toBeNull ( ) ;
919936 expect ( yield * resolveAsset ( token , ".env" ) ) . toBeNull ( ) ;
920937 expect ( yield * resolveAsset ( `${ token } tampered` , "report.html" ) ) . toBeNull ( ) ;
938+ for ( const extension of [
939+ "docx" ,
940+ "xlsx" ,
941+ "pptx" ,
942+ "bmp" ,
943+ "heic" ,
944+ "tif" ,
945+ "tiff" ,
946+ "weba" ,
947+ "mmd" ,
948+ "mermaid" ,
949+ ] ) {
950+ const siblingName = `private.${ extension } ` ;
951+ yield * fileSystem . writeFileString ( path . join ( root , siblingName ) , "private sibling" ) ;
952+ for ( const resource of [
953+ { _tag : "workspace-file" as const , threadId : ThreadId . make ( "thread-1" ) , path : htmlPath } ,
954+ { _tag : "draft-workspace-file" as const , cwd : root , path : "report.html" } ,
955+ ] ) {
956+ const url = yield * issueAssetUrl ( { resource, workspaceRoot : root } ) ;
957+ const suffix = url . relativeUrl . slice ( `${ ASSET_ROUTE_PREFIX } /` . length ) ;
958+ expect ( yield * resolveAsset ( suffix . slice ( 0 , suffix . indexOf ( "/" ) ) , siblingName ) ) . toBeNull ( ) ;
959+ }
960+ }
921961 } ) . pipe ( Effect . provide ( layerTest ) ) ,
922962 ) ;
923963
@@ -955,6 +995,58 @@ describe("AssetAccess", () => {
955995 } ) . pipe ( Effect . provide ( layerTest ) ) ,
956996 ) ;
957997
998+ it . effect ( "issues exact workspace URLs for image, office, and font previews" , ( ) =>
999+ Effect . gen ( function * ( ) {
1000+ const fileSystem = yield * FileSystem . FileSystem ;
1001+ const path = yield * Path . Path ;
1002+ const root = yield * fileSystem . makeTempDirectoryScoped ( {
1003+ prefix : "t3-asset-image-workspace-" ,
1004+ } ) ;
1005+ const assetsDirectory = path . join ( root , "assets" ) ;
1006+ yield * fileSystem . makeDirectory ( assetsDirectory , { recursive : true } ) ;
1007+ yield * fileSystem . writeFileString (
1008+ path . join ( assetsDirectory , "private.docx" ) ,
1009+ "private document" ,
1010+ ) ;
1011+ for ( const extension of [
1012+ "png" ,
1013+ "bmp" ,
1014+ "heic" ,
1015+ "tif" ,
1016+ "tiff" ,
1017+ "docx" ,
1018+ "xlsx" ,
1019+ "pptx" ,
1020+ "ttf" ,
1021+ "otf" ,
1022+ "woff" ,
1023+ "woff2" ,
1024+ ] ) {
1025+ const name = `preview.${ extension } ` ;
1026+ const filePath = path . join ( assetsDirectory , name ) ;
1027+ const siblingName = `other.${ extension } ` ;
1028+ yield * fileSystem . writeFileString ( filePath , "preview" ) ;
1029+ yield * fileSystem . writeFileString (
1030+ path . join ( assetsDirectory , siblingName ) ,
1031+ "private sibling" ,
1032+ ) ;
1033+ const canonicalPath = yield * fileSystem . realPath ( filePath ) ;
1034+ for ( const resource of [
1035+ { _tag : "workspace-file" as const , threadId : ThreadId . make ( "thread-1" ) , path : filePath } ,
1036+ { _tag : "draft-workspace-file" as const , cwd : root , path : `assets/${ name } ` } ,
1037+ ] ) {
1038+ const result = yield * issueAssetUrl ( { resource, workspaceRoot : root } ) ;
1039+ const suffix = result . relativeUrl . slice ( `${ ASSET_ROUTE_PREFIX } /` . length ) ;
1040+ const token = suffix . slice ( 0 , suffix . indexOf ( "/" ) ) ;
1041+ expect ( yield * resolveAsset ( token , name ) ) . toEqual ( { kind : "file" , path : canonicalPath } ) ;
1042+ expect ( yield * resolveAsset ( token , siblingName ) ) . toBeNull ( ) ;
1043+ expect ( yield * resolveAsset ( token , "private.docx" ) ) . toBeNull ( ) ;
1044+ expect ( yield * resolveAsset ( token , `../${ name } ` ) ) . toBeNull ( ) ;
1045+ }
1046+ }
1047+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
1048+ ) ;
1049+
9581050 it . effect ( "previews workspace files with literal fragment characters in their paths" , ( ) =>
9591051 Effect . gen ( function * ( ) {
9601052 const fileSystem = yield * FileSystem . FileSystem ;
@@ -963,7 +1055,21 @@ describe("AssetAccess", () => {
9631055 const directory = path . join ( root , "assets#archive" ) ;
9641056 yield * fileSystem . makeDirectory ( directory ) ;
9651057
966- for ( const name of [ "icon#v2.png" , "report#draft.pdf" ] ) {
1058+ for ( const name of [
1059+ "icon#v2.png" ,
1060+ "report#draft.pdf" ,
1061+ "report.docx" ,
1062+ "workbook.xlsx" ,
1063+ "slides.pptx" ,
1064+ "specimen.ttf" ,
1065+ "specimen.otf" ,
1066+ "specimen.woff" ,
1067+ "specimen.woff2" ,
1068+ "image.bmp" ,
1069+ "image.heic" ,
1070+ "image.tif" ,
1071+ "image.tiff" ,
1072+ ] ) {
9671073 const filePath = path . join ( directory , name ) ;
9681074 yield * fileSystem . writeFileString ( filePath , "preview fixture" ) ;
9691075 const canonicalFile = yield * fileSystem . realPath ( filePath ) ;
@@ -1049,6 +1155,12 @@ describe("AssetAccess", () => {
10491155 for ( const [ extension , mimeType ] of [
10501156 [ "pdf" , "application/pdf" ] ,
10511157 [ "svg" , "image/svg+xml" ] ,
1158+ [ "bmp" , "image/bmp" ] ,
1159+ [ "ttf" , "font/ttf" ] ,
1160+ [ "otf" , "font/otf" ] ,
1161+ [ "woff" , "font/woff" ] ,
1162+ [ "woff2" , "font/woff2" ] ,
1163+ [ "weba" , "audio/webm" ] ,
10521164 ] as const ) {
10531165 const attachmentId = `thread-1-00000000-0000-4000-8000-000000000001-${ extension } ` ;
10541166 const attachmentPath = path . join ( config . attachmentsDir , `${ attachmentId } .${ extension } ` ) ;
@@ -1059,7 +1171,7 @@ describe("AssetAccess", () => {
10591171 _tag : "attachment" ,
10601172 attachmentId,
10611173 fileName : `report.${ extension } ` ,
1062- mimeType,
1174+ mimeType : "application/octet-stream" ,
10631175 disposition : "inline" ,
10641176 } ,
10651177 } ) ;
0 commit comments