Add test for trailing assistant+system ordering, improve docstring

Add test exercising the step 3 ordering where stripping a trailing
assistant exposes a system message that then gets converted to user.
Move the reasoning about when a trailing system message can occur
into the docstring.
This commit is contained in:
Paul Kompfner
2026-03-12 15:24:17 -04:00
parent 7f98cc9921
commit e69f5a76e1
2 changed files with 25 additions and 4 deletions

View File

@@ -1152,6 +1152,25 @@ class TestPerplexityGetLLMInvocationParams(unittest.TestCase):
self.assertEqual(params["messages"][1]["role"], "user")
self.assertEqual(params["messages"][1]["content"], "Always be polite.")
def test_trailing_assistant_removed_then_system_converted(self):
"""Test that trailing assistant is removed, exposing a system message that becomes user.
This exercises the ordering of step 3: strip trailing assistants first,
then convert a trailing system to user.
"""
messages: list[LLMStandardMessage] = [
{"role": "system", "content": "You are helpful."},
{"role": "assistant", "content": "Sure thing."},
]
context = LLMContext(messages=messages)
params = self.adapter.get_llm_invocation_params(context)
# Trailing assistant removed → [system] → system converted to user → [user]
self.assertEqual(len(params["messages"]), 1)
self.assertEqual(params["messages"][0]["role"], "user")
self.assertEqual(params["messages"][0]["content"], "You are helpful.")
def test_consecutive_assistants_merged_then_trailing_removed(self):
"""Test that consecutive assistant messages are merged, then trailing assistant is removed."""
messages: list[LLMStandardMessage] = [