from unittest.mock import MagicMock
from src import ai_client


def test_gemini_cli_full_integration() -> None:
    ai_client.reset_session()
    ai_client.set_provider("gemini_cli", "gemini-2.0-flash")
    mock_adapter = MagicMock()
    mock_adapter.send.return_value = {
        "text": "Final integrated answer",
        "tool_calls": [],
    }
    mock_adapter.last_usage = {"total_tokens": 10}
    ai_client._gemini_cli_adapter = mock_adapter
    result = ai_client.send("context", "integrated test")
    assert "Final integrated answer" in result


def test_gemini_cli_rejection_and_history() -> None:
    ai_client.reset_session()
    ai_client.set_provider("gemini_cli", "gemini-2.0-flash")
    mock_adapter = MagicMock()
    mock_adapter.send.return_value = {
        "text": "",
        "tool_calls": [{"name": "run_powershell", "args": {"script": "dir"}}],
    }
    mock_adapter.last_usage = {}
    ai_client._gemini_cli_adapter = mock_adapter
    result = ai_client.send("ctx", "msg", pre_tool_callback=lambda *a, **kw: None)
    assert result is not None
