@@ -1094,6 +1094,42 @@ describe("createAITools filesystem tools", () => {
10941094 } ) ;
10951095 } ) ;
10961096
1097+ it ( "recognizes message-only missing media errors" , async ( ) => {
1098+ const store = memoryStore ( { size : 2 } ) ;
1099+ store . readChunks = ( ) => ( {
1100+ [ Symbol . asyncIterator ] ( ) {
1101+ return this ;
1102+ } ,
1103+ async next ( ) : Promise < IteratorResult < Uint8Array > > {
1104+ throw new Error ( "ENOENT: no such file or directory" ) ;
1105+ } ,
1106+ } ) ;
1107+ const tool = createReadTool ( { store, maxModelBytes : 4 } ) ;
1108+ const output = await executeTool ( tool , { path : "/workspace/image.png" } ) ;
1109+
1110+ await expect ( modelOutput ( tool , { path : "/workspace/image.png" } , output ) ) . resolves . toEqual ( {
1111+ type : "error-text" ,
1112+ value : "Could not read file bytes: /workspace/image.png" ,
1113+ } ) ;
1114+ } ) ;
1115+
1116+ it ( "does not confuse unrelated no-such errors with missing media" , async ( ) => {
1117+ const failure = new Error ( "SQLITE_ERROR: no such table: vfs_chunks" ) ;
1118+ const store = memoryStore ( { size : 2 } ) ;
1119+ store . readChunks = ( ) => ( {
1120+ [ Symbol . asyncIterator ] ( ) {
1121+ return this ;
1122+ } ,
1123+ async next ( ) : Promise < IteratorResult < Uint8Array > > {
1124+ throw failure ;
1125+ } ,
1126+ } ) ;
1127+ const tool = createReadTool ( { store, maxModelBytes : 4 } ) ;
1128+ const output = await executeTool ( tool , { path : "/workspace/image.png" } ) ;
1129+
1130+ await expect ( modelOutput ( tool , { path : "/workspace/image.png" } , output ) ) . rejects . toBe ( failure ) ;
1131+ } ) ;
1132+
10971133 it ( "does not hide unrelated inline media read failures" , async ( ) => {
10981134 const failure = new Error ( "storage unavailable" ) ;
10991135 const store = memoryStore ( { size : 2 } ) ;
0 commit comments