10
10
from f5_ai_gateway_sdk .request_input import RequestInput
11
11
from f5_ai_gateway_sdk .response_output import ResponseOutput
12
12
from f5_ai_gateway_sdk .result import Result
13
+ from f5_ai_gateway_sdk .tags import Tags
13
14
14
15
15
16
def test_prompt_not_allowed_with_response ():
@@ -22,3 +23,62 @@ def test_prompt_not_allowed_with_response():
22
23
modified_prompt = RequestInput (messages = []),
23
24
modified_response = ResponseOutput (choices = []),
24
25
)
26
+
27
+
28
+ @pytest .mark .parametrize (
29
+ "name,annotate,modify,result,expected_log" ,
30
+ [
31
+ (
32
+ "Annotate not allowed" ,
33
+ False ,
34
+ False ,
35
+ Result (tags = Tags ({"test" : ["value" ]})),
36
+ "test_processor tried to annotate request with tags when parameters.annotate was set to false, tags will be dropped" ,
37
+ ),
38
+ ("Treat empty Tags as no annotate" , False , False , Result (tags = Tags ()), "" ),
39
+ (
40
+ "Modify not allowed for prompt" ,
41
+ True ,
42
+ False ,
43
+ Result (modified_prompt = RequestInput (messages = [])),
44
+ "test_processor tried to modify request when parameters.modify was set to false, modification will be dropped" ,
45
+ ),
46
+ (
47
+ "Modify not allowed for response" ,
48
+ True ,
49
+ False ,
50
+ Result (modified_response = ResponseOutput (choices = [])),
51
+ "test_processor tried to modify request when parameters.modify was set to false, modification will be dropped" ,
52
+ ),
53
+ (
54
+ "Modify allowed" ,
55
+ False ,
56
+ True ,
57
+ Result (modified_response = ResponseOutput (choices = [])),
58
+ "" ,
59
+ ),
60
+ (
61
+ "Annotate allowed" ,
62
+ True ,
63
+ True ,
64
+ Result (tags = Tags (), modified_prompt = RequestInput (messages = [])),
65
+ "" ,
66
+ ),
67
+ ],
68
+ ids = lambda name : name ,
69
+ )
70
+ def test_validate_not_allowed_parameters (
71
+ caplog , name , annotate : bool , modify : bool , result : Result , expected_log
72
+ ):
73
+ """Test validate_allowed drops modifications or tags which have not been approved."""
74
+ result .validate_allowed ("test_processor" , annotate , modify )
75
+
76
+ if expected_log :
77
+ assert expected_log in caplog .text
78
+ else :
79
+ assert len (caplog .records ) == 0
80
+ if not annotate :
81
+ assert not bool (result .tags )
82
+ if not modify :
83
+ assert result .modified_prompt is None
84
+ assert result .modified_response is None
0 commit comments