@@ -374,19 +374,46 @@ describe('buildCopilotRequestPayload', () => {
374374 ] )
375375 } )
376376
377- it ( 'fails the request when an authorized attachment cannot be prepared ' , async ( ) => {
377+ it ( 'isolates a failed attachment and still prepares valid siblings ' , async ( ) => {
378378 const cause = new Error ( 'provenance sidecar unavailable' )
379- mockTrackChatUpload . mockRejectedValueOnce ( cause )
380-
381- await expect (
382- buildCopilotRequestPayload (
383- { ...attachmentParams , userPermission : 'write' } ,
384- { selectedModel : 'claude-opus-4-8' }
385- )
386- ) . rejects . toMatchObject ( {
387- message : 'Failed to prepare attached file "payroll.xlsx" for Copilot. Please try again.' ,
388- cause,
389- } )
379+ mockTrackChatUpload
380+ . mockRejectedValueOnce ( cause )
381+ . mockResolvedValueOnce ( { displayName : 'photo.png' } )
382+
383+ const payload = await buildCopilotRequestPayload (
384+ {
385+ ...attachmentParams ,
386+ userPermission : 'write' ,
387+ fileAttachments : [
388+ ...attachmentParams . fileAttachments ,
389+ {
390+ id : 'a2' ,
391+ key : 'workspace/ws-1/1731000000001-ab12cd35-photo.png' ,
392+ filename : 'photo.png' ,
393+ media_type : 'image/png' ,
394+ size : 10 ,
395+ } ,
396+ ] ,
397+ } ,
398+ { selectedModel : 'claude-opus-4-8' }
399+ )
400+
401+ expect ( mockTrackChatUpload ) . toHaveBeenCalledTimes ( 2 )
402+ expect ( payload . context ) . toEqual ( [
403+ {
404+ type : 'uploaded_file' ,
405+ content :
406+ 'File "payroll.xlsx" could not be prepared for Copilot and was omitted. Other attached files remain available.' ,
407+ } ,
408+ {
409+ type : 'uploaded_file' ,
410+ content : [
411+ 'File "photo.png" (image/png, 10 bytes) uploaded.' ,
412+ 'Read with: read("uploads/photo.png")' ,
413+ 'To save permanently: materialize_file(fileName: "photo.png")' ,
414+ ] . join ( '\n' ) ,
415+ } ,
416+ ] )
390417 } )
391418 } )
392419
0 commit comments