test(suite): update all tests for streaming/locking architecture and mock parity

This commit is contained in:
2026-03-02 10:15:41 -05:00
parent 5de253b15b
commit 0b5552fa01
14 changed files with 130 additions and 77 deletions

View File

@@ -89,6 +89,7 @@ async def test_headless_verification_error_and_qa_interceptor(vlogger) -> None:
mock_resp1.candidates = [MagicMock(content=MagicMock(parts=[mock_part1]), finish_reason=MagicMock(name="STOP"))]
mock_resp1.usage_metadata.prompt_token_count = 10
mock_resp1.usage_metadata.candidates_token_count = 5
mock_resp1.text = mock_part1.text
# 2nd round: Final text after tool result
mock_part2 = MagicMock()
mock_part2.text = "The command failed but I understand why. Task done."
@@ -97,16 +98,22 @@ async def test_headless_verification_error_and_qa_interceptor(vlogger) -> None:
mock_resp2.candidates = [MagicMock(content=MagicMock(parts=[mock_part2]), finish_reason=MagicMock(name="STOP"))]
mock_resp2.usage_metadata.prompt_token_count = 20
mock_resp2.usage_metadata.candidates_token_count = 10
mock_resp2.text = mock_part2.text
mock_chat.send_message.side_effect = [mock_resp1, mock_resp2]
# Handle streaming calls
def make_stream_mock(resp):
m = MagicMock()
m.__iter__.return_value = [resp]
m.candidates = resp.candidates
m.usage_metadata = resp.usage_metadata
return m
mock_chat.send_message_stream.side_effect = [make_stream_mock(mock_resp1), make_stream_mock(mock_resp2)]
# Mock run_powershell behavior: it should call the qa_callback on error
def run_side_effect(script: Any, base_dir: Any, qa_callback: Any) -> Any:
if qa_callback:
analysis = qa_callback("Error: file not found")
return f"""STDERR: Error: file not found
QA ANALYSIS:
{analysis}"""
return f"STDERR: Error: file not found\n\nQA ANALYSIS:\n{analysis}"
return "Error: file not found"
mock_run.side_effect = run_side_effect
mock_qa.return_value = "FIX: Check if path exists."
@@ -123,8 +130,11 @@ QA ANALYSIS:
mock_qa.assert_called_once_with("Error: file not found")
# Verify the 2nd send_message call includes the QA ANALYSIS in its payload (f_resps)
# The first call is the user message, the second is the tool response.
assert mock_chat.send_message.call_count == 2
args, kwargs = mock_chat.send_message.call_args_list[1]
assert (mock_chat.send_message.call_count + mock_chat.send_message_stream.call_count) == 2
# Get the second call's payload (either from send_message or send_message_stream)
calls = mock_chat.send_message.call_args_list + mock_chat.send_message_stream.call_args_list
args, kwargs = calls[1]
f_resps = args[0]
found_qa = False