feat(mma): Integrate Tier 4 QA analysis across all providers and conductor
This commit is contained in:
@@ -126,3 +126,99 @@ def test_end_to_end_tier4_integration():
|
||||
|
||||
mock_analysis.assert_called_once_with(stderr_content)
|
||||
assert f"QA ANALYSIS:\n{expected_analysis}" in output
|
||||
|
||||
def test_ai_client_passes_qa_callback():
|
||||
"""
|
||||
Verifies that ai_client.send passes the qa_callback down to the provider function.
|
||||
"""
|
||||
import ai_client
|
||||
|
||||
# Mocking a provider function to avoid actual API calls
|
||||
mock_send_gemini = MagicMock(return_value="AI Response")
|
||||
|
||||
qa_callback = MagicMock(return_value="QA Analysis")
|
||||
|
||||
# Force provider to gemini and mock its send function
|
||||
with patch("ai_client._provider", "gemini"), \
|
||||
patch("ai_client._send_gemini", mock_send_gemini):
|
||||
|
||||
ai_client.send(
|
||||
md_content="Context",
|
||||
user_message="Hello",
|
||||
qa_callback=qa_callback
|
||||
)
|
||||
|
||||
# Verify provider received the qa_callback
|
||||
mock_send_gemini.assert_called_once()
|
||||
args, kwargs = mock_send_gemini.call_args
|
||||
# qa_callback is the 7th positional argument in _send_gemini
|
||||
assert args[6] == qa_callback
|
||||
|
||||
def test_gemini_provider_passes_qa_callback_to_run_script():
|
||||
"""
|
||||
Verifies that _send_gemini passes the qa_callback to _run_script.
|
||||
"""
|
||||
import ai_client
|
||||
|
||||
# Mock Gemini chat and client
|
||||
mock_client = MagicMock()
|
||||
mock_chat = MagicMock()
|
||||
|
||||
# Simulate a tool call response
|
||||
mock_part = MagicMock()
|
||||
mock_part.text = ""
|
||||
mock_part.function_call = MagicMock()
|
||||
mock_part.function_call.name = "run_powershell"
|
||||
mock_part.function_call.args = {"script": "dir"}
|
||||
|
||||
mock_candidate = MagicMock()
|
||||
mock_candidate.content.parts = [mock_part]
|
||||
mock_candidate.finish_reason.name = "STOP"
|
||||
|
||||
mock_response = MagicMock()
|
||||
mock_response.candidates = [mock_candidate]
|
||||
mock_response.usage_metadata.prompt_token_count = 10
|
||||
mock_response.usage_metadata.candidates_token_count = 5
|
||||
|
||||
# Second call returns a stop response to break the loop
|
||||
mock_stop_part = MagicMock()
|
||||
mock_stop_part.text = "Done"
|
||||
mock_stop_part.function_call = None
|
||||
|
||||
mock_stop_candidate = MagicMock()
|
||||
mock_stop_candidate.content.parts = [mock_stop_part]
|
||||
mock_stop_candidate.finish_reason.name = "STOP"
|
||||
|
||||
mock_stop_response = MagicMock()
|
||||
mock_stop_response.candidates = [mock_stop_candidate]
|
||||
mock_stop_response.usage_metadata.prompt_token_count = 5
|
||||
mock_stop_response.usage_metadata.candidates_token_count = 2
|
||||
|
||||
mock_chat.send_message.side_effect = [mock_response, mock_stop_response]
|
||||
|
||||
# Mock count_tokens to avoid chat creation failure
|
||||
mock_count_resp = MagicMock()
|
||||
mock_count_resp.total_tokens = 100
|
||||
mock_client.models.count_tokens.return_value = mock_count_resp
|
||||
|
||||
qa_callback = MagicMock()
|
||||
|
||||
# Set global state for the test
|
||||
with patch("ai_client._gemini_client", mock_client), \
|
||||
patch("ai_client._gemini_chat", None), \
|
||||
patch("ai_client._ensure_gemini_client"), \
|
||||
patch("ai_client._run_script", return_value="output") as mock_run_script, \
|
||||
patch("ai_client._get_gemini_history_list", return_value=[]):
|
||||
|
||||
# Ensure chats.create returns our mock_chat
|
||||
mock_client.chats.create.return_value = mock_chat
|
||||
|
||||
ai_client._send_gemini(
|
||||
md_content="Context",
|
||||
user_message="Run dir",
|
||||
base_dir=".",
|
||||
qa_callback=qa_callback
|
||||
)
|
||||
|
||||
# Verify _run_script received the qa_callback
|
||||
mock_run_script.assert_called_once_with("dir", ".", qa_callback)
|
||||
|
||||
Reference in New Issue
Block a user