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.

fix: correct test quality bugs and env var pollution (#2976)

LearningCircuit13e7cdb2f119
diff --git a/tests/research_library/routes/test_rag_routes.py b/tests/research_library/routes/test_rag_routes.py
index 12162af2d4..395a977ebe 100644
--- a/tests/research_library/routes/test_rag_routes.py
+++ b/tests/research_library/routes/test_rag_routes.py
@@ -25,13 +25,13 @@ class TestGetAutoIndexExecutor:
# Reset global state
rag_routes._auto_index_executor = None
- executor = rag_routes._get_auto_index_executor()
+ try:
+ executor = rag_routes._get_auto_index_executor()
- assert executor is not None
- assert rag_routes._auto_index_executor is not None
-
- # Cleanup
- rag_routes._shutdown_auto_index_executor()
+ assert executor is not None
+ assert rag_routes._auto_index_executor is not None
+ finally:
+ rag_routes._shutdown_auto_index_executor()
def test_executor_reused(self):
"""Test that executor is reused on subsequent calls."""
@@ -40,13 +40,13 @@ class TestGetAutoIndexExecutor:
# Reset global state
rag_routes._auto_index_executor = None
- executor1 = rag_routes._get_auto_index_executor()
- executor2 = rag_routes._get_auto_index_executor()
+ try:
+ executor1 = rag_routes._get_auto_index_executor()
+ executor2 = rag_routes._get_auto_index_executor()
- assert executor1 is executor2
-
- # Cleanup
- rag_routes._shutdown_auto_index_executor()
+ assert executor1 is executor2
+ finally:
+ rag_routes._shutdown_auto_index_executor()
class TestShutdownAutoIndexExecutor:
diff --git a/tests/research_library/routes/test_rag_routes_deep_coverage.py b/tests/research_library/routes/test_rag_routes_deep_coverage.py
index 146439bf77..148ac3bb8c 100644
--- a/tests/research_library/routes/test_rag_routes_deep_coverage.py
+++ b/tests/research_library/routes/test_rag_routes_deep_coverage.py
@@ -27,7 +27,7 @@ Covers:
import uuid
from contextlib import contextmanager
from io import BytesIO
-from unittest.mock import MagicMock, Mock, patch
+from unittest.mock import ANY, MagicMock, Mock, patch
import pytest
from flask import Flask, jsonify
@@ -130,7 +130,6 @@ def _make_settings_mock(overrides=None):
mock_sm.get_bool_setting.side_effect = lambda k, d=False, **kw: bool(
defaults.get(k, d)
)
- mock_sm.get_bool_setting.side_effect = lambda k, d=None: defaults.get(k, d)
mock_sm.get_all_settings.return_value = {}
mock_sm.set_setting = Mock()
mock_sm.get_settings_snapshot.return_value = {}
@@ -468,8 +467,12 @@ class TestAutoIndexDocumentsWorker:
mock_service.__exit__ = Mock(return_value=False)
mock_service.index_document.return_value = {"status": "skipped"}
- with patch(
- f"{MODULE}._get_rag_service_for_thread", return_value=mock_service
+ with (
+ patch(
+ f"{MODULE}._get_rag_service_for_thread",
+ return_value=mock_service,
+ ),
+ patch(f"{MODULE}.thread_cleanup", lambda f: f),
):
_auto_index_documents_worker(["doc1"], "coll-1", "user", "pass")
@@ -611,9 +614,7 @@ class TestBackgroundIndexWorker:
# Last call should be the failure update
last_call = mock_update.call_args
- assert last_call.kwargs.get("status") == "failed" or (
- len(last_call.args) > 3 and "failed" in str(last_call)
- )
+ assert last_call.kwargs.get("status") == "failed"
# ---------------------------------------------------------------------------
@@ -842,6 +843,8 @@ class TestUploadPdfStorageDatabase:
"db-password-123"
)
+ mock_trigger = Mock()
+
with _auth_client(
app,
mock_db_session=db_session,
@@ -859,7 +862,7 @@ class TestUploadPdfStorageDatabase:
patch(
f"{_DB_PASS}.session_password_store", mock_password_store
),
- patch(f"{MODULE}.trigger_auto_index"),
+ patch(f"{MODULE}.trigger_auto_index", mock_trigger),
],
) as (client, ctx):
data = {"files": (BytesIO(b"text content"), "doc.txt")}
@@ -869,6 +872,9 @@ class TestUploadPdfStorageDatabase:
content_type="multipart/form-data",
)
assert resp.status_code == 200
+ mock_trigger.assert_called_once_with(
+ ANY, "coll-1", ANY, "db-password-123"
+ )
def test_upload_pdf_save_failure_continues(self, app):
"""Upload continues even if PDF save to database fails."""
diff --git a/tests/test_ci_config.py b/tests/test_ci_config.py
deleted file mode 100644
index 74eca814b2..0000000000
--- a/tests/test_ci_config.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# allow: no-sut-import — not a test module; CI env-setup helper that only sets os.environ, no SUT to import
-"""
-CI-specific test configuration for API tests.
-Sets up environment for tests to run without external LLM services.
-"""
-
-import os
-
-# Set environment variables for CI testing
-os.environ["LDR_TESTING_MODE"] = "true"
-
-# Disable all external LLM providers
-os.environ["LDR_DISABLE_OLLAMA"] = "true"
-os.environ["LDR_DISABLE_OPENAI"] = "true"
-os.environ["LDR_DISABLE_ANTHROPIC"] = "true"
-
-# Set test-specific configurations
-os.environ["LDR_LLM_TIMEOUT"] = "5" # Shorter timeout for tests
-os.environ["LDR_SEARCH_TIMEOUT"] = "5" # Shorter timeout for searches