~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
test: add 40 tests for paths, multiselect parsing, domain extraction, and notifications (round 16) (#2649)
LearningCircuit8901d81294f0
diff --git a/tests/config/test_paths_unit.py b/tests/config/test_paths_unit.pynew file mode 100644index 0000000000..16730b6f56--- /dev/null+++ b/tests/config/test_paths_unit.py@@ -0,0 +1,103 @@+"""+Tests for get_user_database_filename() and get_data_directory() in paths.py.++Covers SHA-256 hash-based filename generation and LDR_DATA_DIR env var override.+"""++import hashlib+from pathlib import Path+from unittest.mock import patch+++def _get_user_db_fn():+ from local_deep_research.config.paths import get_user_database_filename++ return get_user_database_filename+++def _get_data_dir_fn():+ from local_deep_research.config.paths import get_data_directory++ return get_data_directory+++class TestGetUserDatabaseFilename:+ """Tests for get_user_database_filename()."""++ def test_basic_username(self):+ expected_hash = hashlib.sha256("alice".encode()).hexdigest()[:16]+ result = _get_user_db_fn()("alice")+ assert result == f"ldr_user_{expected_hash}.db"++ def test_deterministic(self):+ fn = _get_user_db_fn()+ assert fn("alice") == fn("alice")++ def test_different_users_different_filenames(self):+ fn = _get_user_db_fn()+ assert fn("alice") != fn("bob")++ def test_case_sensitive(self):+ fn = _get_user_db_fn()+ assert fn("Alice") != fn("alice")++ def test_special_characters_safe(self):+ result = _get_user_db_fn()("[email protected]")+ assert "@" not in result+ assert result.startswith("ldr_user_")+ assert result.endswith(".db")++ def test_unicode_username(self):+ result = _get_user_db_fn()("用户")+ assert result.startswith("ldr_user_")+ assert result.endswith(".db")+ # Extract hash portion and verify it's 16-char hex+ hash_part = result[len("ldr_user_") : -len(".db")]+ assert len(hash_part) == 16+ assert all(c in "0123456789abcdef" for c in hash_part)+++class TestGetDataDirectory:+ """Tests for get_data_directory()."""++ def test_ldr_data_dir_set(self, monkeypatch):+ monkeypatch.setenv("LDR_DATA_DIR", "/tmp/custom")+ result = _get_data_dir_fn()()+ assert result == Path("/tmp/custom")++ def test_ldr_data_dir_empty_falls_through(self, monkeypatch):+ monkeypatch.setenv("LDR_DATA_DIR", "")+ with patch(+ "local_deep_research.config.paths.platformdirs.user_data_dir",+ return_value="/fake/platformdirs/local-deep-research",+ ):+ result = _get_data_dir_fn()()+ assert "local-deep-research" in str(result)++ def test_ldr_data_dir_unset_uses_platformdirs(self, monkeypatch):+ monkeypatch.delenv("LDR_DATA_DIR", raising=False)+ with patch(+ "local_deep_research.config.paths.platformdirs.user_data_dir",+ return_value="/fake/platformdirs/local-deep-research",+ ):+ result = _get_data_dir_fn()()+ assert result == Path("/fake/platformdirs/local-deep-research")++ def test_returns_path_object(self, monkeypatch):+ monkeypatch.setenv("LDR_DATA_DIR", "/tmp/test")+ result = _get_data_dir_fn()()+ assert isinstance(result, Path)++ def test_platformdirs_path_contains_app_name(self, monkeypatch):+ monkeypatch.delenv("LDR_DATA_DIR", raising=False)+ with patch(+ "local_deep_research.config.paths.platformdirs.user_data_dir",+ return_value="/home/user/.local/share/local-deep-research",+ ):+ result = _get_data_dir_fn()()+ assert "local-deep-research" in str(result)++ def test_ldr_data_dir_with_spaces(self, monkeypatch):+ monkeypatch.setenv("LDR_DATA_DIR", "/tmp/my data")+ result = _get_data_dir_fn()()+ assert result == Path("/tmp/my data")diff --git a/tests/notifications/test_service_edge_cases.py b/tests/notifications/test_service_edge_cases.pynew file mode 100644index 0000000000..4f30e4b3fc--- /dev/null+++ b/tests/notifications/test_service_edge_cases.py@@ -0,0 +1,114 @@+"""+Tests for NotificationService edge cases: test_service() error paths+and get_service_type() pattern coverage.+"""++from unittest.mock import patch, MagicMock++from local_deep_research.notifications.service import NotificationService+++class TestTestServiceErrorPaths:+ """Tests for test_service() error branches."""++ @patch("local_deep_research.notifications.service.apprise.Apprise")+ @patch(+ "local_deep_research.notifications.service.NotificationURLValidator.validate_service_url",+ return_value=(False, "blocked by SSRF check"),+ )+ def test_ssrf_validation_fails(self, mock_validator, mock_apprise_class):+ service = NotificationService()+ result = service.test_service("http://169.254.169.254/metadata")+ assert result["success"] is False+ assert "Invalid" in result["error"]++ @patch("local_deep_research.notifications.service.apprise.Apprise")+ @patch(+ "local_deep_research.notifications.service.NotificationURLValidator.validate_service_url",+ return_value=(True, None),+ )+ def test_apprise_add_fails(self, mock_validator, mock_apprise_class):+ mock_instance = MagicMock()+ mock_instance.add.return_value = False+ mock_apprise_class.return_value = mock_instance++ service = NotificationService()+ result = service.test_service("discord://webhook/token")+ assert result["success"] is False+ assert "Failed to add" in result["error"]++ @patch("local_deep_research.notifications.service.apprise.Apprise")+ @patch(+ "local_deep_research.notifications.service.NotificationURLValidator.validate_service_url",+ return_value=(True, None),+ )+ def test_apprise_notify_fails(self, mock_validator, mock_apprise_class):+ mock_instance = MagicMock()+ mock_instance.add.return_value = True+ mock_instance.notify.return_value = False+ mock_apprise_class.return_value = mock_instance++ service = NotificationService()+ result = service.test_service("discord://webhook/token")+ assert result["success"] is False+ assert "Failed to send" in result["error"]++ @patch("local_deep_research.notifications.service.apprise.Apprise")+ @patch(+ "local_deep_research.notifications.service.NotificationURLValidator.validate_service_url",+ return_value=(True, None),+ )+ def test_success_path(self, mock_validator, mock_apprise_class):+ mock_instance = MagicMock()+ mock_instance.add.return_value = True+ mock_instance.notify.return_value = True+ mock_apprise_class.return_value = mock_instance++ service = NotificationService()+ result = service.test_service("discord://webhook/token")+ assert result["success"] is True+ assert "successfully" in result["message"]++ @patch("local_deep_research.notifications.service.apprise.Apprise")+ @patch(+ "local_deep_research.notifications.service.NotificationURLValidator.validate_service_url",+ return_value=(False, "internal DNS resolution error"),+ )+ def test_validation_error_message_not_leaked(+ self, mock_validator, mock_apprise_class+ ):+ service = NotificationService()+ result = service.test_service("http://evil.com")+ assert result["success"] is False+ # Internal error detail should NOT appear in the user-facing message+ assert "internal DNS" not in result["error"]+ assert "Invalid" in result["error"]+++class TestGetServiceTypePatterns:+ """Tests for get_service_type() across all SERVICE_PATTERNS."""++ def test_email_detection(self):+ service = NotificationService()+ assert service.get_service_type("mailto://[email protected]") == "email"++ def test_slack_detection(self):+ service = NotificationService()+ assert (+ service.get_service_type("slack://token_a/token_b/token_c")+ == "slack"+ )++ def test_telegram_detection(self):+ service = NotificationService()+ assert (+ service.get_service_type("tgram://bottoken/chat_id") == "telegram"+ )++ def test_smtp_detection(self):+ service = NotificationService()+ assert service.get_service_type("smtp://user:[email protected]") == "smtp"++ def test_smtps_detection(self):+ service = NotificationService()+ assert service.get_service_type("smtps://user:[email protected]") == "smtp"diff --git a/tests/settings/test_parse_multiselect.py b/tests/settings/test_parse_multiselect.pynew file mode 100644index 0000000000..ccaf3caf3f--- /dev/null+++ b/tests/settings/test_parse_multiselect.py@@ -0,0 +1,46 @@+"""+Tests for _parse_multiselect() in settings/manager.py.++Covers list passthrough, JSON array parsing, comma-separated splitting,+and edge cases (empty, malformed, non-string/list types).+"""++from local_deep_research.settings.manager import _parse_multiselect+++class TestParseMultiselect:+ """Tests for _parse_multiselect()."""++ def test_list_passthrough(self):+ assert _parse_multiselect(["a", "b"]) == ["a", "b"]++ def test_empty_list_passthrough(self):+ assert _parse_multiselect([]) == []++ def test_json_array_string(self):+ assert _parse_multiselect('["markdown","latex"]') == [+ "markdown",+ "latex",+ ]++ def test_json_array_with_spaces(self):+ assert _parse_multiselect(' ["a", "b"] ') == ["a", "b"]++ def test_comma_separated_string(self):+ assert _parse_multiselect("markdown,latex") == ["markdown", "latex"]++ def test_comma_separated_with_spaces(self):+ assert _parse_multiselect(" a , b , c ") == ["a", "b", "c"]++ def test_single_value_no_comma(self):+ assert _parse_multiselect("markdown") == ["markdown"]++ def test_empty_string(self):+ assert _parse_multiselect("") == []++ def test_malformed_json_falls_back_to_comma(self):+ result = _parse_multiselect('["broken')+ assert result == ['["broken']++ def test_non_string_non_list_passthrough(self):+ assert _parse_multiselect(42) == 42diff --git a/tests/web/routes/test_extract_domain.py b/tests/web/routes/test_extract_domain.pynew file mode 100644index 0000000000..a4716696d6--- /dev/null+++ b/tests/web/routes/test_extract_domain.py@@ -0,0 +1,42 @@+"""+Tests for _extract_domain() in metrics_routes.py.++Covers URL parsing, www. stripping, lowercasing, and error handling.+"""++from local_deep_research.web.routes.metrics_routes import _extract_domain+++class TestExtractDomain:+ """Tests for _extract_domain()."""++ def test_normal_https_url(self):+ assert _extract_domain("https://example.com/path") == "example.com"++ def test_strips_www_prefix(self):+ assert _extract_domain("https://www.example.com") == "example.com"++ def test_lowercases_domain(self):+ assert _extract_domain("https://EXAMPLE.COM") == "example.com"++ def test_url_with_port(self):+ assert (+ _extract_domain("https://example.com:8080/path")+ == "example.com:8080"+ )++ def test_empty_string_returns_none(self):+ assert _extract_domain("") is None++ def test_none_input_raises(self):+ """urlparse(None) produces bytes netloc; TypeError not caught."""+ import pytest++ with pytest.raises(TypeError):+ _extract_domain(None)++ def test_path_only_no_netloc_returns_none(self):+ assert _extract_domain("/just/a/path") is None++ def test_subdomain_preserved(self):+ assert _extract_domain("https://api.example.com") == "api.example.com"