Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test: add 62 coverage tests for LLM config, socket service, notifications (round 6) (#2938)

LearningCircuit5757d4ad5cba
diff --git a/tests/config/test_llm_config_extra_coverage.py b/tests/config/test_llm_config_extra_coverage.py
new file mode 100644
index 0000000000..d4049ab1d0
--- /dev/null
+++ b/tests/config/test_llm_config_extra_coverage.py
@@ -0,0 +1,410 @@
+"""Extra coverage tests for config/llm_config.py — provider availability and context window.
+
+Targets uncovered branches:
+- is_*_available() Exception (non-ImportError) paths
+- is_vllm_available() success and import failure paths
+- is_llamacpp_available() path configurations
+- _get_context_window_for_provider() all branches
+- get_available_providers() with various provider combinations
+- get_selected_llm_provider()
+"""
+
+from unittest.mock import MagicMock, patch
+
+
+MODULE = "local_deep_research.config.llm_config"
+
+
+# ===========================================================================
+# is_*_available — Exception (non-ImportError) paths
+# ===========================================================================
+
+
+class TestProviderAvailabilityExceptionPaths:
+ """Each is_*_available catches both ImportError and Exception.
+ Test the Exception branch (provider imported but is_available raises)."""
+
+ def test_openai_exception_returns_false(self):
+ from local_deep_research.config.llm_config import is_openai_available
+
+ with patch(
+ f"{MODULE}.OpenAIProvider",
+ create=True,
+ ):
+ # Patch the import to succeed but is_available to raise
+ mock_provider = MagicMock()
+ mock_provider.is_available.side_effect = RuntimeError("API error")
+
+ with patch.dict(
+ "sys.modules",
+ {
+ "local_deep_research.llm.providers.implementations.openai": MagicMock(
+ OpenAIProvider=mock_provider
+ )
+ },
+ ):
+ result = is_openai_available()
+
+ assert result is False
+
+ def test_anthropic_exception_returns_false(self):
+ from local_deep_research.config.llm_config import is_anthropic_available
+
+ mock_mod = MagicMock()
+ mock_mod.AnthropicProvider.is_available.side_effect = RuntimeError(
+ "err"
+ )
+
+ with patch.dict(
+ "sys.modules",
+ {
+ "local_deep_research.llm.providers.implementations.anthropic": mock_mod
+ },
+ ):
+ assert is_anthropic_available() is False
+
+ def test_ollama_exception_returns_false(self):
+ from local_deep_research.config.llm_config import is_ollama_available
+
+ mock_mod = MagicMock()
+ mock_mod.OllamaProvider.is_available.side_effect = ConnectionError(
+ "refused"
+ )
+
+ with patch.dict(
+ "sys.modules",
+ {
+ "local_deep_research.llm.providers.implementations.ollama": mock_mod
+ },
+ ):
+ assert is_ollama_available() is False
+
+ def test_openai_endpoint_exception_returns_false(self):
+ from local_deep_research.config.llm_config import (
+ is_openai_endpoint_available,
+ )
+
+ mock_mod = MagicMock()
+ mock_mod.CustomOpenAIEndpointProvider.is_available.side_effect = (
+ ValueError("bad config")
+ )
+
+ with patch.dict(
+ "sys.modules",
+ {
+ "local_deep_research.llm.providers.implementations.custom_openai_endpoint": mock_mod
+ },
+ ):
+ assert is_openai_endpoint_available() is False
+
+ def test_lmstudio_exception_returns_false(self):
+ from local_deep_research.config.llm_config import is_lmstudio_available
+
+ mock_mod = MagicMock()
+ mock_mod.LMStudioProvider.is_available.side_effect = TimeoutError()
+
+ with patch.dict(
+ "sys.modules",
+ {
+ "local_deep_research.llm.providers.implementations.lmstudio": mock_mod
+ },
+ ):
+ assert is_lmstudio_available() is False
+
+ def test_google_exception_returns_false(self):
+ from local_deep_research.config.llm_config import is_google_available
+
+ mock_mod = MagicMock()
+ mock_mod.GoogleProvider.is_available.side_effect = RuntimeError("auth")
+
+ with patch.dict(
+ "sys.modules",
+ {"local_deep_research.llm.providers.google": mock_mod},
+ ):
+ assert is_google_available() is False
+
+ def test_openrouter_exception_returns_false(self):
+ from local_deep_research.config.llm_config import (
+ is_openrouter_available,
+ )
+
+ mock_mod = MagicMock()
+ mock_mod.OpenRouterProvider.is_available.side_effect = RuntimeError()
+
+ with patch.dict(
+ "sys.modules",
+ {"local_deep_research.llm.providers.openrouter": mock_mod},
+ ):
+ assert is_openrouter_available() is False
+
+
+# ===========================================================================
+# is_vllm_available
+# ===========================================================================
+
+
+class TestIsVllmAvailable:
+ def test_all_imports_missing(self):
+ from local_deep_research.config.llm_config import is_vllm_available
+
+ with patch.dict("sys.modules", {"torch": None}):
+ assert is_vllm_available() is False
+
+ def test_vllm_missing(self):
+ from local_deep_research.config.llm_config import is_vllm_available
+
+ with patch.dict("sys.modules", {"vllm": None}):
+ assert is_vllm_available() is False
+
+
+# ===========================================================================
+# is_llamacpp_available
+# ===========================================================================
+
+
+class TestIsLlamacppAvailable:
+ def test_import_error_returns_false(self):
+ from local_deep_research.config.llm_config import is_llamacpp_available
+
+ with patch.dict("sys.modules", {"langchain_community.llms": None}):
+ assert is_llamacpp_available() is False
+
+ def test_no_model_path_returns_false(self):
+ from local_deep_research.config.llm_config import is_llamacpp_available
+
+ with patch(f"{MODULE}.get_setting_from_snapshot", return_value=None):
+ result = is_llamacpp_available(settings_snapshot={})
+
+ assert result is False
+
+ def test_empty_model_path_returns_false(self):
+ from local_deep_research.config.llm_config import is_llamacpp_available
+
+ with patch(f"{MODULE}.get_setting_from_snapshot", return_value=""):
+ assert is_llamacpp_available(settings_snapshot={}) is False
+
+ def test_valid_model_path_returns_true(self):
+ from local_deep_research.config.llm_config import is_llamacpp_available
+
+ with patch(
+ f"{MODULE}.get_setting_from_snapshot",
+ return_value="/models/llama.gguf",
+ ):
+ result = is_llamacpp_available(settings_snapshot={})
+
+ assert result is True
+
+ def test_setting_exception_returns_false(self):
+ from local_deep_research.config.llm_config import is_llamacpp_available
+
+ with patch(
+ f"{MODULE}.get_setting_from_snapshot",
+ side_effect=RuntimeError("settings error"),
+ ):
+ assert is_llamacpp_available(settings_snapshot={}) is False
+
+
+# ===========================================================================
+# _get_context_window_for_provider
+# ===========================================================================
+
+
+class TestGetContextWindowForProvider:
+ def test_local_provider_default(self):
+ from local_deep_research.config.llm_config import (
+ _get_context_window_for_provider,
+ )
+
+ with patch(f"{MODULE}.get_setting_from_snapshot", return_value=4096):
+ result = _get_context_window_for_provider("ollama")
+
+ assert result == 4096
+
+ def test_local_provider_custom_size(self):
+ from local_deep_research.config.llm_config import (
+ _get_context_window_for_provider,
+ )
+
+ with patch(f"{MODULE}.get_setting_from_snapshot", return_value=8192):
+ result = _get_context_window_for_provider("llamacpp")
+
+ assert result == 8192
+
+ def test_local_provider_none_returns_default(self):
+ from local_deep_research.config.llm_config import (
+ _get_context_window_for_provider,
+ )
+
+ with patch(f"{MODULE}.get_setting_from_snapshot", return_value=None):
+ result = _get_context_window_for_provider("lmstudio")
+
+ assert result == 4096
+
+ def test_cloud_provider_unrestricted(self):
+ from local_deep_research.config.llm_config import (
+ _get_context_window_for_provider,
+ )
+
+ with patch(f"{MODULE}.get_setting_from_snapshot", return_value=True):
+ result = _get_context_window_for_provider("openai")
+
+ assert result is None
+
+ def test_cloud_provider_restricted_custom_size(self):
+ from local_deep_research.config.llm_config import (
+ _get_context_window_for_provider,
+ )
+
+ call_count = 0
+
+ def setting_side_effect(key, default=None, **kwargs):
+ nonlocal call_count
+ call_count += 1
+ if call_count == 1:
+ return False # unrestricted = False
+ return 64000 # custom window size
+
+ with patch(
+ f"{MODULE}.get_setting_from_snapshot",
+ side_effect=setting_side_effect,
+ ):
+ result = _get_context_window_for_provider("anthropic")
+
+ assert result == 64000
+
+ def test_cloud_provider_restricted_none_returns_default(self):
+ from local_deep_research.config.llm_config import (
+ _get_context_window_for_provider,
+ )
+
+ call_count = 0
+
+ def setting_side_effect(key, default=None, **kwargs):
+ nonlocal call_count
+ call_count += 1
+ if call_count == 1:
+ return False # unrestricted = False
+ return None # no custom size
+
+ with patch(
+ f"{MODULE}.get_setting_from_snapshot",
+ side_effect=setting_side_effect,
+ ):
+ result = _get_context_window_for_provider("openrouter")
+
+ assert result == 128000
+
+ def test_local_provider_string_converted(self):
+ from local_deep_research.config.llm_config import (
+ _get_context_window_for_provider,
+ )
+
+ with patch(f"{MODULE}.get_setting_from_snapshot", return_value="16384"):
+ result = _get_context_window_for_provider("ollama")
+
+ assert result == 16384
+
+
+# ===========================================================================
+# get_available_providers
+# ===========================================================================
+
+
+class TestGetAvailableProviders:
+ def test_no_providers_returns_none_entry(self):
+ from local_deep_research.config.llm_config import (
+ get_available_providers,
+ )
+
+ get_available_providers.cache_clear()
+
+ with (
+ patch(f"{MODULE}.is_ollama_available", return_value=False),
+ patch(f"{MODULE}.is_openai_available", return_value=False),
+ patch(f"{MODULE}.is_anthropic_available", return_value=False),
+ patch(f"{MODULE}.is_google_available", return_value=False),
+ patch(f"{MODULE}.is_openrouter_available", return_value=False),
+ patch(f"{MODULE}.is_openai_endpoint_available", return_value=False),
+ patch(f"{MODULE}.is_lmstudio_available", return_value=False),
+ patch(f"{MODULE}.is_llamacpp_available", return_value=False),
+ patch(f"{MODULE}.is_vllm_available", return_value=False),
+ ):
+ result = get_available_providers()
+
+ assert "none" in result
+ get_available_providers.cache_clear()
+
+ def test_multiple_providers_available(self):
+ from local_deep_research.config.llm_config import (
+ get_available_providers,
+ )
+
+ get_available_providers.cache_clear()
+
+ with (
+ patch(f"{MODULE}.is_ollama_available", return_value=True),
+ patch(f"{MODULE}.is_openai_available", return_value=True),
+ patch(f"{MODULE}.is_anthropic_available", return_value=False),
+ patch(f"{MODULE}.is_google_available", return_value=False),
+ patch(f"{MODULE}.is_openrouter_available", return_value=False),
+ patch(f"{MODULE}.is_openai_endpoint_available", return_value=False),
+ patch(f"{MODULE}.is_lmstudio_available", return_value=False),
+ patch(f"{MODULE}.is_llamacpp_available", return_value=False),
+ patch(f"{MODULE}.is_vllm_available", return_value=False),
+ ):
+ result = get_available_providers()
+
+ assert "ollama" in result
+ assert "openai" in result
+ assert "none" not in result
+ get_available_providers.cache_clear()
+
+ def test_all_providers_available(self):
+ from local_deep_research.config.llm_config import (
+ get_available_providers,
+ )
+
+ get_available_providers.cache_clear()
+
+ with (
+ patch(f"{MODULE}.is_ollama_available", return_value=True),
+ patch(f"{MODULE}.is_openai_available", return_value=True),
+ patch(f"{MODULE}.is_anthropic_available", return_value=True),
+ patch(f"{MODULE}.is_google_available", return_value=True),
+ patch(f"{MODULE}.is_openrouter_available", return_value=True),
+ patch(f"{MODULE}.is_openai_endpoint_available", return_value=True),
+ patch(f"{MODULE}.is_lmstudio_available", return_value=True),
+ patch(f"{MODULE}.is_llamacpp_available", return_value=True),
+ patch(f"{MODULE}.is_vllm_available", return_value=True),
+ ):
+ result = get_available_providers()
+
+ assert len(result) == 9
+ get_available_providers.cache_clear()
+
+
+# ===========================================================================
+# get_selected_llm_provider
+# ===========================================================================
+
+
+class TestGetSelectedLlmProvider:
+ def test_returns_lowercase(self):
+ from local_deep_research.config.llm_config import (
+ get_selected_llm_provider,
+ )
+
+ with patch(
+ f"{MODULE}.get_setting_from_snapshot", return_value="OLLAMA"
+ ):
+ assert get_selected_llm_provider() == "ollama"
+
+ def test_default_ollama(self):
+ from local_deep_research.config.llm_config import (
+ get_selected_llm_provider,
+ )
+
+ result = get_selected_llm_provider(
+ settings_snapshot={"llm.provider": "anthropic"}
+ )
+ assert result == "anthropic"
diff --git a/tests/notifications/test_service_extra_coverage.py b/tests/notifications/test_service_extra_coverage.py
new file mode 100644
index 0000000000..cc9808e2ee
--- /dev/null
+++ b/tests/notifications/test_service_extra_coverage.py
@@ -0,0 +1,169 @@
+"""Extra coverage for notifications/service.py — _send_with_retry, URL validation, service detection."""
+
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+from local_deep_research.notifications.service import (
+ NotificationService,
+ SendError,
+ ServiceError,
+)
+
+MODULE = "local_deep_research.notifications.service"
+
+
+def _make_service():
+ """Create a NotificationService with mocked apprise."""
+ with patch(f"{MODULE}.apprise") as mock_apprise_module:
+ mock_apprise_module.Apprise.return_value = MagicMock()
+ svc = NotificationService.__new__(NotificationService)
+ svc.apprise = mock_apprise_module.Apprise.return_value
+ svc.allow_private_ips = False
+ svc.SERVICE_PATTERNS = NotificationService.SERVICE_PATTERNS
+ return svc
+
+
+# ===========================================================================
+# _send_with_retry — direct invocation
+# ===========================================================================
+
+
+class TestSendWithRetry:
+ def test_success_returns_true(self):
+ svc = _make_service()
+ mock_apprise = MagicMock()
+ mock_apprise.notify.return_value = True
+
+ # Call _send_with_retry directly (bypasses Tenacity decorator in test)
+ result = svc._send_with_retry("Title", "Body", mock_apprise)
+ assert result is True
+ mock_apprise.notify.assert_called_once()
+
+ def test_failure_raises_send_error(self):
+ svc = _make_service()
+ mock_apprise = MagicMock()
+ mock_apprise.notify.return_value = False
+
+ with pytest.raises(SendError, match="Failed to send"):
+ svc._send_with_retry("Title", "Body", mock_apprise)
+
+ def test_with_tag_and_attach(self):
+ svc = _make_service()
+ mock_apprise = MagicMock()
+ mock_apprise.notify.return_value = True
+
+ result = svc._send_with_retry(
+ "Title", "Body", mock_apprise, tag="urgent", attach=["/tmp/f.txt"]
+ )
+ assert result is True
+ call_kwargs = mock_apprise.notify.call_args.kwargs
+ assert call_kwargs["tag"] == "urgent"
+ assert call_kwargs["attach"] == ["/tmp/f.txt"]
+
+
+# ===========================================================================
+# send — URL validation failure
+# ===========================================================================
+
+
+class TestSendUrlValidation:
+ def test_invalid_service_url_raises(self):
+ svc = _make_service()
+
+ mock_validator = MagicMock()
+ mock_validator.validate_multiple_urls.return_value = (
+ False,
+ "SSRF blocked",
+ )
+
+ with (
+ patch(f"{MODULE}.NotificationURLValidator", mock_validator),
+ pytest.raises((ServiceError, SendError)),
+ ):
+ svc.send("Title", "Body", service_urls="file:///etc/passwd")
+
+ def test_apprise_add_fails_returns_false(self):
+ svc = _make_service()
+
+ mock_validator = MagicMock()
+ mock_validator.validate_multiple_urls.return_value = (True, None)
+
+ mock_apprise_mod = MagicMock()
+ temp_instance = MagicMock()
+ temp_instance.add.return_value = False
+ mock_apprise_mod.Apprise.return_value = temp_instance
+
+ with (
+ patch(f"{MODULE}.NotificationURLValidator", mock_validator),
+ patch(f"{MODULE}.apprise", mock_apprise_mod),
+ ):
+ result = svc.send("Title", "Body", service_urls="discord://w/t")
+
+ assert result is False
+
+ def test_no_services_configured_returns_false(self):
+ svc = _make_service()
+ svc.apprise.__len__ = MagicMock(return_value=0)
+
+ result = svc.send("Title", "Body")
+ assert result is False
+
+
+# ===========================================================================
+# _validate_url
+# ===========================================================================
+
+
+class TestValidateUrlStatic:
+ def test_empty_raises(self):
+ with pytest.raises(ServiceError, match="non-empty"):
+ NotificationService._validate_url("")
+
+ def test_none_raises(self):
+ with pytest.raises(ServiceError, match="non-empty"):
+ NotificationService._validate_url(None)
+
+ def test_int_raises(self):
+ with pytest.raises(ServiceError, match="non-empty"):
+ NotificationService._validate_url(123)
+
+ def test_no_scheme_raises(self):
+ with pytest.raises(ServiceError, match="Invalid URL"):
+ NotificationService._validate_url("no-scheme-here")
+
+ def test_valid_discord_url(self):
+ NotificationService._validate_url("discord://webhook_id/token")
+
+ def test_valid_mailto_url(self):
+ NotificationService._validate_url("mailto://user:[email protected]")
+
+
+# ===========================================================================
+# get_service_type
+# ===========================================================================
+
+
+class TestGetServiceType:
+ def _get_type(self, url):
+ svc = _make_service()
+ return svc.get_service_type(url)
+
+ def test_discord(self):
+ assert self._get_type("discord://id/token") == "discord"
+
+ def test_slack(self):
+ assert self._get_type("slack://token_a/token_b/token_c") == "slack"
+
+ def test_email(self):
+ assert self._get_type("mailto://user:[email protected]") == "email"
+
+ def test_telegram(self):
+ assert self._get_type("tgram://bot_token/chat_id") == "telegram"
+
+ def test_unknown(self):
+ assert self._get_type("custom://something") == "unknown"
+
+ def test_case_insensitive(self):
+ # Patterns use re.IGNORECASE
+ assert self._get_type("Discord://ID/TOKEN") == "discord"
diff --git a/tests/web/services/test_socket_service_extra_coverage.py b/tests/web/services/test_socket_service_extra_coverage.py
new file mode 100644
index 0000000000..e27e8838dd
--- /dev/null
+++ b/tests/web/services/test_socket_service_extra_coverage.py
@@ -0,0 +1,238 @@
+"""Extra coverage tests for socket_service.py — private event handlers and logging."""
+
+from unittest.mock import MagicMock, patch
+
+
+MODULE = "local_deep_research.web.services.socket_service"
+
+
+def _get_service_with_patched_init():
+ """Get a SocketIOService instance bypassing singleton + Flask requirement."""
+ from local_deep_research.web.services.socket_service import SocketIOService
+
+ with patch.object(
+ SocketIOService, "__new__", lambda cls, *a, **kw: object.__new__(cls)
+ ):
+ svc = object.__new__(SocketIOService)
+
+ svc._SocketIOService__socket_subscriptions = {}
+ svc._SocketIOService__lock = __import__("threading").Lock()
+ svc._SocketIOService__socketio = MagicMock()
+ svc._SocketIOService__logging_enabled = True
+ return svc
+
+
+# ===========================================================================
+# __handle_connect
+# ===========================================================================
+
+
+class TestHandleConnect:
+ def test_logs_connection(self):
+ svc = _get_service_with_patched_init()
+ mock_request = MagicMock()
+ mock_request.sid = "client-123"
+
+ # Should not raise
+ svc._SocketIOService__handle_connect(mock_request)
+
+
+# ===========================================================================
+# __handle_disconnect
+# ===========================================================================
+
+
+class TestHandleDisconnect:
+ def test_removes_subscription(self):
+ svc = _get_service_with_patched_init()
+ svc._SocketIOService__socket_subscriptions = {
+ "res-1": {"client-1", "client-2"},
+ "res-2": {"client-1"},
+ }
+
+ mock_request = MagicMock()
+ mock_request.sid = "client-1"
+
+ with patch(f"{MODULE}.cleanup_current_thread", create=True):
+ svc._SocketIOService__handle_disconnect(
+ mock_request, "transport close"
+ )
+
+ assert "client-1" not in svc._SocketIOService__socket_subscriptions.get(
+ "res-1", set()
+ )
+ # res-2 should be cleaned up entirely since no clients left
+ assert "res-2" not in svc._SocketIOService__socket_subscriptions
+
+ def test_empty_subscriptions_handled(self):
+ svc = _get_service_with_patched_init()
+ mock_request = MagicMock()
+ mock_request.sid = "unknown-client"
+
+ with patch(f"{MODULE}.cleanup_current_thread", create=True):
+ svc._SocketIOService__handle_disconnect(mock_request, "timeout")
+
+ def test_cleanup_import_error_swallowed(self):
+ svc = _get_service_with_patched_init()
+ mock_request = MagicMock()
+ mock_request.sid = "client-1"
+
+ with patch.dict(
+ "sys.modules",
+ {"local_deep_research.database.thread_local_session": None},
+ ):
+ svc._SocketIOService__handle_disconnect(mock_request, "close")
+
+ def test_cleanup_exception_swallowed(self):
+ svc = _get_service_with_patched_init()
+ mock_request = MagicMock()
+ mock_request.sid = "client-1"
+
+ mock_mod = MagicMock()
+ mock_mod.cleanup_current_thread.side_effect = RuntimeError(
+ "cleanup fail"
+ )
+
+ with patch.dict(
+ "sys.modules",
+ {"local_deep_research.database.thread_local_session": mock_mod},
+ ):
+ svc._SocketIOService__handle_disconnect(mock_request, "close")
+
+ def test_outer_exception_swallowed(self):
+ svc = _get_service_with_patched_init()
+ # Make the lock acquisition fail
+ svc._SocketIOService__lock = MagicMock()
+ svc._SocketIOService__lock.__enter__ = MagicMock(
+ side_effect=RuntimeError("lock fail")
+ )
+ svc._SocketIOService__lock.__exit__ = MagicMock(return_value=False)
+
+ mock_request = MagicMock()
+ mock_request.sid = "client-1"
+
+ # Should not raise
+ svc._SocketIOService__handle_disconnect(mock_request, "error")
+
+
+# ===========================================================================
+# __handle_subscribe
+# ===========================================================================
+
+
+class TestHandleSubscribe:
+ def test_adds_subscriber(self):
+ svc = _get_service_with_patched_init()
+ mock_request = MagicMock()
+ mock_request.sid = "client-1"
+
+ with patch(f"{MODULE}.get_active_research_snapshot", return_value=None):
+ svc._SocketIOService__handle_subscribe(
+ {"research_id": "res-1"}, mock_request
+ )
+
+ assert "client-1" in svc._SocketIOService__socket_subscriptions["res-1"]
+
+ def test_sends_current_status_when_available(self):
+ svc = _get_service_with_patched_init()
+ mock_request = MagicMock()
+ mock_request.sid = "client-1"
+
+ snapshot = {
+ "progress": 50,
+ "log": [{"message": "Searching...", "phase": "search"}],
+ }
+
+ with patch(
+ f"{MODULE}.get_active_research_snapshot", return_value=snapshot
+ ):
+ svc._SocketIOService__handle_subscribe(
+ {"research_id": "res-1"}, mock_request
+ )
+
+ svc._SocketIOService__socketio.emit.assert_called()
+
+ def test_no_status_when_snapshot_none(self):
+ svc = _get_service_with_patched_init()
+ mock_request = MagicMock()
+ mock_request.sid = "client-1"
+
+ with patch(f"{MODULE}.get_active_research_snapshot", return_value=None):
+ svc._SocketIOService__handle_subscribe(
+ {"research_id": "res-1"}, mock_request
+ )
+
+ svc._SocketIOService__socketio.emit.assert_not_called()
+
+ def test_empty_log_no_emit(self):
+ svc = _get_service_with_patched_init()
+ mock_request = MagicMock()
+ mock_request.sid = "client-1"
+
+ snapshot = {"progress": 0, "log": []}
+
+ with patch(
+ f"{MODULE}.get_active_research_snapshot", return_value=snapshot
+ ):
+ svc._SocketIOService__handle_subscribe(
+ {"research_id": "res-1"}, mock_request
+ )
+
+ svc._SocketIOService__socketio.emit.assert_not_called()
+
+ def test_no_research_id_ignored(self):
+ svc = _get_service_with_patched_init()
+ mock_request = MagicMock()
+
+ svc._SocketIOService__handle_subscribe({}, mock_request)
+
+ assert len(svc._SocketIOService__socket_subscriptions) == 0
+
+
+# ===========================================================================
+# __handle_socket_error / __handle_default_error
+# ===========================================================================
+
+
+class TestErrorHandlers:
+ def test_socket_error_returns_false(self):
+ svc = _get_service_with_patched_init()
+ result = svc._SocketIOService__handle_socket_error(RuntimeError("test"))
+ assert result is False
+
+ def test_default_error_returns_false(self):
+ svc = _get_service_with_patched_init()
+ result = svc._SocketIOService__handle_default_error(ValueError("test"))
+ assert result is False
+
+
+# ===========================================================================
+# __log_info / __log_error / __log_exception — logging control
+# ===========================================================================
+
+
+class TestLoggingControl:
+ def test_log_info_when_enabled(self):
+ svc = _get_service_with_patched_init()
+ svc._SocketIOService__logging_enabled = True
+ svc._SocketIOService__log_info("test message")
+
+ def test_log_info_when_disabled(self):
+ svc = _get_service_with_patched_init()
+ svc._SocketIOService__logging_enabled = False
+ svc._SocketIOService__log_info("should not log")
+
+ def test_log_error_when_enabled(self):
+ svc = _get_service_with_patched_init()
+ svc._SocketIOService__logging_enabled = True
+ svc._SocketIOService__log_error("error message")
+
+ def test_log_exception_when_enabled(self):
+ svc = _get_service_with_patched_init()
+ svc._SocketIOService__logging_enabled = True
+ svc._SocketIOService__log_exception("exception message")
+
+ def test_log_exception_when_disabled(self):
+ svc = _get_service_with_patched_init()
+ svc._SocketIOService__logging_enabled = False
+ svc._SocketIOService__log_exception("should not log")