~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(search): contract test that engines honor programmatic_mode (#3654)
LearningCircuit78085ecc6372
diff --git a/src/local_deep_research/web_search_engines/search_engine_base.py b/src/local_deep_research/web_search_engines/search_engine_base.pyindex 0e0536c328..f3be58f463 100644--- a/src/local_deep_research/web_search_engines/search_engine_base.py+++ b/src/local_deep_research/web_search_engines/search_engine_base.py@@ -36,6 +36,25 @@ class BaseSearchEngine(ABC):"""Abstract base class for search engines with two-phase retrieval capability.Handles common parameters and implements the two-phase search approach.++ Subclass contract for ``__init__``+ ---------------------------------+ Concrete engines should forward ``settings_snapshot`` and+ ``programmatic_mode`` to ``super().__init__`` so the base class can wire+ them up correctly. The cleanest way is to declare ``**kwargs`` and pass+ it along::++ def __init__(self, max_results=10, *, my_param=None, **kwargs):+ super().__init__(max_results=max_results, **kwargs)+ self.my_param = my_param++ Many existing engines accept ``**kwargs`` but don't forward — that+ silently drops ``programmatic_mode`` (and used to bind the wrong rate+ tracker). The factory has a post-construction safety net that calls+ ``_configure_programmatic_mode`` when the engine's mode doesn't match+ what the caller asked for, but new engines should not rely on it: the+ safety net only covers ``programmatic_mode``, not ``settings_snapshot``+ or other base kwargs."""# Class attribute to indicate if this engine searches public internet sourcesdiff --git a/tests/web_search_engines/test_search_engine_factory_coverage.py b/tests/web_search_engines/test_search_engine_factory_coverage.pyindex 52daa48f77..2cbddae2c2 100644--- a/tests/web_search_engines/test_search_engine_factory_coverage.py+++ b/tests/web_search_engines/test_search_engine_factory_coverage.py@@ -1380,3 +1380,106 @@ class TestProgrammaticModePostConstructionPatch:assert result is not Noneassert result.programmatic_mode is True+++# ---------------------------------------------------------------------------+# Tests: factory enforces programmatic_mode regardless of subclass __init__+# pattern. Three patterns exist in the wild — see the Subclass contract+# section in BaseSearchEngine for the recommended approach.+# ---------------------------------------------------------------------------+++class TestProgrammaticModeContract:+ """Factory must produce the requested ``programmatic_mode`` regardless+ of how an engine subclass handles its kwargs:++ 1. ``swallow_no_forward``: Serper/Tavily/Wikipedia pattern. Subclass+ accepts ``**kwargs`` but doesn't forward them to ``super().__init__``.+ The factory's post-construction patch is the safety net here.+ 2. ``forward_kwargs``: Subclass accepts ``**kwargs`` and forwards them.+ The base ``__init__`` sets ``programmatic_mode`` directly.+ 3. ``named_param``: Subclass names ``programmatic_mode`` explicitly+ in its signature and forwards it. Base handles it during init."""++ @pytest.mark.parametrize(+ "swallow_pattern",+ ["swallow_no_forward", "forward_kwargs", "named_param"],+ )+ def test_factory_enforces_programmatic_mode_across_swallow_patterns(+ self, swallow_pattern+ ):+ from local_deep_research.web_search_engines.search_engine_base import (+ BaseSearchEngine,+ )+ from local_deep_research.web_search_engines.search_engine_factory import (+ create_search_engine,+ )++ if swallow_pattern == "swallow_no_forward":++ class _Eng(BaseSearchEngine):+ def __init__(self, max_results: int = 10, **kwargs):+ super().__init__(max_results=max_results)++ def _get_previews(self, query):+ return []++ def _get_full_content(self, items):+ return items++ elif swallow_pattern == "forward_kwargs":++ class _Eng(BaseSearchEngine): # type: ignore[no-redef]+ def __init__(self, max_results: int = 10, **kwargs):+ super().__init__(max_results=max_results, **kwargs)++ def _get_previews(self, query):+ return []++ def _get_full_content(self, items):+ return items++ else: # named_param++ class _Eng(BaseSearchEngine): # type: ignore[no-redef]+ def __init__(+ self,+ max_results: int = 10,+ programmatic_mode: bool = False,+ **kwargs,+ ):+ super().__init__(+ max_results=max_results,+ programmatic_mode=programmatic_mode,+ )++ def _get_previews(self, query):+ return []++ def _get_full_content(self, items):+ return items++ with _patches(+ config_return={"eng": _engine_config()},+ class_return=_Eng,+ ):+ result = create_search_engine(+ "eng",+ settings_snapshot={"x": 1},+ programmatic_mode=True,+ )++ from local_deep_research.web_search_engines.rate_limiting.tracker import (+ AdaptiveRateLimitTracker,+ )++ assert result is not None+ assert result.programmatic_mode is True, (+ f"Pattern {swallow_pattern!r}: factory did not enforce "+ f"programmatic_mode=True"+ )+ assert isinstance(result.rate_tracker, AdaptiveRateLimitTracker), (+ f"Pattern {swallow_pattern!r}: rate_tracker should be the "+ f"per-instance AdaptiveRateLimitTracker, got "+ f"{type(result.rate_tracker).__name__}"+ )