33
44Tests custom scoring rules functionality.
55"""
6- import pytest
6+
77from acontext_core .llm .prompt .sop_customization import SOPPromptCustomization
88from acontext_core .llm .prompt .task_sop import TaskSOPPrompt
99from acontext_core .schema .config import CustomScoringRule , ProjectConfig
@@ -21,16 +21,14 @@ def test_build_custom_scoring_section_empty(self):
2121 def test_build_custom_scoring_section_normal (self ):
2222 """Test building custom scoring section with normal level rules"""
2323 rule1 = CustomScoringRule (
24- description = "If the task involves database operations" ,
25- level = "normal"
24+ description = "If the task involves database operations" , level = "normal"
2625 )
2726 rule2 = CustomScoringRule (
28- description = "If the task requires file I/O" ,
29- level = "normal"
27+ description = "If the task requires file I/O" , level = "normal"
3028 )
3129 customization = SOPPromptCustomization (custom_scoring_rules = [rule1 , rule2 ])
3230 result = customization .build_custom_scoring_section (start_index = 5 )
33-
31+
3432 assert "(c.5)" in result
3533 assert "(c.6)" in result
3634 assert "If the task involves database operations" in result
@@ -40,12 +38,11 @@ def test_build_custom_scoring_section_normal(self):
4038 def test_build_custom_scoring_section_critical (self ):
4139 """Test building custom scoring section with critical level rules"""
4240 rule = CustomScoringRule (
43- description = "If the task requires external API calls" ,
44- level = "critical"
41+ description = "If the task requires external API calls" , level = "critical"
4542 )
4643 customization = SOPPromptCustomization (custom_scoring_rules = [rule ])
4744 result = customization .build_custom_scoring_section (start_index = 5 )
48-
45+
4946 assert "(c.5)" in result
5047 assert "If the task requires external API calls" in result
5148 assert "+ 3 points" in result # critical level = 3 points
@@ -56,7 +53,7 @@ def test_build_custom_scoring_section_mixed(self):
5653 rule2 = CustomScoringRule (description = "Critical rule" , level = "critical" )
5754 customization = SOPPromptCustomization (custom_scoring_rules = [rule1 , rule2 ])
5855 result = customization .build_custom_scoring_section (start_index = 5 )
59-
56+
6057 assert "(c.5)" in result
6158 assert "(c.6)" in result
6259 assert "Normal rule" in result
@@ -76,7 +73,7 @@ def test_get_all_rule_indices_with_custom(self):
7673 rule2 = CustomScoringRule (description = "Rule 2" , level = "critical" )
7774 customization = SOPPromptCustomization (custom_scoring_rules = [rule1 , rule2 ])
7875 indices = customization .get_all_rule_indices (base_count = 4 )
79-
76+
8077 assert len (indices ) == 6
8178 assert indices == ["(c.1)" , "(c.2)" , "(c.3)" , "(c.4)" , "(c.5)" , "(c.6)" ]
8279
@@ -87,46 +84,44 @@ class TestTaskSOPPromptWithCustomization:
8784 def test_system_prompt_without_customization (self ):
8885 """Test system prompt generation without customization"""
8986 prompt = TaskSOPPrompt .system_prompt ()
90-
87+
9188 # Should contain base rules
9289 assert "(c.1)" in prompt
9390 assert "(c.2)" in prompt
9491 assert "(c.3)" in prompt
9592 assert "(c.4)" in prompt
96-
93+
9794 # Should not contain custom rules
9895 assert "(c.5)" not in prompt
99-
96+
10097 # Report section should reference base rules only
10198 assert "Give your judgement on (c.1), (c.2), (c.3), (c.4)" in prompt
10299
103100 def test_system_prompt_with_customization (self ):
104101 """Test system prompt generation with customization"""
105102 rule1 = CustomScoringRule (
106- description = "If the task involves database operations" ,
107- level = "normal"
103+ description = "If the task involves database operations" , level = "normal"
108104 )
109105 rule2 = CustomScoringRule (
110- description = "If the task requires external API calls" ,
111- level = "critical"
106+ description = "If the task requires external API calls" , level = "critical"
112107 )
113108 customization = SOPPromptCustomization (custom_scoring_rules = [rule1 , rule2 ])
114109 prompt = TaskSOPPrompt .system_prompt (customization = customization )
115-
110+
116111 # Should contain base rules
117112 assert "(c.1)" in prompt
118113 assert "(c.2)" in prompt
119114 assert "(c.3)" in prompt
120115 assert "(c.4)" in prompt
121-
116+
122117 # Should contain custom rules
123118 assert "(c.5)" in prompt
124119 assert "(c.6)" in prompt
125120 assert "If the task involves database operations" in prompt
126121 assert "If the task requires external API calls" in prompt
127122 assert "+ 1 point" in prompt # normal
128123 assert "+ 3 points" in prompt # critical
129-
124+
130125 # Report section should reference all rules
131126 assert "(c.5)" in prompt
132127 assert "(c.6)" in prompt
@@ -138,13 +133,13 @@ def test_system_prompt_customization_appended_not_replaced(self):
138133 rule = CustomScoringRule (description = "Custom rule" , level = "normal" )
139134 customization = SOPPromptCustomization (custom_scoring_rules = [rule ])
140135 prompt = TaskSOPPrompt .system_prompt (customization = customization )
141-
136+
142137 # Base rules should still be present
143138 assert "(c.1)" in prompt
144139 assert "(c.2)" in prompt
145140 assert "(c.3)" in prompt
146141 assert "(c.4)" in prompt
147-
142+
148143 # Custom rule should be appended
149144 assert "(c.5)" in prompt
150145 assert "Custom rule" in prompt
@@ -159,10 +154,8 @@ def test_project_config_with_custom_rules(self):
159154 CustomScoringRule (description = "Test rule 1" , level = "normal" ),
160155 CustomScoringRule (description = "Test rule 2" , level = "critical" ),
161156 ]
162- config = ProjectConfig (
163- sop_agent_custom_scoring_rules = custom_rules
164- )
165-
157+ config = ProjectConfig (sop_agent_custom_scoring_rules = custom_rules )
158+
166159 assert len (config .sop_agent_custom_scoring_rules ) == 2
167160 assert config .sop_agent_custom_scoring_rules [0 ].description == "Test rule 1"
168161 assert config .sop_agent_custom_scoring_rules [0 ].level == "normal"
@@ -172,7 +165,6 @@ def test_project_config_with_custom_rules(self):
172165 def test_project_config_without_custom_rules (self ):
173166 """Test ProjectConfig without custom scoring rules (default)"""
174167 config = ProjectConfig ()
175-
168+
176169 assert config .sop_agent_custom_scoring_rules == []
177170 assert isinstance (config .sop_agent_custom_scoring_rules , list )
178-
0 commit comments