@@ -491,7 +491,8 @@ test("Gemini tool schema is transformed but canonical numeric enum remains autho
491491test ( "prose-only finish is a counted corrective attempt before a valid result" , async ( ) => {
492492 const result = await run ( [ "prose" , '{"result":"repaired"}' ] , 1 )
493493 expect ( result . requests ) . toHaveLength ( 2 )
494- result . requests . forEach ( ( request ) => expect ( request . tool_choice ) . toBe ( "required" ) )
494+ expect ( result . requests [ 0 ] . tool_choice ) . toBe ( "required" )
495+ expect ( result . requests [ 1 ] . tool_choice ) . toEqual ( { type : "function" , function : { name : "StructuredOutput" } } )
495496 expect ( result . info . structured ) . toEqual ( { result : "repaired" } )
496497 expect ( result . info . error ) . toBeUndefined ( )
497498 expect ( result . rejected ) . toEqual ( [
@@ -678,3 +679,24 @@ test("every parallel rejection is counted after the corrective budget is spent",
678679 ] )
679680 expect ( result . outcomes ) . toEqual ( [ { status : "failed" , reason : "exhausted" , attempts : 3 } ] )
680681} )
682+
683+ test ( "provider tool description includes canonical pattern constraints" , async ( ) => {
684+ const canonical = {
685+ type : "object" ,
686+ properties : { result : { type : "string" , pattern : "^OK-[0-9]{4}$" } } ,
687+ required : [ "result" ] ,
688+ additionalProperties : false ,
689+ }
690+ const result = await run ( [ '{"result":"OK-1234"}' ] , 0 , { schema : canonical , gemini : true } )
691+ const tools = result . requests [ 0 ] . tools as { function : { name : string ; description : string } } [ ]
692+ expect ( tools . find ( ( tool ) => tool . function . name === "StructuredOutput" ) ?. function . description ) . toContain (
693+ JSON . stringify ( canonical ) ,
694+ )
695+ } )
696+
697+ test ( "tool description caps the canonical schema at 8 KiB and explains truncation" , ( ) => {
698+ const canonical = { type : "object" , description : "x" . repeat ( 9 * 1024 ) }
699+ const tool = SessionPrompt . createStructuredOutputTool ( { schema : canonical , onSuccess ( ) { } } )
700+ expect ( tool . description ) . toContain ( "truncated; the validator enforces the full schema" )
701+ expect ( tool . description ?. split ( ": " ) . at ( - 1 ) ) . toBe ( JSON . stringify ( canonical ) . slice ( 0 , 8 * 1024 ) )
702+ } )
0 commit comments