@@ -190,7 +190,7 @@ describe("safe_outputs_tools_loader", () => {
190190 expect ( defaultHandler ) . toHaveBeenCalledWith ( "dispatch_workflow" ) ;
191191 } ) ;
192192
193- it ( "should include workflow_name in dispatch_workflow handler args " , ( ) => {
193+ it ( "should wrap args in inputs property for dispatch_workflow handler" , ( ) => {
194194 const tools = [ { name : "ci_workflow" , description : "CI workflow" , _workflow_name : "ci" } ] ;
195195 const mockHandlerFunction = vi . fn ( ) ;
196196 const defaultHandler = vi . fn ( ( ) => mockHandlerFunction ) ;
@@ -204,16 +204,63 @@ describe("safe_outputs_tools_loader", () => {
204204 const result = attachHandlers ( tools , handlers ) ;
205205
206206 // Call the handler
207- const mockArgs = { input1 : "value1" } ;
207+ const mockArgs = { input1 : "value1" , input2 : "value2" } ;
208208 result [ 0 ] . handler ( mockArgs ) ;
209209
210- // Verify the handler function was called with workflow_name
211- expect ( mockHandlerFunction ) . toHaveBeenCalledWith (
212- expect . objectContaining ( {
213- workflow_name : "ci" ,
210+ // Verify the handler function was called with workflow_name and inputs wrapped
211+ expect ( mockHandlerFunction ) . toHaveBeenCalledWith ( {
212+ workflow_name : "ci" ,
213+ inputs : {
214214 input1 : "value1" ,
215- } )
216- ) ;
215+ input2 : "value2" ,
216+ } ,
217+ } ) ;
218+ } ) ;
219+
220+ it ( "should handle dispatch_workflow with no inputs (empty object)" , ( ) => {
221+ const tools = [ { name : "no_inputs_workflow" , description : "No inputs workflow" , _workflow_name : "no-inputs" } ] ;
222+ const mockHandlerFunction = vi . fn ( ) ;
223+ const defaultHandler = vi . fn ( ( ) => mockHandlerFunction ) ;
224+ const handlers = {
225+ createPullRequestHandler : vi . fn ( ) ,
226+ pushToPullRequestBranchHandler : vi . fn ( ) ,
227+ uploadAssetHandler : vi . fn ( ) ,
228+ defaultHandler : defaultHandler ,
229+ } ;
230+
231+ const result = attachHandlers ( tools , handlers ) ;
232+
233+ // Call the handler with empty object (typical for MCP tools with no inputs)
234+ result [ 0 ] . handler ( { } ) ;
235+
236+ // Verify inputs is still included as empty object
237+ expect ( mockHandlerFunction ) . toHaveBeenCalledWith ( {
238+ workflow_name : "no-inputs" ,
239+ inputs : { } ,
240+ } ) ;
241+ } ) ;
242+
243+ it ( "should handle dispatch_workflow with undefined args" , ( ) => {
244+ const tools = [ { name : "undefined_workflow" , description : "Undefined workflow" , _workflow_name : "undefined-test" } ] ;
245+ const mockHandlerFunction = vi . fn ( ) ;
246+ const defaultHandler = vi . fn ( ( ) => mockHandlerFunction ) ;
247+ const handlers = {
248+ createPullRequestHandler : vi . fn ( ) ,
249+ pushToPullRequestBranchHandler : vi . fn ( ) ,
250+ uploadAssetHandler : vi . fn ( ) ,
251+ defaultHandler : defaultHandler ,
252+ } ;
253+
254+ const result = attachHandlers ( tools , handlers ) ;
255+
256+ // Call the handler with undefined (edge case)
257+ result [ 0 ] . handler ( undefined ) ;
258+
259+ // When args is undefined, inputs should not be included
260+ // The dispatch_workflow handler will handle missing inputs property
261+ expect ( mockHandlerFunction ) . toHaveBeenCalledWith ( {
262+ workflow_name : "undefined-test" ,
263+ } ) ;
217264 } ) ;
218265 } ) ;
219266
0 commit comments