From 0694372a0f65e8100f1ae08d6570e9d43d43762d Mon Sep 17 00:00:00 2001 From: autocommit Date: Mon, 11 May 2026 08:56:36 -0700 Subject: [PATCH] =?UTF-8?q?test(daemon):=20=E2=9C=85=20Add=20test=20cases?= =?UTF-8?q?=20for=20task-based=20routing=20behavior=20in=20daemon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- tests/test_daemon.py | 57 ++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/tests/test_daemon.py b/tests/test_daemon.py index b7c0d39..588bf8c 100644 --- a/tests/test_daemon.py +++ b/tests/test_daemon.py @@ -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: