@@ -190,28 +190,58 @@ def test_build_prompt_trace_snapshot_contains_sorted_sources():
190190 assert "messages" not in snapshot ["context_suffix" ][0 ]
191191
192192
193- def test_prompt_mutation_facade_registers_blocks ():
193+ def test_prompt_mutation_facade_dispatches_to_helper_functions ():
194194 assembly = PromptAssembly ()
195195 mutation = PromptMutation (assembly )
196196
197- mutation .add_system ("\n PLUGIN\n " , "plugin:test" , 950 )
198- mutation .add_user_text ("plugin user" , "plugin:test" , 950 )
199- mutation .add_context_prefix (
200- [{"role" : "system" , "content" : "prefix" }], "plugin:test" , 950
197+ with (
198+ patch ("astrbot.core.prompt.assembly.add_system_block" ) as mock_add_system ,
199+ patch ("astrbot.core.prompt.assembly.add_user_text" ) as mock_add_user_text ,
200+ patch (
201+ "astrbot.core.prompt.assembly.add_context_prefix"
202+ ) as mock_add_context_prefix ,
203+ patch (
204+ "astrbot.core.prompt.assembly.add_context_suffix"
205+ ) as mock_add_context_suffix ,
206+ patch ("astrbot.core.prompt.assembly.logger.warning" ),
207+ ):
208+ mutation .add_system ("\n PLUGIN\n " , "plugin:test" , 950 )
209+ mutation .add_user_text ("plugin user" , "plugin:test" , 950 )
210+ mutation .add_context_prefix (
211+ [{"role" : "system" , "content" : "prefix" }], "plugin:test" , 950
212+ )
213+ mutation .add_context_suffix (
214+ [{"role" : "assistant" , "content" : "suffix" }], "plugin:test" , 950
215+ )
216+
217+ mock_add_system .assert_called_once_with (
218+ assembly ,
219+ source = "plugin:test" ,
220+ order = 950 ,
221+ content = "\n PLUGIN\n " ,
222+ visible_in_trace = True ,
201223 )
202- mutation .add_context_suffix (
203- [{"role" : "assistant" , "content" : "suffix" }], "plugin:test" , 950
224+ mock_add_user_text .assert_called_once_with (
225+ assembly ,
226+ source = "plugin:test" ,
227+ order = 950 ,
228+ text = "plugin user" ,
229+ visible_in_trace = True ,
230+ )
231+ mock_add_context_prefix .assert_called_once_with (
232+ assembly ,
233+ source = "plugin:test" ,
234+ order = 950 ,
235+ messages = [{"role" : "system" , "content" : "prefix" }],
236+ visible_in_trace = True ,
237+ )
238+ mock_add_context_suffix .assert_called_once_with (
239+ assembly ,
240+ source = "plugin:test" ,
241+ order = 950 ,
242+ messages = [{"role" : "assistant" , "content" : "suffix" }],
243+ visible_in_trace = True ,
204244 )
205-
206- req = ProviderRequest (prompt = "hello" )
207- render_prompt_assembly (req , assembly )
208-
209- assert req .system_prompt == "\n PLUGIN\n "
210- assert [part .text for part in req .extra_user_content_parts ] == ["plugin user" ]
211- assert req .contexts == [
212- {"role" : "system" , "content" : "prefix" },
213- {"role" : "assistant" , "content" : "suffix" },
214- ]
215245
216246
217247def test_prompt_mutation_warns_once_for_reserved_plugin_order ():
0 commit comments