30
30
from f5_ai_gateway_sdk .processor import Tags
31
31
from f5_ai_gateway_sdk .request_input import Message , RequestInput
32
32
from f5_ai_gateway_sdk .response_output import Choice , ResponseOutput
33
- from f5_ai_gateway_sdk .result import Result
34
33
35
34
from ..libs .exceptions import TestTypeError
36
35
from ..libs .fakes import processors as fake_processors
@@ -79,22 +78,22 @@ def test_multipart_fields_breaking_change():
79
78
f"breaking change detected: { encoded_field } change from { expected_metadata_name } "
80
79
)
81
80
assert (encoded_fields := multipart_fields .INPUT_NAME ) == expected_prompt_name , (
82
- f"breaking change detected: { encoded_fields } change from { expected_optional_multipart_fields } "
81
+ f"breaking change detected: { encoded_fields } change from { expected_prompt_name } "
83
82
)
84
83
assert (
85
84
encoded_field := multipart_fields .INPUT_PARAMETERS_NAME
86
85
) == expected_prompt_parameters_name , (
87
- f"breaking change detected: { encoded_field } change from { expected_prompt_name } "
86
+ f"breaking change detected: { encoded_field } change from { expected_prompt_parameters_name } "
88
87
)
89
88
assert (
90
89
encoded_field := multipart_fields .RESPONSE_NAME
91
90
) == expected_response_name , (
92
- f"breaking change detected: { encoded_field } change from { expected_prompt_name } "
91
+ f"breaking change detected: { encoded_field } change from { expected_response_name } "
93
92
)
94
93
assert (
95
94
encoded_field := multipart_fields .RESPONSE_PARAMETERS_NAME
96
95
) == expected_response_parameters_name , (
97
- f"breaking change detected: { encoded_field } change from { expected_prompt_name } "
96
+ f"breaking change detected: { encoded_field } change from { expected_response_parameters_name } "
98
97
)
99
98
# - validate required versus optional field definitions; order not super important
100
99
assert (expected := set (expected_required_multipart_fields )) == (
@@ -109,7 +108,7 @@ def test_multipart_fields_breaking_change():
109
108
def test_processor_response_parameters_a_prompt_mismatch (
110
109
data_loader , processor_client_loader , test_logger , judgy_class
111
110
):
112
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
111
+ """Verify that response parameters cannot be present with only an input field ."""
113
112
expected_message = (
114
113
f"response parameters cannot be present with only a { INPUT_NAME } field"
115
114
)
@@ -159,7 +158,7 @@ def test_processor_response_parameters_a_prompt_mismatch(
159
158
def test_processor_overload_both_parameters (
160
159
data_loader , processor_client_loader , test_logger , judgy_class
161
160
):
162
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
161
+ """Verify that providing both input and response parameters generates an error ."""
163
162
expected_message = (
164
163
f"response parameters cannot be present with only a { INPUT_NAME } field"
165
164
)
@@ -171,7 +170,9 @@ def test_processor_overload_both_parameters(
171
170
test_logger .info (f"given: processor with path: { PROCESSOR_PATH } " )
172
171
judgy = fake_judgy (judgy_class )
173
172
174
- test_logger .info ("when: client requests a post with no prompt" )
173
+ test_logger .info (
174
+ "when: client requests a post with both input and response parameters"
175
+ )
175
176
client = processor_client_loader (judgy )
176
177
data = build_processor_prompt_content (
177
178
data_loader ,
@@ -211,7 +212,7 @@ def test_processor_overload_both_parameters(
211
212
def test_processor_500_raising (
212
213
data_loader , processor_client_loader , test_logger , judgy_class
213
214
):
214
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
215
+ """Verify that processor errors are properly handled and return a 500 status code ."""
215
216
expected_response = """{"detail": "problem executing processor implementation"}"""
216
217
expected_status_code = http_status_codes .HTTP_500_INTERNAL_SERVER_ERROR
217
218
@@ -223,7 +224,9 @@ def test_processor_500_raising(
223
224
http_status_codes .HTTP_500_INTERNAL_SERVER_ERROR , "fool of the fools"
224
225
)
225
226
226
- test_logger .info ("when: client requests a post with no prompt" )
227
+ test_logger .info (
228
+ "when: client requests a post with a prompt that causes processor to raise an error"
229
+ )
227
230
client = processor_client_loader (judgy )
228
231
data = build_processor_prompt_content (
229
232
data_loader ,
@@ -261,7 +264,7 @@ def test_processor_500_raising(
261
264
def test_processor_returns_none (
262
265
data_loader , processor_client_loader , test_logger , judgy_class
263
266
):
264
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
267
+ """Verify that processors returning None are handled properly with appropriate error messages ."""
265
268
266
269
if judgy_class .uses_process_method ():
267
270
@@ -296,7 +299,9 @@ def process_response(*_, **__):
296
299
)
297
300
judgy .raise_error = TypeError ("fool of the fools" )
298
301
299
- test_logger .info ("when: client requests a post with no prompt" )
302
+ test_logger .info (
303
+ "when: client requests a post with a prompt and processor returns None"
304
+ )
300
305
client = processor_client_loader (judgy )
301
306
data = build_processor_prompt_content (
302
307
data_loader ,
@@ -333,7 +338,7 @@ def process_response(*_, **__):
333
338
def test_processor_returns_bogus_class (
334
339
data_loader , processor_client_loader , test_logger , judgy_class
335
340
):
336
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
341
+ """Verify that processors returning invalid objects are handled properly with appropriate error messages ."""
337
342
338
343
class BogusClass :
339
344
rejected = False
@@ -374,7 +379,9 @@ def process_input(*_, **__):
374
379
)
375
380
judgy .raise_error = TypeError ("fool of the fools" )
376
381
377
- test_logger .info ("when: client requests a post with no prompt" )
382
+ test_logger .info (
383
+ "when: client requests a post with a prompt and processor returns invalid object"
384
+ )
378
385
client = processor_client_loader (judgy )
379
386
data = build_processor_prompt_content (
380
387
data_loader ,
@@ -426,7 +433,9 @@ def test_raising_processor(
426
433
)
427
434
judgy .raise_error = TypeError ("fool of the fools" )
428
435
429
- test_logger .info ("when: client requests a post with no prompt" )
436
+ test_logger .info (
437
+ "when: client requests a post with a prompt that causes processor to raise an error"
438
+ )
430
439
client = processor_client_loader (judgy )
431
440
data = build_processor_prompt_content (
432
441
data_loader ,
@@ -512,7 +521,7 @@ def test_request_no_prompt(
512
521
def test_request_null_parameters (
513
522
data_loader , processor_client_loader , test_logger , judgy_class
514
523
):
515
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
524
+ """Verify that null parameters are properly validated and rejected ."""
516
525
expected_response = """{"detail": "invalid parameters submitted", "messages": ["Input should be an object"]}"""
517
526
expected_status_code = http_status_codes .HTTP_400_BAD_REQUEST
518
527
@@ -526,7 +535,7 @@ def test_request_null_parameters(
526
535
parameters_class = fake_processors .JudgyParameters ,
527
536
)
528
537
529
- test_logger .info ("when: client requests a post with no prompt " )
538
+ test_logger .info ("when: client requests a post with null parameters " )
530
539
client = processor_client_loader (judgy )
531
540
data = build_processor_prompt_content (
532
541
data_loader ,
@@ -561,7 +570,7 @@ def test_request_null_parameters(
561
570
def test_request_empty_metadata (
562
571
data_loader , processor_client_loader , test_logger , judgy_class
563
572
):
564
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
573
+ """Verify that empty metadata is properly handled ."""
565
574
expected_response = '{"detail": "Unable to parse JSON field [metadata]: Expecting value: line 1 column 1 (char 0)"}'
566
575
expected_status_code = http_status_codes .HTTP_400_BAD_REQUEST
567
576
@@ -575,7 +584,7 @@ def test_request_empty_metadata(
575
584
parameters_class = fake_processors .JudgyParameters ,
576
585
)
577
586
578
- test_logger .info ("when: client requests a post with no prompt " )
587
+ test_logger .info ("when: client requests a post with empty metadata " )
579
588
client = processor_client_loader (judgy )
580
589
data = build_processor_prompt_content (
581
590
data_loader ,
@@ -611,7 +620,7 @@ def test_request_empty_metadata(
611
620
def test_request_invalid_metadata (
612
621
data_loader , processor_client_loader , test_logger , judgy_class
613
622
):
614
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
623
+ """Verify that invalid metadata format is properly rejected ."""
615
624
expected_response = """{"detail": "invalid metadata submitted"}"""
616
625
expected_status_code = http_status_codes .HTTP_400_BAD_REQUEST
617
626
@@ -625,7 +634,7 @@ def test_request_invalid_metadata(
625
634
parameters_class = fake_processors .JudgyParameters ,
626
635
)
627
636
628
- test_logger .info ("when: client requests a post with no prompt " )
637
+ test_logger .info ("when: client requests a post with invalid metadata " )
629
638
client = processor_client_loader (judgy )
630
639
data = build_processor_prompt_content (
631
640
data_loader ,
@@ -686,7 +695,7 @@ def test_request_invalid_metadata(
686
695
def test_request_string_metadata (
687
696
data_loader , processor_client_loader , test_logger , judgy_class
688
697
):
689
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
698
+ """Verify that string metadata (instead of JSON object) is properly rejected ."""
690
699
expected_response = """{"detail": "metadata must be a JSON object"}"""
691
700
expected_status_code = http_status_codes .HTTP_400_BAD_REQUEST
692
701
@@ -695,7 +704,7 @@ def test_request_string_metadata(
695
704
test_logger .info (f"given: processor with path: { PROCESSOR_PATH } " )
696
705
judgy = fake_judgy (judgy_class )
697
706
698
- test_logger .info ("when: client requests a post with no prompt " )
707
+ test_logger .info ("when: client requests a post with string metadata " )
699
708
client = processor_client_loader (judgy )
700
709
data = build_processor_prompt_content (
701
710
data_loader ,
@@ -849,7 +858,7 @@ def test_request_query_post_command_invalid_parameters(
849
858
def test_request_invalid_parameters (
850
859
data_loader , processor_client_loader , test_logger , judgy_class
851
860
):
852
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
861
+ """Verify that invalid parameters are properly validated and rejected ."""
853
862
expected_error = """{"detail": "invalid parameters submitted", "messages": ["Input should be a valid boolean: modified"]}"""
854
863
expected_status_code = http_status_codes .HTTP_400_BAD_REQUEST
855
864
@@ -863,7 +872,7 @@ def test_request_invalid_parameters(
863
872
parameters_class = fake_processors .JudgyParameters ,
864
873
)
865
874
866
- test_logger .info ("when: client requests a post with no prompt " )
875
+ test_logger .info ("when: client requests a post with invalid parameters " )
867
876
client = processor_client_loader (judgy )
868
877
parameters = data_loader ("judgy_parameters.yaml" )
869
878
parameters ["modified" ] = "Lucy in the sky with diamonds"
@@ -899,7 +908,7 @@ def test_request_invalid_parameters(
899
908
def test_request_required_parameters_missing (
900
909
data_loader , processor_client_loader , test_logger , judgy_class
901
910
):
902
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
911
+ """Verify that missing required parameters are properly validated and rejected ."""
903
912
expected_error = """{"detail": "invalid parameters submitted", "messages": ["Field required: required_message"]}"""
904
913
expected_invalid_status_code = http_status_codes .HTTP_400_BAD_REQUEST
905
914
method = "post"
@@ -948,7 +957,7 @@ def test_request_required_parameters_missing(
948
957
def test_request_required_parameters_present (
949
958
data_loader , processor_client_loader , test_logger , judgy_class
950
959
):
951
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
960
+ """Verify that requests with required parameters present are handled correctly ."""
952
961
expected_valid_status_code = http_status_codes .HTTP_400_BAD_REQUEST
953
962
method = "post"
954
963
@@ -1028,7 +1037,7 @@ def test_request_required_metadata_response_fields(
1028
1037
def test_request_required_parameters_missing_multipart (
1029
1038
data_loader , processor_client_loader , test_logger , judgy_class
1030
1039
):
1031
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
1040
+ """Verify that missing required parameters in multipart requests are properly validated and rejected ."""
1032
1041
expected_error = """{"detail": "invalid parameters submitted", "messages": ["Field required: required_message"]}"""
1033
1042
expected_valid_status_code = http_status_codes .HTTP_400_BAD_REQUEST
1034
1043
method = "post"
@@ -1072,45 +1081,16 @@ def test_request_required_parameters_missing_multipart(
1072
1081
def test_modification_with_reject (
1073
1082
data_loader , processor_client_loader , test_logger , judgy_class
1074
1083
):
1075
- """Verify that with a stood up processor that the request will reject a request with no prompt ."""
1076
- expected_valid_status_code = http_status_codes .HTTP_400_BAD_REQUEST
1084
+ """Verify that processors allow modify and reject to be set at once ."""
1085
+ expected_valid_status_code = http_status_codes .HTTP_200_OK
1077
1086
method = "post"
1078
1087
1079
- if judgy_class .uses_process_method ():
1080
-
1081
- class ModifyAndRejectProcessor (judgy_class ):
1082
- def process (* _ , ** __ ):
1083
- """Return None as a matter of existence."""
1084
- return Result (
1085
- modified_prompt = RequestInput (
1086
- messages = [Message (content = "foo-input" )]
1087
- ),
1088
- modified_response = ResponseOutput (
1089
- choices = [Choice (message = Message (content = "bar-output" ))]
1090
- ),
1091
- )
1092
- else :
1093
-
1094
- class ModifyAndRejectProcessor (judgy_class ):
1095
- def process_input (* _ , ** __ ):
1096
- """Return None as a matter of existence."""
1097
- return Result (
1098
- modified_prompt = RequestInput (
1099
- messages = [Message (content = "foo-input" )]
1100
- ),
1101
- modified_response = ResponseOutput (
1102
- choices = [Choice (message = Message (content = "bar-output" ))]
1103
- ),
1104
- )
1105
-
1106
- test_logger .info (f"given: processor with path: { PROCESSOR_PATH } " )
1107
- judgy = ModifyAndRejectProcessor (
1088
+ judgy = judgy_class (
1108
1089
PROCESSOR_NAME ,
1109
1090
PROCESSOR_VERSION ,
1110
1091
PROCESSOR_NAMESPACE ,
1092
+ parameters_class = fake_processors .JudgyParameters ,
1111
1093
)
1112
-
1113
- test_logger .info ("when: client requests a post without a required parameter" )
1114
1094
client = processor_client_loader (judgy )
1115
1095
data = build_processor_prompt_content (
1116
1096
data_loader ,
@@ -1134,7 +1114,6 @@ def process_input(*_, **__):
1134
1114
assert response .status_code == expected_valid_status_code , (
1135
1115
f"({ response .status_code } != { expected_valid_status_code } ) from { method } ({ PROCESSOR_PATH } ): { content } "
1136
1116
)
1137
- assert "mutually exclusive" in response .text
1138
1117
1139
1118
1140
1119
@pytest .mark .parametrize ("judgy_class" , TEST_PROCESSORS )
@@ -1147,7 +1126,7 @@ def test_get_signature_definition(
1147
1126
1148
1127
test_logger .info (f"given: processor with path: { SIGNATURE_PATH } " )
1149
1128
judgy = fake_judgy (judgy_class )
1150
- test_logger .info ("when: client requests a post with no prompt " )
1129
+ test_logger .info ("when: client requests signature definition " )
1151
1130
client = processor_client_loader (judgy )
1152
1131
request = client .build_request (
1153
1132
url = SIGNATURE_PATH , method = method , headers = {"Accept" : "application/json" }
0 commit comments