@@ -203,4 +203,101 @@ async def test_create_action_tool_with_complex_trigger(mock_client_with_create_a
203
203
assert result ["trigger" ]["operation" ] == "DAY-2"
204
204
assert result ["trigger" ]["blueprintIdentifier" ] == "service"
205
205
assert "userInputs" in result ["trigger" ]
206
- assert len (result ["trigger" ]["userInputs" ]["required" ]) == 2
206
+ assert len (result ["trigger" ]["userInputs" ]["required" ]) == 2
207
+
208
+
209
+ @pytest .mark .asyncio
210
+ async def test_create_action_tool_with_string_invocation_method (mock_client_with_create_action ):
211
+ """Test creating an action when invocationMethod is provided as a JSON string."""
212
+ from src .models .actions .action import ActionTrigger , ActionInvocationMethodWebhook
213
+ tool = CreateActionTool (mock_client_with_create_action )
214
+
215
+ # Mock return value with webhook invocation
216
+ mock_client_with_create_action .create_action .return_value = Action (
217
+ identifier = "string-invocation-action" ,
218
+ title = "String Invocation Action" ,
219
+ description = "Action with string invocation method" ,
220
+ trigger = ActionTrigger (
221
+ type = "self-service" ,
222
+ operation = "CREATE" ,
223
+ user_inputs = {"properties" : {}, "required" : []},
224
+ ),
225
+ invocation_method = ActionInvocationMethodWebhook (
226
+ type = "WEBHOOK" ,
227
+ url = "https://api.github.com/repos/test/test/issues" ,
228
+ method = "POST" ,
229
+ headers = {"Accept" : "application/vnd.github+json" },
230
+ body = {"title" : "{{ .inputs.title }}" , "body" : "{{ .inputs.body }}" }
231
+ ),
232
+ )
233
+
234
+ # Input data with invocationMethod as a JSON string (like Claude might provide)
235
+ input_data = {
236
+ "identifier" : "string-invocation-action" ,
237
+ "title" : "String Invocation Action" ,
238
+ "description" : "Action with string invocation method" ,
239
+ "trigger" : {
240
+ "type" : "self-service" ,
241
+ "operation" : "CREATE" ,
242
+ "userInputs" : {"properties" : {}, "required" : []},
243
+ },
244
+ "invocationMethod" : '{"type": "WEBHOOK", "url": "https://api.github.com/repos/test/test/issues", "method": "POST", "headers": {"Accept": "application/vnd.github+json"}, "body": {"title": "{{ .inputs.title }}", "body": "{{ .inputs.body }}"}}'
245
+ }
246
+
247
+ # This should work after our fix
248
+ result = await tool .create_action (tool .validate_input (input_data ))
249
+
250
+ # Verify the webhook-specific fields
251
+ assert result ["identifier" ] == "string-invocation-action"
252
+ assert result ["invocationMethod" ]["type" ] == "WEBHOOK"
253
+ assert result ["invocationMethod" ]["url" ] == "https://api.github.com/repos/test/test/issues"
254
+ assert result ["invocationMethod" ]["method" ] == "POST"
255
+ assert result ["invocationMethod" ]["headers" ]["Accept" ] == "application/vnd.github+json"
256
+
257
+
258
+ @pytest .mark .asyncio
259
+ async def test_create_action_tool_with_string_github_invocation_method (mock_client_with_create_action ):
260
+ """Test creating an action when GitHub invocationMethod is provided as a JSON string."""
261
+ from src .models .actions .action import ActionTrigger , ActionInvocationMethodGitHub
262
+ tool = CreateActionTool (mock_client_with_create_action )
263
+
264
+ # Mock return value with GitHub invocation
265
+ mock_client_with_create_action .create_action .return_value = Action (
266
+ identifier = "string-github-action" ,
267
+ title = "String GitHub Action" ,
268
+ description = "Action with string GitHub invocation method" ,
269
+ trigger = ActionTrigger (
270
+ type = "self-service" ,
271
+ operation = "CREATE" ,
272
+ user_inputs = {"properties" : {}, "required" : []},
273
+ ),
274
+ invocation_method = ActionInvocationMethodGitHub (
275
+ type = "GITHUB" ,
276
+ org = "test-org" ,
277
+ repo = "test-repo" ,
278
+ workflow = "test-workflow.yml"
279
+ ),
280
+ )
281
+
282
+ # Input data with GitHub invocationMethod as a JSON string
283
+ input_data = {
284
+ "identifier" : "string-github-action" ,
285
+ "title" : "String GitHub Action" ,
286
+ "description" : "Action with string GitHub invocation method" ,
287
+ "trigger" : {
288
+ "type" : "self-service" ,
289
+ "operation" : "CREATE" ,
290
+ "userInputs" : {"properties" : {}, "required" : []},
291
+ },
292
+ "invocationMethod" : '{"type": "GITHUB", "org": "test-org", "repo": "test-repo", "workflow": "test-workflow.yml"}'
293
+ }
294
+
295
+ # This should work after our fix
296
+ result = await tool .create_action (tool .validate_input (input_data ))
297
+
298
+ # Verify the GitHub-specific fields
299
+ assert result ["identifier" ] == "string-github-action"
300
+ assert result ["invocationMethod" ]["type" ] == "GITHUB"
301
+ assert result ["invocationMethod" ]["org" ] == "test-org"
302
+ assert result ["invocationMethod" ]["repo" ] == "test-repo"
303
+ assert result ["invocationMethod" ]["workflow" ] == "test-workflow.yml"
0 commit comments