@@ -52,49 +52,6 @@ def test_interaction_set_expected_output_instantiation():
52
52
assert interaction_set .expected_output [0 ].policy == "test_policy"
53
53
54
54
55
- def test_eval_config_policy_validation_valid ():
56
- """Test that policy validation works correctly."""
57
-
58
- config = EvalConfig .model_validate (
59
- {
60
- "policies" : [{"id" : "policy1" , "description" : "Test policy" }],
61
- "interactions" : [
62
- {
63
- "id" : "test_id" ,
64
- "inputs" : ["test input" ],
65
- "expected_output" : [{"type" : "string" , "policy" : "policy1" }],
66
- }
67
- ],
68
- }
69
- )
70
- assert len (config .policies ) == 1
71
- assert len (config .interactions ) == 1
72
-
73
-
74
- def test_eval_config_policy_validation_invalid_policy_not_found ():
75
- # invalid case, policy not found
76
- with pytest .raises (
77
- ValueError , match = "Invalid policy id policy2 used in interaction set"
78
- ):
79
- EvalConfig .model_validate (
80
- {
81
- "policies" : [{"id" : "policy1" , "description" : "Test policy" }],
82
- "interactions" : [
83
- {
84
- "id" : "test_id" ,
85
- "inputs" : ["test input" ],
86
- "expected_output" : [
87
- {
88
- "type" : "string" ,
89
- "policy" : "policy2" ,
90
- }
91
- ],
92
- }
93
- ],
94
- }
95
- )
96
-
97
-
98
55
def test_eval_config_from_path ():
99
56
"""Test loading config from path."""
100
57
@@ -268,3 +225,118 @@ def test_expected_output_missing_field():
268
225
ExpectedOutput (
269
226
type = "refusal" ,
270
227
)
228
+
229
+
230
+ def test_eval_config_policy_validation_valid ():
231
+ """Test that policy validation works correctly."""
232
+
233
+ config = EvalConfig .model_validate (
234
+ {
235
+ "policies" : [{"id" : "policy1" , "description" : "Test policy" }],
236
+ "interactions" : [
237
+ {
238
+ "id" : "test_id" ,
239
+ "inputs" : ["test input" ],
240
+ "expected_output" : [{"type" : "string" , "policy" : "policy1" }],
241
+ }
242
+ ],
243
+ }
244
+ )
245
+ assert len (config .policies ) == 1
246
+ assert len (config .interactions ) == 1
247
+
248
+
249
+ def test_eval_config_policy_validation_invalid_policy_not_found ():
250
+ # invalid case, policy not found
251
+ with pytest .raises (
252
+ ValueError , match = "Invalid policy id policy2 used in interaction set"
253
+ ):
254
+ EvalConfig .model_validate (
255
+ {
256
+ "policies" : [{"id" : "policy1" , "description" : "Test policy" }],
257
+ "interactions" : [
258
+ {
259
+ "id" : "test_id" ,
260
+ "inputs" : ["test input" ],
261
+ "expected_output" : [
262
+ {
263
+ "type" : "string" ,
264
+ "policy" : "policy2" ,
265
+ }
266
+ ],
267
+ }
268
+ ],
269
+ }
270
+ )
271
+
272
+
273
+ def test_eval_config_policy_validation_multiple_interactions ():
274
+ """Test that policy validation works with multiple interactions."""
275
+ config = EvalConfig .model_validate (
276
+ {
277
+ "policies" : [{"id" : "policy1" , "description" : "Test policy" }],
278
+ "interactions" : [
279
+ {
280
+ "id" : "test_id1" ,
281
+ "inputs" : ["test input 1" ],
282
+ "expected_output" : [{"type" : "string" , "policy" : "policy1" }],
283
+ },
284
+ {
285
+ "id" : "test_id2" ,
286
+ "inputs" : ["test input 2" ],
287
+ "expected_output" : [{"type" : "string" , "policy" : "policy1" }],
288
+ },
289
+ ],
290
+ }
291
+ )
292
+ assert len (config .interactions ) == 2
293
+
294
+
295
+ def test_eval_config_policy_validation_multiple_policies ():
296
+ """Test that policy validation works with multiple policies."""
297
+ config = EvalConfig .model_validate (
298
+ {
299
+ "policies" : [
300
+ {"id" : "policy1" , "description" : "Test policy 1" },
301
+ {"id" : "policy2" , "description" : "Test policy 2" },
302
+ ],
303
+ "interactions" : [
304
+ {
305
+ "id" : "test_id" ,
306
+ "inputs" : ["test input" ],
307
+ "expected_output" : [
308
+ {"type" : "string" , "policy" : "policy1" },
309
+ {"type" : "string" , "policy" : "policy2" },
310
+ ],
311
+ }
312
+ ],
313
+ }
314
+ )
315
+ assert len (config .policies ) == 2
316
+ assert len (config .interactions [0 ].expected_output ) == 2
317
+
318
+
319
+ def test_eval_config_policy_validation_duplicate_policy_ids ():
320
+ """Test that duplicate policy IDs are handled.
321
+
322
+ Note: The model currently doesn't validate for duplicate policy IDs.
323
+ This test should be updated if duplicate policy ID validation is added.
324
+ """
325
+ config = EvalConfig .model_validate (
326
+ {
327
+ "policies" : [
328
+ {"id" : "policy1" , "description" : "Test policy 1" },
329
+ {"id" : "policy1" , "description" : "Test policy 2" },
330
+ ],
331
+ "interactions" : [
332
+ {
333
+ "id" : "test_id" ,
334
+ "inputs" : ["test input" ],
335
+ "expected_output" : [{"type" : "string" , "policy" : "policy1" }],
336
+ }
337
+ ],
338
+ }
339
+ )
340
+ assert len (config .policies ) == 2
341
+ assert config .policies [0 ].id == "policy1"
342
+ assert config .policies [1 ].id == "policy1"
0 commit comments