~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
refactor: extract has_legacy_customizations() to reduce duplication (#2675)
LearningCircuite99a0ec3d9fb
diff --git a/src/local_deep_research/web/server_config.py b/src/local_deep_research/web/server_config.pyindex c3364adec7..51f238f7fe 100644--- a/src/local_deep_research/web/server_config.py+++ b/src/local_deep_research/web/server_config.py@@ -12,7 +12,7 @@ written back to the JSON file.import jsonimport osfrom pathlib import Path-from typing import Any, Dict+from typing import Any, Dict, Optionalfrom loguru import logger@@ -71,6 +71,30 @@ def get_server_config_path() -> Path:return Path(get_data_dir()) / "server_config.json"+def has_legacy_customizations(config_path: Optional[Path] = None) -> bool:+ """Return True if server_config.json exists with non-default values.++ Parameters+ ----------+ config_path : Path, optional+ Path to the legacy JSON file. Defaults to get_server_config_path().+ """+ path = config_path or get_server_config_path()+ if not path.exists():+ return False+ try:+ data = json.loads(path.read_text(encoding="utf-8-sig"))+ except (json.JSONDecodeError, OSError, UnicodeDecodeError):+ return False+ if not isinstance(data, dict):+ return False+ for json_key in _LEGACY_KEY_MAP:+ if json_key in data and data[json_key] != _DEFAULTS.get(json_key):+ return True+ unrecognized = set(data.keys()) - set(_LEGACY_KEY_MAP.keys())+ return bool(unrecognized)++def _load_legacy_config() -> Dict[str, Any]:"""Read legacy server_config.json as a read-only migration fallback.diff --git a/src/local_deep_research/web/warning_checks/hardware.py b/src/local_deep_research/web/warning_checks/hardware.pyindex df8393e4fa..4c8473d692 100644--- a/src/local_deep_research/web/warning_checks/hardware.py+++ b/src/local_deep_research/web/warning_checks/hardware.py@@ -63,45 +63,12 @@ def check_model_mismatch(def check_legacy_server_config(dismissed: bool) -> Optional[dict]:"""Return a warning only if server_config.json has non-default values."""- from ..server_config import (- _DEFAULTS,- _LEGACY_KEY_MAP,- get_server_config_path,- )+ from ..server_config import has_legacy_customizationsif dismissed:return None-- config_path = get_server_config_path()- if not config_path.exists():- return None-- # Load and compare against defaults — only warn if user customized something- import json-- try:- data = json.loads(config_path.read_text(encoding="utf-8-sig"))- except (json.JSONDecodeError, OSError):- return None-- if not isinstance(data, dict):+ if not has_legacy_customizations():return None-- has_customization = False- for json_key in _LEGACY_KEY_MAP:- if json_key in data and data[json_key] != _DEFAULTS.get(json_key):- has_customization = True- break-- # Also flag unrecognized keys as customizations- if not has_customization:- unrecognized = set(data.keys()) - set(_LEGACY_KEY_MAP.keys())- if unrecognized:- has_customization = True-- if not has_customization:- return None-return {"type": "legacy_server_config","icon": "ℹ️",diff --git a/tests/web/test_server_config.py b/tests/web/test_server_config.pyindex 17ca3eaff1..f53e4c2635 100644--- a/tests/web/test_server_config.py+++ b/tests/web/test_server_config.py@@ -14,6 +14,7 @@ import pytestfrom local_deep_research.web.server_config import (get_server_config_path,+ has_legacy_customizations,load_server_config,)@@ -593,3 +594,34 @@ class TestLegacyAllowRegistrationsFailClosed:assert not any("Legacy server_config.json" in call for call in warning_calls)+++# ===================================================================+# has_legacy_customizations — direct tests using config_path parameter+# ===================================================================+class TestHasLegacyCustomizations:+ """Tests for has_legacy_customizations helper."""++ def test_returns_false_when_no_file(self, tmp_path):+ """Non-existent path should return False."""+ assert has_legacy_customizations(tmp_path / "nope.json") is False++ def test_returns_true_when_non_default_value(self, tmp_path):+ """File with a non-default value should return True."""+ cfg = tmp_path / "server_config.json"+ cfg.write_text('{"port": 9999}', encoding="utf-8")+ assert has_legacy_customizations(cfg) is True++ def test_returns_false_when_all_defaults(self, tmp_path):+ """File with all default values should return False."""+ from local_deep_research.web.server_config import _DEFAULTS++ cfg = tmp_path / "server_config.json"+ cfg.write_text(json.dumps(_DEFAULTS), encoding="utf-8")+ assert has_legacy_customizations(cfg) is False++ def test_returns_false_on_malformed_json(self, tmp_path):+ """Malformed JSON should return False, not raise."""+ cfg = tmp_path / "server_config.json"+ cfg.write_text("not valid json", encoding="utf-8")+ assert has_legacy_customizations(cfg) is Falsediff --git a/tests/web/warning_checks/test_hardware.py b/tests/web/warning_checks/test_hardware.pyindex 95c00df1b3..6c847f9ec2 100644--- a/tests/web/warning_checks/test_hardware.py+++ b/tests/web/warning_checks/test_hardware.py@@ -263,3 +263,62 @@ class TestCheckLegacyServerConfig:return_value=config_file,):assert check_legacy_server_config(dismissed=False) is None++ def test_warns_with_partial_defaults_and_one_custom(self, tmp_path):+ """Mix of default and non-default values — should warn on the mismatch."""+ import json++ config_file = tmp_path / "server_config.json"+ config_file.write_text(+ json.dumps({"host": "0.0.0.0", "port": 5000, "debug": True}),+ encoding="utf-8",+ )+ with patch(+ "local_deep_research.web.server_config.get_server_config_path",+ return_value=config_file,+ ):+ result = check_legacy_server_config(dismissed=False)+ assert result is not None+ assert result["type"] == "legacy_server_config"++ def test_warns_unrecognized_keys_with_default_recognized(self, tmp_path):+ """All recognized keys match defaults but an unknown key exists — should warn."""+ import json++ from local_deep_research.web.server_config import _DEFAULTS++ data = dict(_DEFAULTS)+ data["unknown"] = "val"+ config_file = tmp_path / "server_config.json"+ config_file.write_text(json.dumps(data), encoding="utf-8")+ with patch(+ "local_deep_research.web.server_config.get_server_config_path",+ return_value=config_file,+ ):+ result = check_legacy_server_config(dismissed=False)+ assert result is not None+ assert result["type"] == "legacy_server_config"++ def test_warns_when_value_is_none(self, tmp_path):+ """null value differs from default — should warn."""+ config_file = tmp_path / "server_config.json"+ config_file.write_text('{"port": null}', encoding="utf-8")+ with patch(+ "local_deep_research.web.server_config.get_server_config_path",+ return_value=config_file,+ ):+ result = check_legacy_server_config(dismissed=False)+ assert result is not None+ assert result["type"] == "legacy_server_config"++ def test_warns_when_type_differs_from_default(self, tmp_path):+ """String '5000' != int 5000 — strict comparison should catch this."""+ config_file = tmp_path / "server_config.json"+ config_file.write_text('{"port": "5000"}', encoding="utf-8")+ with patch(+ "local_deep_research.web.server_config.get_server_config_path",+ return_value=config_file,+ ):+ result = check_legacy_server_config(dismissed=False)+ assert result is not None+ assert result["type"] == "legacy_server_config"