test(daemon): ✅ Add test cases for task-based routing behavior in daemon
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
c59be053f0
commit
0694372a0f
1 changed files with 42 additions and 15 deletions
|
|
@ -43,28 +43,55 @@ class TestMultiModelClientQueueParams:
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_chat_passes_queue_params(self) -> None:
|
||||
"""_chat() sends keep_alive and context through to InferenceClient."""
|
||||
"""_chat() POSTs task + queue params to /v1/chat/completions."""
|
||||
from auto_commit_service.llm.multi_model_client import MultiModelLlamaClient
|
||||
|
||||
client = MultiModelLlamaClient(client_id="test-svc")
|
||||
client._client = MagicMock()
|
||||
client._client.chat = AsyncMock(return_value="response text")
|
||||
client._client._coordinator_url = "http://coord.test"
|
||||
client._client._default_priority = "normal"
|
||||
|
||||
result = await client._chat(
|
||||
"ministral-3b-instruct",
|
||||
[{"role": "user", "content": "test"}],
|
||||
max_tokens=100,
|
||||
)
|
||||
captured: dict = {}
|
||||
|
||||
class _FakeResponse:
|
||||
def raise_for_status(self) -> None:
|
||||
return None
|
||||
|
||||
def json(self) -> dict:
|
||||
return {"choices": [{"message": {"content": "response text"}}]}
|
||||
|
||||
class _FakeAsyncClient:
|
||||
def __init__(self, *_args, **_kwargs) -> None:
|
||||
pass
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *_args) -> None:
|
||||
return None
|
||||
|
||||
async def post(self, url: str, json: dict) -> _FakeResponse:
|
||||
captured["url"] = url
|
||||
captured["body"] = json
|
||||
return _FakeResponse()
|
||||
|
||||
import httpx
|
||||
with patch.object(httpx, "AsyncClient", _FakeAsyncClient):
|
||||
result = await client._chat(
|
||||
"summarization.short",
|
||||
[{"role": "user", "content": "test"}],
|
||||
max_tokens=100,
|
||||
)
|
||||
|
||||
assert result == "response text"
|
||||
client._client.chat.assert_called_once_with(
|
||||
model="ministral-3b-instruct",
|
||||
messages=[{"role": "user", "content": "test"}],
|
||||
max_tokens=100,
|
||||
temperature=client._temperature,
|
||||
keep_alive=300,
|
||||
context=None,
|
||||
)
|
||||
assert captured["url"] == "http://coord.test/v1/chat/completions"
|
||||
assert captured["body"]["task"] == "summarization.short"
|
||||
assert captured["body"]["messages"] == [{"role": "user", "content": "test"}]
|
||||
assert captured["body"]["max_tokens"] == 100
|
||||
assert captured["body"]["temperature"] == client._temperature
|
||||
assert captured["body"]["x_client_id"] == "test-svc"
|
||||
assert captured["body"]["x_keep_alive"] == 300
|
||||
assert "model" not in captured["body"]
|
||||
|
||||
|
||||
class TestDaemonSimplifiedLoop:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue