"""Tests for CommitDaemon and MultiModelLlamaClient queue integration. Verifies that auto-commit-service sends batch priority, stay_warm=0, and cooldown=60 to the model-boss coordinator via InferenceClient. """ from unittest.mock import AsyncMock, MagicMock, patch import pytest from auto_commit_service.config import AutoCommitSettings @pytest.fixture def settings(): """Minimal settings for testing.""" return AutoCommitSettings( service_name="test-daemon", reasoning_model_id="ministral-14b-reasoning", instruct_model_id="ministral-3b-instruct", llm_timeout=30.0, cycle_interval_seconds=1, enabled=False, ) class TestMultiModelClientQueueParams: """MultiModelLlamaClient passes queue params to InferenceClient.""" def test_default_client_id(self) -> None: from auto_commit_service.llm.multi_model_client import MultiModelLlamaClient client = MultiModelLlamaClient() assert client._client_id == "auto-commit-service" assert client._client._client_id == "auto-commit-service" def test_custom_client_id(self) -> None: from auto_commit_service.llm.multi_model_client import MultiModelLlamaClient client = MultiModelLlamaClient(client_id="test-service") assert client._client_id == "test-service" assert client._client._client_id == "test-service" @pytest.mark.asyncio async def test_chat_passes_queue_params(self) -> None: """_chat() sends keep_alive and context through to InferenceClient.""" 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") result = await client._chat( "ministral-3b-instruct", [{"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, ) class TestDaemonSimplifiedLoop: """Daemon loop no longer manages model lifecycle directly.""" def _make_daemon(self, settings): mock_client = MagicMock() mock_client.is_available = AsyncMock(return_value=True) mock_client.ensure_services = AsyncMock() mock_client.reasoning_model_id = settings.reasoning_model_id mock_client.instruct_model_id = settings.instruct_model_id from auto_commit_service.scheduler.daemon import CommitDaemon return CommitDaemon(settings=settings, llm_client=mock_client) def test_no_lifecycle_attrs(self, settings) -> None: """Daemon no longer has _models_loaded_since or _models_released_at.""" daemon = self._make_daemon(settings) assert not hasattr(daemon, "_models_loaded_since") assert not hasattr(daemon, "_models_released_at") def test_no_lifecycle_methods(self, settings) -> None: """Daemon no longer has _should_force_release or _is_in_cooldown.""" daemon = self._make_daemon(settings) assert not hasattr(daemon, "_should_force_release") assert not hasattr(daemon, "_is_in_cooldown") class TestConfigRemovedFields: """model_max_alive_seconds and model_cooldown_seconds are removed.""" def test_no_model_max_alive_seconds(self) -> None: settings = AutoCommitSettings(service_name="test") assert not hasattr(settings, "model_max_alive_seconds") def test_no_model_cooldown_seconds(self) -> None: settings = AutoCommitSettings(service_name="test") assert not hasattr(settings, "model_cooldown_seconds")