@@ -1090,6 +1090,41 @@ describe("createAITools filesystem tools", () => {
10901090 expect ( reads ) . toBe ( 1 ) ;
10911091 } ) ;
10921092
1093+ it ( "rejects empty image and PDF attachments" , async ( ) => {
1094+ for ( const { path, size } of [
1095+ { path : "/workspace/empty.png" , size : 0 } ,
1096+ { path : "/workspace/empty.pdf" , size : 0 } ,
1097+ { path : "/workspace/incomplete.png" , size : 10 } ,
1098+ ] ) {
1099+ const store = memoryStore ( { size } ) ;
1100+ store . readChunks = async function * ( ) { } ;
1101+ const tool = createReadTool ( { store } ) ;
1102+
1103+ await expect ( executeTool ( tool , { path } ) ) . resolves . toEqual ( {
1104+ error : `Cannot attach empty file: ${ path } ` ,
1105+ } ) ;
1106+ }
1107+
1108+ const tool = createReadTool ( { store : memoryStore ( { size : 0 } ) } ) ;
1109+ await expect (
1110+ modelOutput (
1111+ tool ,
1112+ { path : "/workspace/empty.png" } ,
1113+ {
1114+ kind : "image" ,
1115+ path : "/workspace/empty.png" ,
1116+ name : "empty.png" ,
1117+ mediaType : "image/png" ,
1118+ sizeBytes : 0 ,
1119+ data : "" ,
1120+ } ,
1121+ ) ,
1122+ ) . resolves . toEqual ( {
1123+ type : "error-text" ,
1124+ value : "Cannot attach empty file: /workspace/empty.png" ,
1125+ } ) ;
1126+ } ) ;
1127+
10931128 it ( "sniffs only a bounded prefix for files without a known extension" , async ( ) => {
10941129 const content = new Uint8Array ( [ 0x25 , 0x50 , 0x44 , 0x46 , 0x2d , ...bytes ( "body" ) ] ) ;
10951130 const ranges : Array < { offset : number ; length : number | undefined } > = [ ] ;
0 commit comments