@@ -225,13 +225,15 @@ async function runSchemaToolCall(params: {
225225 name ?: string ;
226226 namespace ?: SchemaToolNamespace ;
227227 parameters ?: AnyAgentTool [ "parameters" ] ;
228+ prepareArguments ?: AnyAgentTool [ "prepareArguments" ] ;
228229} ) {
229230 const name = params . name ?? "strict_tool" ;
230231 const namespace = params . namespace ?? null ;
231232 const execute = vi . fn ( async ( ) => textToolResult ( "done" ) ) ;
232233 const tool = createTool ( {
233234 name,
234235 parameters : params . parameters ?? STRICT_INSTRUCTION_SCHEMA ,
236+ prepareArguments : params . prepareArguments ,
235237 execute,
236238 } ) ;
237239 const bridge = createCodexDynamicToolBridge ( {
@@ -339,31 +341,38 @@ describe("createCodexDynamicToolBridge", () => {
339341 expect ( ( contentItem . text as string ) . length ) . toBeLessThanOrEqual ( 260 ) ;
340342 } ) ;
341343
342- it . each ( [
343- { label : "number" , arguments : 47 } ,
344- { label : "string" , arguments : "unexpected" } ,
345- { label : "array" , arguments : [ ] } ,
346- { label : "null" , arguments : null } ,
347- ] ) (
348- "rejects a $label root before optional-only object arguments are normalized" ,
349- async ( testCase ) => {
350- const { execute, response } = await runSchemaToolCall ( {
351- arguments : testCase . arguments as JsonValue ,
352- callId : `call-non-object-${ testCase . label } ` ,
353- name : "optional_object_tool" ,
354- parameters : {
355- type : "object" ,
356- properties : { note : { type : "string" } } ,
357- additionalProperties : false ,
358- } ,
359- namespace : CODEX_OPENCLAW_DIRECT_DYNAMIC_TOOL_NAMESPACE ,
360- } ) ;
344+ it ( "prepares raw null arguments before native Codex schema validation" , async ( ) => {
345+ const prepareArguments = vi . fn ( function ( this : AnyAgentTool , arguments_ : unknown ) {
346+ return arguments_ === null ? { preparedBy : this . name } : arguments_ ;
347+ } ) ;
348+ const { execute, response } = await runSchemaToolCall ( {
349+ arguments : null ,
350+ callId : "call-null-compatibility" ,
351+ name : "optional_object_tool" ,
352+ parameters : {
353+ type : "object" ,
354+ properties : { preparedBy : { type : "string" } } ,
355+ additionalProperties : false ,
356+ } ,
357+ prepareArguments,
358+ namespace : CODEX_OPENCLAW_DIRECT_DYNAMIC_TOOL_NAMESPACE ,
359+ } ) ;
361360
362- expectSchemaRejection ( response , execute , "must be object" ) ;
363- } ,
364- ) ;
361+ expect ( prepareArguments ) . toHaveBeenCalledWith ( null ) ;
362+ expect ( response ) . toEqual ( expectInputText ( "done" ) ) ;
363+ expectExecuteCall ( execute , {
364+ callId : "call-null-compatibility" ,
365+ args : { preparedBy : "optional_object_tool" } ,
366+ } ) ;
367+ } ) ;
365368
366369 it . each ( [
370+ {
371+ label : "repairs primitive input" ,
372+ initial : 47 ,
373+ adjusted : { instruction : "repaired" } ,
374+ executes : true ,
375+ } ,
367376 {
368377 label : "repairs invalid input" ,
369378 initial : { instruction : 47 } ,
0 commit comments