4646
4747def _build_test_params ():
4848 actions = [
49- {"action" : "ALLOW" , "reason" : "Go ahead" },
50- {"action" : "DENY" , "reason" : "Nope" },
51- {"action" : "ABORT" , "reason" : "Kill it with fire" },
49+ {"action" : "ALLOW" , "reason" : "Go ahead" , "tags" : [] },
50+ {"action" : "DENY" , "reason" : "Nope" , "tags" : [ "deny_everything" , "test_deny" ] },
51+ {"action" : "ABORT" , "reason" : "Kill it with fire" , "tags" : [ "alarm_tag" , "abort_everything" ] },
5252 ]
5353 block = [True , False ]
5454 suites = [
@@ -63,6 +63,7 @@ def _build_test_params():
6363 pytest .param (
6464 action ["action" ],
6565 action ["reason" ],
66+ action ["tags" ],
6667 block ,
6768 suite ["suite" ],
6869 suite ["target" ],
@@ -78,14 +79,24 @@ def assert_telemetry(mocked, metric, tags):
7879 assert ("count" , "appsec" , metric , 1 , tags ) in metrics
7980
8081
81- @pytest .mark .parametrize ("action,reason,blocking,suite,target,messages" , _build_test_params ())
82+ @pytest .mark .parametrize ("action,reason,tags, blocking,suite,target,messages" , _build_test_params ())
8283@patch ("ddtrace.internal.telemetry.telemetry_writer._namespace" )
8384@patch ("ddtrace.appsec.ai_guard._api_client.AIGuardClient._execute_request" )
8485def test_evaluate_method (
85- mock_execute_request , telemetry_mock , ai_guard_client , tracer , action , reason , blocking , suite , target , messages
86+ mock_execute_request ,
87+ telemetry_mock ,
88+ ai_guard_client ,
89+ tracer ,
90+ action ,
91+ reason ,
92+ tags ,
93+ blocking ,
94+ suite ,
95+ target ,
96+ messages ,
8697):
8798 """Test different combinations of evaluations."""
88- mock_execute_request .return_value = mock_evaluate_response (action , reason , blocking )
99+ mock_execute_request .return_value = mock_evaluate_response (action , reason , tags , blocking )
89100 should_block = blocking and action != "ALLOW"
90101
91102 if should_block :
@@ -103,6 +114,8 @@ def test_evaluate_method(
103114 expected_tags .update ({"ai_guard.tool_name" : "calc" })
104115 if action != "ALLOW" and blocking :
105116 expected_tags .update ({"ai_guard.blocked" : "true" })
117+ for tag in tags :
118+ expected_tags .update ({"ai_guard.tag." + tag : "true" })
106119 assert_ai_guard_span (
107120 tracer ,
108121 messages ,
0 commit comments