|
| 1 | +"""Verify the actual SDK payload without importing a real provider client.""" |
| 2 | + |
| 3 | +import asyncio |
| 4 | +import sys |
| 5 | +from types import SimpleNamespace |
| 6 | +from unittest.mock import Mock |
| 7 | + |
| 8 | +import pytest |
| 9 | + |
| 10 | +from modules.ai_assistant.ai_service import AIModel, AIService |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.parametrize( |
| 14 | + ("selection", "expected"), |
| 15 | + [ |
| 16 | + (None, "claude-sonnet-4-6"), |
| 17 | + (AIModel.CLAUDE_OPUS, "claude-opus-4-6"), |
| 18 | + (AIModel.CLAUDE_HAIKU, "claude-haiku-4-5-20251001"), |
| 19 | + ], |
| 20 | +) |
| 21 | +def test_complete_sends_documented_model_id(monkeypatch, selection, expected): |
| 22 | + """The default and selectable models must reach the SDK with valid IDs.""" |
| 23 | + create = Mock( |
| 24 | + return_value=SimpleNamespace( |
| 25 | + content=[SimpleNamespace(text="fixture response")], |
| 26 | + model=expected, |
| 27 | + usage=SimpleNamespace(input_tokens=1, output_tokens=1), |
| 28 | + ) |
| 29 | + ) |
| 30 | + client = SimpleNamespace(messages=SimpleNamespace(create=create)) |
| 31 | + monkeypatch.setitem( |
| 32 | + sys.modules, "anthropic", SimpleNamespace(Anthropic=Mock(return_value=client)) |
| 33 | + ) |
| 34 | + service = AIService(api_key="fixture-not-a-real-key") |
| 35 | + if selection is not None: |
| 36 | + service.set_model(selection) |
| 37 | + |
| 38 | + result = asyncio.run(service.complete("fixture prompt", use_history=False)) |
| 39 | + |
| 40 | + assert result.success |
| 41 | + create.assert_called_once() |
| 42 | + assert create.call_args.kwargs["model"] == expected |
| 43 | + assert create.call_args.kwargs["messages"] == [ |
| 44 | + {"role": "user", "content": "fixture prompt"} |
| 45 | + ] |
0 commit comments