@@ -9,6 +9,7 @@ import { nanoGptDefaultModelId, providerIdentifiers } from "@roo-code/types"
99
1010import { buildApiHandler } from "../../index"
1111import { asyncStreamFrom , collectStream } from "../../../test-utils/stream"
12+ import { createReadFileTool } from "../../../core/prompts/tools/native-tools/read_file"
1213import { NanoGptHandler } from "../nanogpt"
1314import { getModels } from "../fetchers/modelCache"
1415
@@ -171,6 +172,101 @@ describe("NanoGptHandler", () => {
171172 expect ( mockCreate . mock . calls [ 0 ] [ 0 ] ) . not . toHaveProperty ( "max_completion_tokens" )
172173 } )
173174
175+ it . each ( [ "auto" , "tools" ] as const ) ( "preserves read_file optionality with %s routing" , async ( routing ) => {
176+ const tool = createReadFileTool ( )
177+ if ( tool . type !== "function" ) throw new Error ( "read_file must be a function tool" )
178+ const original = structuredClone ( tool )
179+ const handler = new NanoGptHandler ( { nanoGptModelId : "model:thinking" , nanoGptRoutingPreference : routing } )
180+
181+ await collectStream (
182+ handler . createMessage ( "sys" , messages , { taskId : "task" , tools : [ tool ] , tool_choice : "auto" } ) ,
183+ )
184+
185+ expect ( mockCreate ) . toHaveBeenCalledWith (
186+ expect . objectContaining ( {
187+ tool_choice : "auto" ,
188+ tools : [ { ...original , function : { ...original . function , strict : false } } ] ,
189+ } ) ,
190+ expect . anything ( ) ,
191+ )
192+ expect ( tool ) . toEqual ( original )
193+ expect ( tool . function . parameters ?. required ) . toEqual ( [ "path" ] )
194+ } )
195+
196+ it . each ( [ "custom_read" , "mcp--files--read" ] ) (
197+ "preserves nested, nullable, and required fields for %s" ,
198+ async ( name ) => {
199+ const tool : OpenAI . Chat . ChatCompletionTool = {
200+ type : "function" ,
201+ function : {
202+ name,
203+ strict : true ,
204+ parameters : {
205+ type : "object" ,
206+ required : [ "path" ] ,
207+ additionalProperties : false ,
208+ properties : {
209+ path : { type : "string" } ,
210+ label : { type : [ "string" , "null" ] } ,
211+ options : {
212+ type : "object" ,
213+ required : [ "offset" ] ,
214+ properties : { offset : { type : "integer" , minimum : 1 } , limit : { type : "integer" } } ,
215+ } ,
216+ ranges : {
217+ type : "array" ,
218+ items : {
219+ type : "object" ,
220+ required : [ "start" ] ,
221+ properties : { start : { type : "integer" } , end : { type : "integer" } } ,
222+ } ,
223+ } ,
224+ } ,
225+ } ,
226+ } ,
227+ }
228+ const original = structuredClone ( tool )
229+ await collectStream (
230+ new NanoGptHandler ( { nanoGptModelId : "model:thinking" } ) . createMessage ( "sys" , messages , {
231+ taskId : "task" ,
232+ tools : [ tool ] ,
233+ tool_choice : { type : "function" , function : { name } } ,
234+ } ) ,
235+ )
236+ expect ( mockCreate ) . toHaveBeenCalledWith (
237+ expect . objectContaining ( {
238+ tools : [ { ...original , function : { ...original . function , strict : false } } ] ,
239+ tool_choice : { type : "function" , function : { name } } ,
240+ } ) ,
241+ expect . anything ( ) ,
242+ )
243+ expect ( tool ) . toEqual ( original )
244+ } ,
245+ )
246+
247+ it . each ( [ undefined , [ ] ] ) ( "preserves an absent or empty tool catalog (%j)" , async ( tools ) => {
248+ await collectStream (
249+ new NanoGptHandler ( { nanoGptModelId : "model:thinking" } ) . createMessage ( "sys" , messages , {
250+ taskId : "task" ,
251+ tools,
252+ } ) ,
253+ )
254+ expect ( mockCreate ) . toHaveBeenCalledWith ( expect . objectContaining ( { tools } ) , expect . anything ( ) )
255+ } )
256+
257+ it ( "passes non-function tools through unchanged" , async ( ) => {
258+ const tools : OpenAI . Chat . ChatCompletionTool [ ] = [
259+ { type : "custom" , custom : { name : "custom_tool" , format : { type : "text" } } } ,
260+ ]
261+ await collectStream (
262+ new NanoGptHandler ( { nanoGptModelId : "model:thinking" } ) . createMessage ( "sys" , messages , {
263+ taskId : "task" ,
264+ tools,
265+ } ) ,
266+ )
267+ expect ( mockCreate ) . toHaveBeenCalledWith ( expect . objectContaining ( { tools } ) , expect . anything ( ) )
268+ } )
269+
174270 it . each ( [
175271 [ "max" , "max" ] ,
176272 [ "none" , "medium" ] ,
0 commit comments