@@ -140,6 +140,35 @@ describe('POST /api/tools/agiloft/retrieve', () => {
140140 expect ( inputValidationMockFns . mockValidateUrlWithDNS ) . toHaveBeenCalledTimes ( 1 )
141141 } )
142142
143+ it ( 'resolves the real type when Agiloft labels an attachment octet-stream' , async ( ) => {
144+ const fileBytes = Buffer . from ( 'PKdocx-bytes' , 'utf-8' )
145+
146+ inputValidationMockFns . mockSecureFetchWithPinnedIP . mockResolvedValueOnce (
147+ mockSecureFetchResponse ( {
148+ arrayBuffer : fileBytes . buffer . slice (
149+ fileBytes . byteOffset ,
150+ fileBytes . byteOffset + fileBytes . byteLength
151+ ) as ArrayBuffer ,
152+ headers : new Headers ( {
153+ 'content-type' : 'application/octet-stream' ,
154+ 'content-disposition' : 'attachment; filename="Master Agreement.docx"' ,
155+ } ) ,
156+ } )
157+ )
158+
159+ const response = await POST ( createMockRequest ( 'POST' , baseBody ) )
160+ const data = ( await response . json ( ) ) as { output : { file : { mimeType : string } } }
161+
162+ /**
163+ * Agiloft labels most attachments octet-stream whatever they are. The
164+ * filename disambiguates what the leading bytes cannot: a ZIP header is
165+ * equally a .docx, .xlsx or a plain archive.
166+ */
167+ expect ( data . output . file . mimeType ) . toBe (
168+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
169+ )
170+ } )
171+
143172 it ( 'propagates upstream errors' , async ( ) => {
144173 inputValidationMockFns . mockSecureFetchWithPinnedIP . mockResolvedValueOnce (
145174 mockSecureFetchResponse ( { ok : false , status : 404 , text : 'Record not found' } )
0 commit comments