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.

test: delete tier-3 dead-code + stdlib shadow + redundant API tests (#4269)

LearningCircuit51d50eee5504
diff --git a/tests/advanced_search_system/strategies/test_topic_organization_strategy.py b/tests/advanced_search_system/strategies/test_topic_organization_strategy.py
index ae073b5d3a..7862f63ecf 100644
--- a/tests/advanced_search_system/strategies/test_topic_organization_strategy.py
+++ b/tests/advanced_search_system/strategies/test_topic_organization_strategy.py
@@ -871,60 +871,3 @@ class TestTextGeneration:
result = strategy._generate_topic_based_text([topic], "test query")
assert len(result) > 0
-
-
-class TestReselectLeadUrlparsing:
- """Tests for URL domain extraction in _reselect_lead_for_single_topic (PR #2020).
-
- PR #2020 changed bare `except:` to `except Exception:` when using
- urlparse to extract domain from source URLs.
- """
-
- def test_valid_url_domain_extraction(self):
- """Should extract domain from valid URL."""
- from urllib.parse import urlparse
-
- url = "https://www.example.com/path/to/resource"
- try:
- domain = urlparse(url).netloc if url else ""
- except Exception:
- domain = ""
-
- assert domain == "www.example.com"
-
- def test_empty_url_returns_empty_domain(self):
- """Should return empty string for empty URL."""
- from urllib.parse import urlparse
-
- url = ""
- try:
- domain = urlparse(url).netloc if url else ""
- except Exception:
- domain = ""
-
- assert domain == ""
-
- def test_none_url_returns_empty_domain(self):
- """Should return empty string for None URL."""
- url = None
- try:
- from urllib.parse import urlparse
-
- domain = urlparse(url).netloc if url else ""
- except Exception:
- domain = ""
-
- assert domain == ""
-
- def test_malformed_url_handled_gracefully(self):
- """Should handle malformed URLs gracefully."""
- from urllib.parse import urlparse
-
- url = "not-a-valid-url"
- try:
- domain = urlparse(url).netloc if url else ""
- except Exception:
- domain = ""
-
- # urlparse handles most strings without raising
- assert isinstance(domain, str)
diff --git a/tests/api_tests/test_research_api_debug.py b/tests/api_tests/test_research_api_debug.py
deleted file mode 100644
index 14dcdfaa34..0000000000
--- a/tests/api_tests/test_research_api_debug.py
+++ /dev/null
@@ -1,375 +0,0 @@
-#!/usr/bin/env python3
-"""
-Debug test for Research API endpoints.
-
-This test specifically helps debug issues with starting research via the API.
-It can be run standalone to diagnose authentication, CSRF, and endpoint issues.
-"""
-
-import json
-import requests
-from bs4 import BeautifulSoup
-import sys
-import time
-
-
-class ResearchAPIDebugTest:
- """Debug test suite for research API endpoints."""
-
- def __init__(self, base_url="http://localhost:5000"):
- self.base_url = base_url
- self.session = requests.Session()
- # Create unique username to avoid conflicts
- timestamp = int(time.time() * 1000)
- self.username = f"testuser_{timestamp}"
- self.password = "TestPass123" # At least 8 characters
-
- def run_all_tests(self):
- """Run all debug tests."""
- print("=== Research API Debug Test ===")
- print(f"Base URL: {self.base_url}")
- print()
-
- # Test server connectivity
- if not self.test_server_connectivity():
- print("❌ Server is not running. Please start the server first.")
- return False
-
- # Test user registration if login fails
- if not self.test_authentication_flow():
- print("🔄 Authentication failed, trying to register user...")
- if not self.test_user_registration():
- print(
- "❌ User registration failed. Cannot proceed with API tests."
- )
- return False
-
- # Try authentication again after registration
- if not self.test_authentication_flow():
- print("❌ Authentication still failed after registration.")
- return False
-
- # Test CSRF token handling
- if not self.test_csrf_tokens():
- print("❌ CSRF token handling failed.")
- return False
-
- # Test research API endpoints
- self.test_research_endpoints()
-
- return True
-
- def test_server_connectivity(self):
- """Test if server is running."""
- print("1. Testing server connectivity...")
- try:
- response = self.session.get(f"{self.base_url}/")
- print(f" Status: {response.status_code}")
- if response.status_code == 200:
- print(" ✅ Server is running")
- return True
- print(f" ❌ Server returned status {response.status_code}")
- return False
- except requests.exceptions.ConnectionError:
- print(" ❌ Cannot connect to server")
- return False
- except Exception as e:
- print(f" ❌ Error: {e}")
- return False
-
- def test_user_registration(self):
- """Test user registration."""
- print("\n2b. Testing user registration...")
-
- try:
- # Get registration page
- register_page = self.session.get(f"{self.base_url}/auth/register")
- print(f" Registration page status: {register_page.status_code}")
-
- if register_page.status_code != 200:
- print(
- f" ❌ Failed to get registration page: {register_page.text[:200]}"
- )
- return False
-
- # Extract CSRF token from registration page
- soup = BeautifulSoup(register_page.text, "html.parser")
- csrf_input = soup.find("input", {"name": "csrf_token"})
- register_csrf = csrf_input.get("value") if csrf_input else None
-
- if not register_csrf:
- print(" ❌ No CSRF token found in registration page")
- return False
-
- print(f" Registration CSRF token: {register_csrf[:20]}...")
-
- # Attempt registration
- register_response = self.session.post(
- f"{self.base_url}/auth/register",
- data={
- "username": self.username,
- "password": self.password,
- "confirm_password": self.password, # Add confirmation field
- "acknowledge": "true", # Must acknowledge password recovery warning
- "csrf_token": register_csrf,
- },
- allow_redirects=False,
- )
-
- print(
- f" Registration response status: {register_response.status_code}"
- )
-
- if register_response.status_code in [200, 302]:
- print(" ✅ Registration successful")
- return True
- print(f" ❌ Registration failed: {register_response.text[:200]}")
- return False
-
- except Exception as e:
- print(f" ❌ Registration error: {e}")
- return False
-
- def test_authentication_flow(self):
- """Test login and authentication."""
- print("\n2. Testing authentication flow...")
-
- # Get login page (fresh page to ensure fresh CSRF token)
- try:
- login_page = self.session.get(f"{self.base_url}/auth/login")
- print(f" Login page status: {login_page.status_code}")
-
- if login_page.status_code != 200:
- print(
- f" ❌ Failed to get login page: {login_page.text[:200]}"
- )
- return False
-
- # Extract CSRF token
- soup = BeautifulSoup(login_page.text, "html.parser")
- csrf_input = soup.find("input", {"name": "csrf_token"})
- login_csrf = csrf_input.get("value") if csrf_input else None
-
- if not login_csrf:
- print(" ❌ No CSRF token found in login page")
- return False
-
- print(f" Login CSRF token: {login_csrf[:20]}...")
-
- # Attempt login
- login_response = self.session.post(
- f"{self.base_url}/auth/login",
- data={
- "username": self.username,
- "password": self.password,
- "csrf_token": login_csrf,
- },
- allow_redirects=False, # Don't follow redirects to see response clearly
- )
-
- print(f" Login response status: {login_response.status_code}")
-
- if login_response.status_code in [200, 302]:
- print(" ✅ Login successful")
- return True
- print(f" ❌ Login failed: {login_response.text[:200]}")
- return False
-
- except Exception as e:
- print(f" ❌ Authentication error: {e}")
- return False
-
- def test_csrf_tokens(self):
- """Test CSRF token generation and usage."""
- print("\n3. Testing CSRF tokens...")
-
- try:
- # Get API CSRF token
- csrf_response = self.session.get(f"{self.base_url}/auth/csrf-token")
- print(f" CSRF token endpoint status: {csrf_response.status_code}")
-
- if csrf_response.status_code != 200:
- print(
- f" ❌ Failed to get CSRF token: {csrf_response.text[:200]}"
- )
- return False
-
- csrf_data = csrf_response.json()
- csrf_token = csrf_data.get("csrf_token")
-
- if not csrf_token:
- print(" ❌ No CSRF token in response")
- return False
-
- print(f" API CSRF token: {csrf_token[:20]}...")
- self.csrf_token = csrf_token
- return True
-
- except Exception as e:
- print(f" ❌ CSRF token error: {e}")
- return False
-
- def test_research_endpoints(self):
- """Test research API endpoints."""
- print("\n4. Testing research API endpoints...")
-
- if not hasattr(self, "csrf_token"):
- print(" ❌ No CSRF token available")
- return
-
- # Prepare research request
- research_request = {
- "query": "What is machine learning?",
- "model": "gpt-4o-mini", # Use a valid model name
- "search_engines": ["searxng"],
- }
-
- headers = {
- "X-CSRF-Token": self.csrf_token,
- "Content-Type": "application/json",
- }
-
- # Test 1: Correct endpoint /api/start_research
- print("\n 4a. Testing /api/start_research...")
- self._test_endpoint("/api/start_research", research_request, headers)
-
- # Test 2: Old endpoint /research/api/start
- print("\n 4b. Testing /research/api/start...")
- self._test_endpoint("/research/api/start", research_request, headers)
-
- # Test 3: Alternative endpoint /research/api/start_research
- print("\n 4c. Testing /research/api/start_research...")
- self._test_endpoint(
- "/research/api/start_research", research_request, headers
- )
-
- # Test 4: Check if user is properly authenticated for API
- print("\n 4d. Testing auth status...")
- self._test_auth_status()
-
- def _test_endpoint(self, endpoint, research_request, headers):
- """Test a specific research endpoint."""
- try:
- url = f"{self.base_url}{endpoint}"
- response = self.session.post(
- url, json=research_request, headers=headers
- )
-
- print(f" Endpoint: {endpoint}")
- print(f" Status: {response.status_code}")
- print(f" Response: {response.text[:300]}")
-
- if response.status_code == 200:
- try:
- data = response.json()
- if data.get("status") == "success":
- research_id = data.get("research_id")
- print(" ✅ Research started successfully!")
- print(f" Research ID: {research_id}")
-
- # Test research status
- self._test_research_status(research_id)
- elif data.get("status") == "queued":
- print(" ✅ Research queued successfully!")
- print(
- f" Queue position: {data.get('queue_position')}"
- )
- else:
- print(
- f" ⚠️ Research returned: {data.get('status', 'unknown')}"
- )
- except json.JSONDecodeError:
- print(" ⚠️ Response is not valid JSON")
- elif response.status_code == 401:
- print(" ❌ Authentication failed for this endpoint")
- elif response.status_code == 403:
- print(" ❌ Forbidden - CSRF token issue")
- elif response.status_code == 404:
- print(" ❌ Endpoint not found")
- elif response.status_code == 500:
- print(" ❌ Server error - check logs")
- else:
- print(" ⚠️ Unexpected status code")
-
- except Exception as e:
- print(f" ❌ Error testing endpoint: {e}")
-
- def _test_research_status(self, research_id):
- """Test getting research status."""
- if not research_id:
- return
-
- try:
- # Wait a moment for research to initialize
- time.sleep(1) # allow: unmarked-sleep
-
- status_url = f"{self.base_url}/api/research/{research_id}/status"
- response = self.session.get(status_url)
-
- print(f" Status check: {response.status_code}")
- if response.status_code == 200:
- data = response.json()
- print(
- f" Research status: {data.get('status', 'unknown')}"
- )
- print(f" Progress: {data.get('progress', 0)}%")
- else:
- print(f" Status check failed: {response.text[:100]}")
-
- except Exception as e:
- print(f" Error checking status: {e}")
-
- def _test_auth_status(self):
- """Test authentication status."""
- try:
- response = self.session.get(f"{self.base_url}/auth/check")
- print(f" Auth check status: {response.status_code}")
-
- if response.status_code == 200:
- data = response.json()
- print(
- f" Authenticated: {data.get('authenticated', False)}"
- )
- print(f" Username: {data.get('username', 'None')}")
- print(f" Session cookies: {len(self.session.cookies)}")
- else:
- print(f" Auth check failed: {response.text[:100]}")
-
- except Exception as e:
- print(f" Error checking auth: {e}")
-
-
-def main():
- """Run the debug test."""
- import argparse
-
- parser = argparse.ArgumentParser(description="Debug Research API endpoints")
- parser.add_argument(
- "--url", default="http://localhost:5000", help="Base URL for the server"
- )
- parser.add_argument(
- "--username", default="admin", help="Username for authentication"
- )
- parser.add_argument(
- "--password", default="admin", help="Password for authentication"
- )
-
- args = parser.parse_args()
-
- # Create and run test
- test = ResearchAPIDebugTest(args.url)
- test.username = args.username
- test.password = args.password
-
- success = test.run_all_tests()
-
- if success:
- print("\n✅ Debug tests completed successfully")
- sys.exit(0)
- else:
- print("\n❌ Debug tests failed")
- sys.exit(1)
-
-
-if __name__ == "__main__":
- main()
diff --git a/tests/api_tests_with_login/test_research_api_pytest.py b/tests/api_tests_with_login/test_research_api_pytest.py
index 8d9e83e06b..363a876b5e 100644
--- a/tests/api_tests_with_login/test_research_api_pytest.py
+++ b/tests/api_tests_with_login/test_research_api_pytest.py
@@ -105,96 +105,6 @@ def auth_session():
class TestResearchAPI:
"""Test suite for research API endpoints"""
- def test_start_research_with_model(self, auth_session):
- """Test starting research with specific model and verify it's actually used"""
- session, csrf_token = auth_session
-
- # Start research
- research_data = {
- "query": f"Test research with model validation {time.time()}",
- "search_engine": "auto",
- "model": "gemma3n:e2b",
- "model_provider": "OLLAMA",
- "mode": "quick",
- "iterations": 1,
- "questions_per_iteration": 1,
- }
-
- response = session.post(
- f"{BASE_URL}/api/start_research", json=research_data
- )
-
- # Basic assertions
- assert response.status_code in [200, 201, 202], (
- f"Failed to start research: {response.text}"
- )
-
- data = response.json()
- assert "research_id" in data, "No research_id in response"
-
- research_id = data["research_id"]
- assert len(research_id) == 36, "Invalid research_id format"
-
- print(f"Started research with ID: {research_id}")
-
- # Wait for research to start processing
- time.sleep(2) # allow: unmarked-sleep
-
- # Check research status and logs
- status_response = session.get(
- f"{BASE_URL}/api/research/{research_id}/status"
- )
- assert status_response.status_code == 200, (
- f"Failed to get status: {status_response.text}"
- )
-
- status_data = status_response.json()
- assert "status" in status_data
- print(f"Research status: {status_data['status']}")
-
- # Get logs to verify model is being used
- logs_response = session.get(
- f"{BASE_URL}/api/research/{research_id}/logs"
- )
- if logs_response.status_code == 200:
- logs_data = logs_response.json()
- # Handle both list and dict responses
- if isinstance(logs_data, list):
- logs = logs_data
- else:
- logs = logs_data.get("logs", [])
-
- # Check if model appears in logs
- model_found = False
- for log in logs:
- if "gemma3n:e2b" in str(log) or "model" in str(log).lower():
- print(f"Log entry mentioning model: {log}")
- model_found = True
-
- # This should fail if model isn't being passed!
- assert model_found, (
- "Model 'gemma3n:e2b' not found in research logs - model parameter may not be passed correctly!"
- )
-
- # Wait a bit more for research to progress
- time.sleep(5) # allow: unmarked-sleep
-
- # Check if research actually produces results
- report_response = session.get(f"{BASE_URL}/api/report/{research_id}")
- if report_response.status_code == 200:
- report_data = report_response.json()
-
- # Verify report has actual content (not just empty structure)
- assert "title" in report_data or "content" in report_data, (
- "Report has no content"
- )
-
- # If model isn't being used, report will be minimal/empty
- if "content" in report_data:
- assert len(str(report_data["content"])) > 100, (
- "Report content is too short - model may not be running"
- )
-
def test_research_without_required_fields(self, auth_session):
"""Test validation of required fields"""
session, csrf_token = auth_session
@@ -215,66 +125,6 @@ class TestResearchAPI:
)
print(f"✓ Correctly rejected invalid request: {data}")
- def test_research_completion_time(self, auth_session):
- """Test that research actually completes within reasonable time"""
- session, csrf_token = auth_session
-
- # Start research
- research_data = {
- "query": "Quick test for completion time",
- "search_engine": "auto",
- "model": "gemma3n:e2b",
- "model_provider": "OLLAMA",
- "mode": "quick",
- "iterations": 1,
- "questions_per_iteration": 1,
- }
-
- response = session.post(
- f"{BASE_URL}/api/start_research", json=research_data
- )
-
- assert response.status_code in [200, 201, 202]
- research_id = response.json()["research_id"]
-
- # Poll for completion
- start_time = time.time()
- max_wait = 60 # 1 minute max
- completed = False
-
- while time.time() - start_time < max_wait:
- status_response = session.get(
- f"{BASE_URL}/api/research/{research_id}/status"
- )
- if status_response.status_code == 200:
- status = status_response.json().get("status")
- print(
- f"Status after {int(time.time() - start_time)}s: {status}"
- )
-
- if status == "completed":
- completed = True
- break
- if status == "failed":
- # Get logs to understand failure
- logs_response = session.get(
- f"{BASE_URL}/api/research/{research_id}/logs"
- )
- if logs_response.status_code == 200:
- print("Research failed. Logs:")
- for log in logs_response.json().get("logs", [])[
- -10:
- ]: # Last 10 logs
- print(f" {log}")
- pytest.fail("Research failed - check logs above")
-
- time.sleep(2) # allow: unmarked-sleep
-
- assert completed, f"Research did not complete within {max_wait} seconds"
- print(
- f"✓ Research completed in {int(time.time() - start_time)} seconds"
- )
-
if __name__ == "__main__":
# Run tests with verbose output