~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(api): endpoint-completeness meta-test + autospec real-path factories (follow-up to #3661) (#4521)
LearningCircuit0fc06b2ab5e0
diff --git a/tests/web/test_api_coverage.py b/tests/web/test_api_coverage.pyindex 2a791b6127..c05b8a533d 100644--- a/tests/web/test_api_coverage.py+++ b/tests/web/test_api_coverage.py@@ -1134,12 +1134,18 @@ class TestRestToResearchFunctionCallPath:with _mock_access_control():with (+ # autospec=True so analyze_documents' calls into+ # get_llm/get_search are validated against the real+ # signatures — same kwargs-swallowing blind spot the+ # endpoint-level tests close, one layer down.patch("local_deep_research.api.research_functions.get_llm",+ autospec=True,return_value=mock_llm,),patch("local_deep_research.api.research_functions.get_search",+ autospec=True,return_value=mock_search,),):@@ -1192,12 +1198,16 @@ class TestRestToResearchFunctionCallPath:with _mock_access_control():with (+ # autospec=True validates analyze_documents' calls into+ # get_llm/get_search against the real signatures.patch("local_deep_research.api.research_functions.get_llm",+ autospec=True,return_value=mock_llm,),patch("local_deep_research.api.research_functions.get_search",+ autospec=True,return_value=mock_search,),):@@ -1335,12 +1345,16 @@ class TestRestToResearchFunctionCallPath:with _mock_access_control():with (+ # autospec=True validates analyze_documents' calls into+ # get_llm/get_search against the real signatures.patch("local_deep_research.api.research_functions.get_llm",+ autospec=True,return_value=mock_llm,),patch("local_deep_research.api.research_functions.get_search",+ autospec=True,return_value=mock_search,),patch(@@ -1441,6 +1455,136 @@ class TestResearchFunctionSignatures:)+# ===================================================================+# Endpoint completeness: every research endpoint threads user context+# ===================================================================+++# Contract registry for TestEndpointUserContextCompleteness. Maps each+# POST view function on the api_v1 blueprint to (patch target for its+# research function, minimal valid request body, stub return value).+# A NEW POST endpoint added to the blueprint fails+# test_every_post_endpoint_has_contract until it gets an entry here —+# which routes it through test_endpoint_threads_user_context and+# therefore through _load_user_context_into_params. See the contract+# comment above that helper in src/local_deep_research/web/api.py.+#+# Escape hatch: an endpoint that genuinely calls NO research function+# maps to None, with a comment on its entry explaining why — the+# exemption is then visible and reviewable here instead of the endpoint+# being silently absent. None entries are skipped by+# test_endpoint_threads_user_context but still checked for staleness.+_ENDPOINT_CONTRACTS = {+ "api_quick_summary": (+ "local_deep_research.api.research_functions.quick_summary",+ {"query": "q"},+ {"findings": []},+ ),+ "api_generate_report": (+ "local_deep_research.api.research_functions.generate_report",+ {"query": "q"},+ {"content": "ok"},+ ),+ "api_analyze_documents": (+ # analyze_documents is imported at module level in web.api, so+ # the patch target is the web.api binding, not research_functions.+ "local_deep_research.web.api.analyze_documents",+ {"query": "q", "collection_name": "c"},+ {},+ ),+}+++class TestEndpointUserContextCompleteness:+ """Guard against the next variant of the original #3661 bug: a NEW+ endpoint that calls a research function but never loads the user's+ encrypted-DB context.++ The per-endpoint contract tests above can only cover endpoints that+ exist today. This class iterates the api_v1 blueprint's actual URL+ map (not the route registry, which could drift from the blueprint),+ so a POST endpoint added to the blueprint without a contract entry+ fails loudly here instead of shipping silently uncovered.+ """++ @staticmethod+ def _post_view_names(app):+ return sorted(+ rule.endpoint.removeprefix("api_v1.")+ for rule in app.url_map.iter_rules()+ if rule.endpoint.startswith("api_v1.") and "POST" in rule.methods+ )++ def test_every_post_endpoint_has_contract(self, app):+ missing = [+ name+ for name in self._post_view_names(app)+ if name not in _ENDPOINT_CONTRACTS+ ]+ assert not missing, (+ f"POST endpoint(s) on the api_v1 blueprint have no entry in "+ f"_ENDPOINT_CONTRACTS: {missing}. Every research-calling REST "+ f"endpoint must invoke _load_user_context_into_params (see the "+ f"contract comment in web/api.py) and be wired into this "+ f"contract registry so test_endpoint_threads_user_context "+ f"verifies the user's context actually reaches the research "+ f"function. If the new endpoint genuinely calls no research "+ f"function, map it to None with a comment explaining why."+ )++ def test_no_stale_contract_entries(self, app):+ registered = set(self._post_view_names(app))+ stale = [name for name in _ENDPOINT_CONTRACTS if name not in registered]+ assert not stale, (+ f"_ENDPOINT_CONTRACTS lists endpoint(s) that no longer exist "+ f"on the api_v1 blueprint: {stale}. Remove their entries."+ )++ @pytest.mark.parametrize(+ "view_name",+ sorted(+ name+ for name, contract in _ENDPOINT_CONTRACTS.items()+ if contract is not None+ ),+ )+ def test_endpoint_threads_user_context(self, authed_client, app, view_name):+ """Generic contract: an authenticated POST to the endpoint must+ deliver username, the user's settings snapshot (tracer key from+ _mock_access_control), and programmatic_mode=False to its+ research function."""+ patch_target, body, stub_return = _ENDPOINT_CONTRACTS[view_name]+ rule = next(+ r+ for r in app.url_map.iter_rules()+ if r.endpoint == f"api_v1.{view_name}"+ )++ with _mock_access_control():+ with patch(patch_target, return_value=stub_return) as mock_fn:+ resp = authed_client.post(rule.rule, json=body)+ assert resp.status_code == 200, (+ f"{view_name} returned {resp.status_code}: "+ f"{resp.get_data(as_text=True)}"+ )+ kwargs = mock_fn.call_args.kwargs+ assert kwargs.get("username") == "testuser", (+ f"{view_name} did not pass the authenticated username "+ f"to its research function"+ )+ assert kwargs.get("programmatic_mode") is False, (+ f"{view_name} did not pass programmatic_mode=False"+ )+ snapshot = kwargs.get("settings_snapshot")+ assert snapshot is not None, (+ f"{view_name} did not pass settings_snapshot"+ )+ assert snapshot.get("_ldr_test_tracer") == "tracer-value", (+ f"{view_name} passed a settings_snapshot that is not "+ f"the user's snapshot. Got: {snapshot!r}"+ )++# ===================================================================# _serialize_results helper# ===================================================================