@@ -189,3 +189,69 @@ describe("google adapter — tool-call ids on the wire", () => {
189189 expect ( fc ) . toBe ( "call_xyz" ) ;
190190 } ) ;
191191} ) ;
192+
193+ describe ( "google adapter — tool_choice on the wire" , ( ) => {
194+ const TOOLS = [
195+ { name : "get_weather" , parameters : { type : "object" , properties : { } } } ,
196+ { name : "shot" , namespace : "mcp__chrome" , parameters : { type : "object" , properties : { } } } ,
197+ ] ;
198+
199+ function parsedWithChoice ( toolChoice : unknown , tools : unknown [ ] | null = TOOLS ) : OcxParsedRequest {
200+ return {
201+ modelId : "gemini-3-pro" ,
202+ stream : false ,
203+ options : toolChoice === undefined ? { } : { toolChoice } ,
204+ context : { messages : [ { role : "user" , content : "hi" } ] , tools : tools ?? undefined } ,
205+ } as unknown as OcxParsedRequest ;
206+ }
207+
208+ test ( '"none" and "required" map to NONE and ANY' , async ( ) => {
209+ expect ( ( await geminiBody ( parsedWithChoice ( "none" ) ) ) . toolConfig )
210+ . toEqual ( { functionCallingConfig : { mode : "NONE" } } ) ;
211+ expect ( ( await geminiBody ( parsedWithChoice ( "required" ) ) ) . toolConfig )
212+ . toEqual ( { functionCallingConfig : { mode : "ANY" } } ) ;
213+ } ) ;
214+
215+ test ( "a forced tool maps to ANY with its wire name allowed" , async ( ) => {
216+ expect ( ( await geminiBody ( parsedWithChoice ( { name : "get_weather" } ) ) ) . toolConfig )
217+ . toEqual ( { functionCallingConfig : { mode : "ANY" , allowedFunctionNames : [ "get_weather" ] } } ) ;
218+ // Dotted alias resolves to the namespaced declaration name.
219+ expect ( ( await geminiBody ( parsedWithChoice ( { name : "mcp__chrome.shot" } ) ) ) . toolConfig )
220+ . toEqual ( { functionCallingConfig : { mode : "ANY" , allowedFunctionNames : [ "mcp__chrome__shot" ] } } ) ;
221+ } ) ;
222+
223+ test ( '"auto", absent, and allowedTools+auto stay byte-identical (no toolConfig)' , async ( ) => {
224+ expect ( ( await geminiBody ( parsedWithChoice ( "auto" ) ) ) . toolConfig ) . toBeUndefined ( ) ;
225+ expect ( ( await geminiBody ( parsedWithChoice ( undefined ) ) ) . toolConfig ) . toBeUndefined ( ) ;
226+ expect ( ( await geminiBody ( parsedWithChoice ( { allowedTools : [ "get_weather" ] , mode : "auto" } ) ) ) . toolConfig ) . toBeUndefined ( ) ;
227+ } ) ;
228+
229+ test ( "allowedTools with mode required keeps the filtered catalog and adds ANY" , async ( ) => {
230+ const body = await geminiBody ( parsedWithChoice ( { allowedTools : [ "get_weather" ] , mode : "required" } ) ) ;
231+ const declared = ( body . tools as { functionDeclarations : { name : string } [ ] } [ ] ) [ 0 ] . functionDeclarations . map ( d => d . name ) ;
232+ expect ( declared ) . toEqual ( [ "get_weather" ] ) ;
233+ expect ( body . toolConfig ) . toEqual ( { functionCallingConfig : { mode : "ANY" } } ) ;
234+ } ) ;
235+
236+ test ( "no declared tools means no toolConfig even with a choice" , async ( ) => {
237+ expect ( ( await geminiBody ( parsedWithChoice ( "none" , null ) ) ) . toolConfig ) . toBeUndefined ( ) ;
238+ expect ( ( await geminiBody ( parsedWithChoice ( { name : "get_weather" } , [ ] ) ) ) . toolConfig ) . toBeUndefined ( ) ;
239+ } ) ;
240+
241+ test ( "claude-on-antigravity keeps VALIDATED mode over a client choice, allowed names survive" , async ( ) => {
242+ const ccaProvider = {
243+ adapter : "google" ,
244+ googleMode : "cloud-code-assist" ,
245+ baseUrl : "https://daily-cloudcode-pa.googleapis.com" ,
246+ apiKey : "key" ,
247+ project : "proj-123" ,
248+ } ;
249+ const parsed = parsedWithChoice ( { name : "get_weather" } ) ;
250+ ( parsed as unknown as { modelId : string } ) . modelId = "claude-opus-4.8" ;
251+ const { body } = await createGoogleAdapter ( ccaProvider ) . buildRequest ( parsed ) ;
252+ const request = JSON . parse ( body ) . request as Record < string , unknown > ;
253+ expect ( request . toolConfig ) . toEqual ( {
254+ functionCallingConfig : { mode : "VALIDATED" , allowedFunctionNames : [ "get_weather" ] } ,
255+ } ) ;
256+ } ) ;
257+ } ) ;
0 commit comments