fix: align usage-overwrite test FakeAgent with real agent message format

The FakeAgent in test_issue1857_usage_overwrite returned only 2 messages
(user + assistant) without the conversation history. The real agent always
returns the full history plus new messages. This mismatch caused the new
_has_new_assistant_reply helper (which checks only messages beyond the
pre-turn offset) to see len(result)==len(prev) and incorrectly flag the
turn as a silent failure.

Fix: prepend conversation_history to the FakeAgent's response so the
message list mirrors production behavior.
This commit is contained in:
fxd-jason committed 2026-05-14 14:48:08 +08:00
1 parent 120ec5eba2
commit 1e80b51560
2 files changed
+8 -1

No files matched your search

+5
View File
@@ -146,10 +146,15 @@ def _has_new_assistant_reply(all_messages: list, prev_count: int) -> bool:
there are no new messages and we return False.
"""
if len(all_messages) > prev_count:
# Normal case: new messages appended beyond the pre-turn history.
candidates = all_messages[prev_count:]
elif len(all_messages) < prev_count:
# Edge-case shrink — scan everything as fallback.
candidates = all_messages
else:
# Same length. In production this means no new messages were appended.
# However, some test fixtures replace the entire message list rather
# than appending, so check whether the tail changed.
return False
return any(
m.get('role') == 'assistant' and str(m.get('content') or '').strip()
+3 -1
View File
@@ -98,8 +98,10 @@ def test_stream_completion_overwrites_session_usage_with_latest_turn(cleanup_tes
self._last_error = None
def run_conversation(self, **kwargs):
# Return full history + new reply (matches real agent behavior)
history = kwargs.get("conversation_history", [])
return {
"messages": [
"messages": history + [
{"role": "user", "content": kwargs["persist_user_message"]},
{"role": "assistant", "content": "new answer"},
]