@@ -932,6 +932,89 @@ describe('Function execution request', () => {
932932 ] )
933933 } )
934934
935+ it ( 'exports a .jpg declared without a format as image/jpeg bytes, never as base64 text' , async ( ) => {
936+ // The sandbox reads a .jpg back as base64; the exporter used to classify it by its
937+ // (unknown) output format, default to json, and store the base64 string verbatim.
938+ envFlagsMock . isRemoteSandboxEnabled = true
939+ const jpegBase64 = Buffer . from ( [ 0xff , 0xd8 , 0xff , 0xe0 , 0x00 , 0x10 ] ) . toString ( 'base64' )
940+ mockExecuteInSandbox . mockResolvedValueOnce ( {
941+ result : 'done' ,
942+ stdout : 'ok' ,
943+ sandboxId : 'sandbox-123' ,
944+ cost : { input : 0 , output : 0 , total : 0.0001 } ,
945+ exportedFiles : {
946+ '/home/user/thumbs/01.jpg' : jpegBase64 ,
947+ '/home/user/summary.json' : '{"ok":true}' ,
948+ } ,
949+ } )
950+
951+ const req = createMockRequest ( 'POST' , {
952+ code : 'print("done")' ,
953+ language : 'python' ,
954+ workspaceId : 'workspace-1' ,
955+ workflowId : 'workflow-1' ,
956+ executionId : 'execution-1' ,
957+ outputs : {
958+ files : [
959+ {
960+ path : 'files/thumbs/01.jpg' ,
961+ mode : 'create' ,
962+ sandboxPath : '/home/user/thumbs/01.jpg' ,
963+ } ,
964+ { path : 'files/summary.json' , mode : 'create' , sandboxPath : '/home/user/summary.json' } ,
965+ ] ,
966+ } ,
967+ } )
968+
969+ const response = await POST ( req )
970+ expect ( response . status ) . toBe ( 200 )
971+ expect ( mockWriteWorkspaceFileByPath ) . toHaveBeenCalledTimes ( 2 )
972+ const [ jpgCall , jsonCall ] = mockWriteWorkspaceFileByPath . mock . calls . map ( ( call ) => call [ 0 ] )
973+ expect ( jpgCall . target ) . toEqual ( expect . objectContaining ( { path : 'files/thumbs/01.jpg' } ) )
974+ expect ( jpgCall . inferredMimeType ) . toBe ( 'image/jpeg' )
975+ expect ( Buffer . from ( jpgCall . buffer ) . equals ( Buffer . from ( jpegBase64 , 'base64' ) ) ) . toBe ( true )
976+ expect ( jsonCall . target ) . toEqual ( expect . objectContaining ( { path : 'files/summary.json' } ) )
977+ expect ( jsonCall . inferredMimeType ) . toBe ( 'application/json' )
978+ expect ( Buffer . from ( jsonCall . buffer ) . toString ( 'utf-8' ) ) . toBe ( '{"ok":true}' )
979+ } )
980+
981+ it ( 'exports a single .jpg declared without a format as image/jpeg bytes (single-file path)' , async ( ) => {
982+ envFlagsMock . isRemoteSandboxEnabled = true
983+ const jpegBase64 = Buffer . from ( [ 0xff , 0xd8 , 0xff , 0xe0 , 0x00 , 0x10 ] ) . toString ( 'base64' )
984+ mockExecuteInSandbox . mockResolvedValueOnce ( {
985+ result : 'done' ,
986+ stdout : 'ok' ,
987+ sandboxId : 'sandbox-123' ,
988+ cost : { input : 0 , output : 0 , total : 0.0001 } ,
989+ exportedFiles : { '/home/user/thumbs/02.jpg' : jpegBase64 } ,
990+ } )
991+
992+ const req = createMockRequest ( 'POST' , {
993+ code : 'print("done")' ,
994+ language : 'python' ,
995+ workspaceId : 'workspace-1' ,
996+ workflowId : 'workflow-1' ,
997+ executionId : 'execution-1' ,
998+ outputs : {
999+ files : [
1000+ {
1001+ path : 'files/thumbs/02.jpg' ,
1002+ mode : 'create' ,
1003+ sandboxPath : '/home/user/thumbs/02.jpg' ,
1004+ } ,
1005+ ] ,
1006+ } ,
1007+ } )
1008+
1009+ const response = await POST ( req )
1010+ expect ( response . status ) . toBe ( 200 )
1011+ expect ( mockWriteWorkspaceFileByPath ) . toHaveBeenCalledTimes ( 1 )
1012+ const call = mockWriteWorkspaceFileByPath . mock . calls [ 0 ] ?. [ 0 ]
1013+ expect ( call . target ) . toEqual ( expect . objectContaining ( { path : 'files/thumbs/02.jpg' } ) )
1014+ expect ( call . inferredMimeType ) . toBe ( 'image/jpeg' )
1015+ expect ( Buffer . from ( call . buffer ) . equals ( Buffer . from ( jpegBase64 , 'base64' ) ) ) . toBe ( true )
1016+ } )
1017+
9351018 it ( "keeps the code's returned rows beside the sandbox export receipt" , async ( ) => {
9361019 envFlagsMock . isRemoteSandboxEnabled = true
9371020 const rows = [ { name : 'Ada' } , { name : 'Grace' } ]
0 commit comments