@@ -230,15 +230,9 @@ describe("composer file attachments", () => {
230230 it ( "renders a supported original that exceeds the image limit instead of rejecting it" , async ( ) => {
231231 mocks . pickMedia . mockResolvedValue ( {
232232 canceled : false ,
233- assets : [
234- {
235- ...photo ,
236- fileName : "photo.jpg" ,
237- mimeType : "image/jpeg" ,
238- fileSize : PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1 ,
239- } ,
240- ] ,
233+ assets : [ { ...photo , fileName : "photo.jpg" , mimeType : "image/jpeg" } ] ,
241234 } ) ;
235+ mocks . size . mockReturnValue ( PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1 ) ;
242236
243237 const result = await pickComposerImages ( { existingCount : 0 } ) ;
244238
@@ -249,18 +243,35 @@ describe("composer file attachments", () => {
249243 ] ) ;
250244 } ) ;
251245
252- it ( "measures the picker file when the picker reports no size" , async ( ) => {
246+ it ( "measures the picker file instead of trusting the reported size" , async ( ) => {
247+ // A content stream can deliver more bytes than the picker advertises; a supported
248+ // original only skips rendering when the file itself measures within the limit.
253249 mocks . pickMedia . mockResolvedValue ( {
254250 canceled : false ,
255- assets : [ { ...photo , fileName : "photo.png" , mimeType : "image/png" , fileSize : undefined } ] ,
251+ assets : [ { ...photo , fileName : "photo.png" , mimeType : "image/png" , fileSize : 42 } ] ,
256252 } ) ;
257- mocks . size . mockReturnValue ( 3 ) ;
258- mocks . readBase64 . mockResolvedValue ( "YWJj" ) ;
253+ mocks . size . mockReturnValue ( PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1 ) ;
259254
260255 const result = await pickComposerImages ( { existingCount : 0 } ) ;
261256
262- expect ( mocks . manipulate ) . not . toHaveBeenCalled ( ) ;
263- expect ( result . images ) . toEqual ( [ expect . objectContaining ( { mimeType : "image/png" } ) ] ) ;
257+ expect ( mocks . readBase64 ) . not . toHaveBeenCalled ( ) ;
258+ expect ( mocks . manipulate ) . toHaveBeenCalledWith ( photo . uri ) ;
259+ expect ( result . images ) . toEqual ( [ expect . objectContaining ( { mimeType : "image/jpeg" } ) ] ) ;
260+ } ) ;
261+
262+ it ( "renders a supported original whose size cannot be measured" , async ( ) => {
263+ mocks . pickMedia . mockResolvedValue ( {
264+ canceled : false ,
265+ assets : [
266+ { ...photo , uri : "content://media/1" , fileName : "photo.png" , mimeType : "image/png" } ,
267+ ] ,
268+ } ) ;
269+
270+ const result = await pickComposerImages ( { existingCount : 0 } ) ;
271+
272+ expect ( mocks . readBase64 ) . not . toHaveBeenCalled ( ) ;
273+ expect ( mocks . manipulate ) . toHaveBeenCalledWith ( "content://media/1" ) ;
274+ expect ( result . images ) . toEqual ( [ expect . objectContaining ( { mimeType : "image/jpeg" } ) ] ) ;
264275 } ) ;
265276
266277 it ( "checks the rendered JPEG against the image limit" , async ( ) => {
@@ -334,7 +345,9 @@ describe("composer file attachments", () => {
334345
335346 it ( "retains mixed photos and videos, keeping video bytes in durable file storage" , async ( ) => {
336347 mocks . pickMedia . mockResolvedValue ( { canceled : false , assets : [ image , video ] } ) ;
337- mocks . size . mockReturnValue ( video . fileSize ) ;
348+ mocks . size . mockImplementation ( ( uri : string ) =>
349+ uri . endsWith ( "clip.mov" ) ? video . fileSize : 3 ,
350+ ) ;
338351
339352 const result = await pickComposerMedia ( { existingCount : 0 , maxVideoBytes : 50 * 1024 * 1024 } ) ;
340353
@@ -445,7 +458,7 @@ describe("composer file attachments", () => {
445458 canceled : false ,
446459 assets : [ { ...video , fileSize : reported } , image ] ,
447460 } ) ;
448- mocks . size . mockReturnValue ( stored ) ;
461+ mocks . size . mockImplementation ( ( uri : string ) => ( uri . endsWith ( "clip.mov" ) ? stored : 3 ) ) ;
449462
450463 const result = await pickComposerMedia ( { existingCount : 0 , maxVideoBytes : limit } ) ;
451464
0 commit comments