from unittest.mock import patch, MagicMock
from src import ai_client


def test_ai_client_send_gemini_cli() -> None:
 test_message = "Hello, this is a test prompt for the CLI adapter."
 test_response = "This is a dummy response from the Gemini CLI."
 ai_client.reset_session()
 ai_client.set_provider("gemini_cli", "gemini-2.5-flash-lite")
 with patch("src.ai_client.GeminiCliAdapter") as MockAdapterClass:
  mock_adapter_instance = MagicMock()
  mock_adapter_instance.send.return_value = {
   "text": test_response,
   "tool_calls": [],
  }
  mock_adapter_instance.last_usage = {"total_tokens": 100}
  mock_adapter_instance.last_latency = 0.5
  mock_adapter_instance.session_id = "test-session"
  MockAdapterClass.return_value = mock_adapter_instance
  ai_client._gemini_cli_adapter = mock_adapter_instance
  with patch.object(ai_client.events, "emit") as mock_emit:
   response = ai_client.send(
    md_content="<context></context>",
    user_message=test_message,
    base_dir=".",
   )
   mock_adapter_instance.send.assert_called()
   emitted_event_names = [call.args[0] for call in mock_emit.call_args_list]
   assert "request_start" in emitted_event_names
   assert "response_received" in emitted_event_names
   assert response == test_response
