test(minimax): add client instantiation unit tests to catch credential and base URL regressions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import unittest.mock
|
||||
from unittest.mock import patch, MagicMock
|
||||
import pytest
|
||||
from src import ai_client
|
||||
|
||||
def test_minimax_model_selection() -> None:
|
||||
@@ -62,3 +63,28 @@ def test_minimax_reasoning_extractor_omitted_when_caps_reasoning_false() -> None
|
||||
patch("src.ai_client._get_deepseek_tools", return_value=[]):
|
||||
ai_client._send_minimax("system", "user", ".", None, "", False, None, None, None)
|
||||
assert len(captured_kwargs) >= 1
|
||||
|
||||
def test_minimax_ensure_client_instantiation() -> None:
|
||||
"""Verify that _ensure_minimax_client instantiates the OpenAI client with correct credentials and base URL."""
|
||||
mock_openai = MagicMock()
|
||||
mock_openai_module = MagicMock()
|
||||
mock_openai_module.OpenAI = mock_openai
|
||||
|
||||
with patch("src.ai_client._require_warmed", return_value=mock_openai_module), \
|
||||
patch("src.ai_client._load_credentials", return_value={"minimax": {"api_key": "test-key-123", "base_url": "https://api.minimax.io/v1"}}):
|
||||
# Reset client state to force instantiation
|
||||
ai_client._minimax_client = None
|
||||
ai_client._ensure_minimax_client()
|
||||
|
||||
# Assert correct arguments passed to OpenAI
|
||||
mock_openai.assert_called_once_with(api_key="test-key-123", base_url="https://api.minimax.io/v1")
|
||||
assert ai_client._minimax_client == mock_openai.return_value
|
||||
|
||||
def test_minimax_ensure_client_missing_key_raises_value_error() -> None:
|
||||
"""Verify that _ensure_minimax_client raises ValueError if API key is missing."""
|
||||
mock_openai_module = MagicMock()
|
||||
with patch("src.ai_client._require_warmed", return_value=mock_openai_module), \
|
||||
patch("src.ai_client._load_credentials", return_value={}):
|
||||
ai_client._minimax_client = None
|
||||
with pytest.raises(ValueError, match="MiniMax API key not found in credentials.toml"):
|
||||
ai_client._ensure_minimax_client()
|
||||
|
||||
Reference in New Issue
Block a user