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
|
@pytest.mark.asyncio
|
||||||
async def test_chat_passes_queue_params(self) -> None:
|
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
|
from auto_commit_service.llm.multi_model_client import MultiModelLlamaClient
|
||||||
|
|
||||||
client = MultiModelLlamaClient(client_id="test-svc")
|
client = MultiModelLlamaClient(client_id="test-svc")
|
||||||
client._client = MagicMock()
|
client._client = MagicMock()
|
||||||
client._client.chat = AsyncMock(return_value="response text")
|
client._client._coordinator_url = "http://coord.test"
|
||||||
|
client._client._default_priority = "normal"
|
||||||
|
|
||||||
|
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(
|
result = await client._chat(
|
||||||
"ministral-3b-instruct",
|
"summarization.short",
|
||||||
[{"role": "user", "content": "test"}],
|
[{"role": "user", "content": "test"}],
|
||||||
max_tokens=100,
|
max_tokens=100,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result == "response text"
|
assert result == "response text"
|
||||||
client._client.chat.assert_called_once_with(
|
assert captured["url"] == "http://coord.test/v1/chat/completions"
|
||||||
model="ministral-3b-instruct",
|
assert captured["body"]["task"] == "summarization.short"
|
||||||
messages=[{"role": "user", "content": "test"}],
|
assert captured["body"]["messages"] == [{"role": "user", "content": "test"}]
|
||||||
max_tokens=100,
|
assert captured["body"]["max_tokens"] == 100
|
||||||
temperature=client._temperature,
|
assert captured["body"]["temperature"] == client._temperature
|
||||||
keep_alive=300,
|
assert captured["body"]["x_client_id"] == "test-svc"
|
||||||
context=None,
|
assert captured["body"]["x_keep_alive"] == 300
|
||||||
)
|
assert "model" not in captured["body"]
|
||||||
|
|
||||||
|
|
||||||
class TestDaemonSimplifiedLoop:
|
class TestDaemonSimplifiedLoop:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue