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.

refactor: Address PR review feedback (#1570)

LearningCircuit7be59b4dc0e6
diff --git a/.github/workflows/critical-ui-tests.yml b/.github/workflows/critical-ui-tests.yml
index 644524e95b..4a9f76da38 100644
--- a/.github/workflows/critical-ui-tests.yml
+++ b/.github/workflows/critical-ui-tests.yml
@@ -64,6 +64,16 @@ jobs:
- name: Set up test directories
run: mkdir -p "$PWD/data/encrypted_databases"
+ - name: Initialize database
+ env:
+ TEST_ENV: true
+ LDR_DATA_DIR: ${{ github.workspace }}/data
+ LDR_DB_KDF_ITERATIONS: "1000" # Must match server setting for encryption compatibility
+ run: |
+ # Use external script for maintainability (see scripts/ci/init_test_database.py)
+ cd src
+ pdm run python ../scripts/ci/init_test_database.py
+
- name: Start test server
env:
CI: true
diff --git a/.github/workflows/extended-ui-tests.yml b/.github/workflows/extended-ui-tests.yml
index 0415cac426..2d674b276c 100644
--- a/.github/workflows/extended-ui-tests.yml
+++ b/.github/workflows/extended-ui-tests.yml
@@ -78,6 +78,19 @@ jobs:
mkdir -p tests/ui_tests/screenshots
mkdir -p tests/ui_tests/results
+ # Pre-create test_admin user to speed up tests (avoids slow registration).
+ # IMPORTANT: LDR_DATA_DIR and LDR_DB_KDF_ITERATIONS must match between this step and "Start server"!
+ # See scripts/ci/init_test_database.py for details.
+ - name: Initialize database with test user
+ env:
+ TEST_ENV: true
+ LDR_DATA_DIR: ${{ github.workspace }}/data
+ LDR_DB_KDF_ITERATIONS: "1000" # Must match server setting for encryption compatibility
+ run: |
+ # Use external script for maintainability
+ cd src
+ pdm run python ../scripts/ci/init_test_database.py
+
- name: Start server
env:
LDR_DATA_DIR: ${{ github.workspace }}/data
diff --git a/.github/workflows/library-tests.yml b/.github/workflows/library-tests.yml
index 58f976c7df..0fbc9b17e0 100644
--- a/.github/workflows/library-tests.yml
+++ b/.github/workflows/library-tests.yml
@@ -355,12 +355,26 @@ jobs:
mkdir -p tests/ui_tests/screenshots
echo "Created data and screenshots directories for tests"
+ # Pre-create test_admin user to speed up tests (avoids slow registration).
+ # IMPORTANT: LDR_DATA_DIR and LDR_DB_KDF_ITERATIONS must match between this step and "Start application server"!
+ # See scripts/ci/init_test_database.py for details.
+ - name: Initialize database with test user
+ env:
+ TEST_ENV: true
+ LDR_DATA_DIR: ${{ github.workspace }}/data
+ LDR_DB_KDF_ITERATIONS: "1000"
+ run: |
+ cd src
+ pdm run python ../scripts/ci/init_test_database.py
+
- name: Start application server
+ env:
+ CI: true
+ LDR_USE_FALLBACK_LLM: true
+ DISABLE_RATE_LIMITING: true
+ LDR_DATA_DIR: ${{ github.workspace }}/data
+ LDR_DB_KDF_ITERATIONS: "1000"
run: |
- export CI=true
- export LDR_USE_FALLBACK_LLM=true
- export DISABLE_RATE_LIMITING=true
- export LDR_DATA_DIR=$PWD/data
export PYTHONPATH=$PWD/src:$PYTHONPATH
echo "Starting web server with LDR_DATA_DIR=$LDR_DATA_DIR"
pdm run python -m local_deep_research.web.app 2>&1 | tee server.log &
diff --git a/scripts/ci/init_test_database.py b/scripts/ci/init_test_database.py
new file mode 100644
index 0000000000..4875aee3d9
--- /dev/null
+++ b/scripts/ci/init_test_database.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+"""
+Initialize test database with pre-created test user for CI.
+
+This script creates the test_admin user BEFORE tests run, avoiding the slow
+registration process (2+ min) which:
+1. Creates encrypted SQLCipher database
+2. Derives encryption keys from password
+3. Creates 58 database tables
+4. Imports 500+ settings from JSON files
+
+Usage:
+ python scripts/ci/init_test_database.py
+
+Environment variables:
+ LDR_DATA_DIR: Directory for database files (required for path consistency)
+ TEST_ENV: Should be "true" for test environment
+
+Note: Test user credentials must match CI_TEST_USER in tests/ui_tests/auth_helper.js
+"""
+
+import os
+from pathlib import Path
+
+
+def main():
+ """Create test database and test_admin user."""
+ # Test user credentials - must match CI_TEST_USER in auth_helper.js
+ TEST_USERNAME = "test_admin"
+ TEST_PASSWORD = "testpass123" # pragma: allowlist secret
+
+ # Use LDR_DATA_DIR if set, otherwise default
+ data_dir = Path(
+ os.environ.get(
+ "LDR_DATA_DIR",
+ Path.home() / ".local" / "share" / "local-deep-research",
+ )
+ )
+ print(f"Using data directory: {data_dir}")
+ data_dir.mkdir(parents=True, exist_ok=True)
+ (data_dir / "encrypted_databases").mkdir(parents=True, exist_ok=True)
+
+ # Import after setting up paths
+ from local_deep_research.database.auth_db import (
+ get_auth_db_session,
+ init_auth_database,
+ )
+ from local_deep_research.database.encrypted_db import db_manager
+ from local_deep_research.database.models.auth import User
+
+ # Initialize auth database
+ init_auth_database()
+
+ # Create test user in auth database (no password stored)
+ session = get_auth_db_session()
+ user = User(username=TEST_USERNAME)
+ session.add(user)
+ session.commit()
+ session.close()
+
+ # Create user's encrypted database with password
+ db_manager.create_user_database(TEST_USERNAME, TEST_PASSWORD)
+
+ print("✅ Database initialized successfully")
+ print(f"✅ Test user '{TEST_USERNAME}' created")
+ print(f" Encrypted databases in: {data_dir / 'encrypted_databases'}")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/ui_tests/auth_helper.js b/tests/ui_tests/auth_helper.js
index e4fc5d764b..47f82c6760 100644
--- a/tests/ui_tests/auth_helper.js
+++ b/tests/ui_tests/auth_helper.js
@@ -735,8 +735,10 @@ class AuthHelper {
}
timer.lap('login status checked');
- // In CI, first try the pre-created CI test user (much faster than registration!)
- // Note: This only works if the workflow properly created the user with password hash
+ // In CI, try the pre-created CI test user first (much faster than registration!)
+ // If CI login fails, fall back to registration (slower but reliable).
+ // This allows incremental migration - workflows with init_test_database.py
+ // get the speed benefit, while others still work via registration fallback.
if (this.isCI) {
console.log('\n🚀 CI mode: Trying pre-created test user first (fast path)...');
try {
@@ -745,10 +747,10 @@ class AuthHelper {
timer.summary();
return true;
} catch (ciLoginError) {
+ // Fall back to registration (slower but reliable)
console.log(`⚠️ CI test user login failed: ${ciLoginError.message}`);
- console.log(' This is expected if workflow doesn\'t pre-create user properly.');
console.log(' Falling back to registration (slower but reliable)...');
- timer.lap('CI user login failed, falling back to registration');
+ // Continue to registration logic below
}
}