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(db): fix encrypted-DB test that silently skipped in CI (wrong package name) (#4674)

LearningCircuit118ebbab84ec
diff --git a/tests/database/test_database_init.py b/tests/database/test_database_init.py
index cb624d2c4b..a2e589c964 100644
--- a/tests/database/test_database_init.py
+++ b/tests/database/test_database_init.py
@@ -6,8 +6,7 @@ import uuid
from pathlib import Path
import pytest
-from sqlalchemy import create_engine, event, inspect
-from sqlalchemy.exc import OperationalError
+from sqlalchemy import create_engine, inspect
from sqlalchemy.orm import sessionmaker
from local_deep_research.database.models import (
@@ -91,61 +90,54 @@ class TestDatabaseInitialization:
engine.dispose()
- def test_encrypted_database_creation(self, temp_dir):
- """Test creating an encrypted database with SQLCipher."""
- db_path = str(Path(temp_dir) / "encrypted.db")
- password = "test_password_123"
-
- # Try to create encrypted database (will fail if sqlcipher not available)
- engine = None
- bad_engine = None
- try:
- # Check if pysqlcipher3 is available
- import importlib.util
-
- if importlib.util.find_spec("pysqlcipher3") is None:
- raise ImportError("pysqlcipher3 not available")
-
- # SQLCipher URI format - disable regexp to avoid compatibility issues
- engine = create_engine(
- f"sqlite+pysqlcipher://:{password}@/{db_path}",
- connect_args={"check_same_thread": False, "timeout": 15},
- )
-
- # Disable regexp function that causes issues
- @event.listens_for(engine, "connect")
- def do_connect(dbapi_conn, connection_record):
- # Disable loading of regexp
- connection_record.info["regexp"] = False
-
- # Create tables
- Base.metadata.create_all(engine)
-
- # Test writing data
- Session = sessionmaker(bind=engine)
- session = Session()
-
- user = User(username="testuser")
- session.add(user)
- session.commit()
- session.close()
+ def test_encrypted_database_creation(self, temp_dir, monkeypatch):
+ """A user database created via DatabaseManager is real SQLCipher-encrypted.
+
+ Uses the production creation path (DatabaseManager + sqlcipher3), not
+ the obsolete ``sqlite+pysqlcipher://`` dialect, and skips only when a
+ functional SQLCipher backend is genuinely unavailable -- checked via
+ ``DatabaseManager.has_encryption`` rather than guessing a package name.
+ The previous version probed ``pysqlcipher3`` (which this project does
+ not install -- it uses ``sqlcipher3``), so it silently skipped
+ everywhere, including CI.
+ """
+ from sqlalchemy import text
+ from sqlalchemy.exc import DatabaseError
- # Verify database is encrypted by trying to open without password
- bad_engine = create_engine(f"sqlite:///{db_path}")
- with pytest.raises((OperationalError, Exception)):
- with bad_engine.connect() as conn:
- from sqlalchemy import text
+ from local_deep_research.database.encrypted_db import DatabaseManager
- conn.execute(text("SELECT * FROM users"))
+ monkeypatch.setattr(
+ "local_deep_research.database.encrypted_db.get_data_directory",
+ lambda: Path(temp_dir),
+ )
+ manager = DatabaseManager()
+ if not manager.has_encryption:
+ pytest.skip("Functional SQLCipher backend not available")
- except (ImportError, TypeError) as e:
- # Skip if SQLCipher not available or compatibility issues
- pytest.skip(f"SQLCipher test skipped: {e}")
+ username, password = "encuser", "TestPassword123!"
+ engine = manager.create_user_database(username, password)
+ plain_engine = None
+ try:
+ # The encrypted engine is functional.
+ with engine.connect() as conn:
+ assert conn.execute(text("SELECT 1")).scalar() == 1
+
+ db_path = manager._get_user_db_path(username)
+ assert db_path.exists()
+
+ # Opening the same file as PLAINTEXT SQLite must fail with "file is
+ # not a database": the bytes are encrypted, so SQLite cannot parse
+ # the header. DatabaseError (SQLAlchemy's OperationalError subclasses
+ # it) is specific enough that the test can't pass for an unrelated
+ # reason -- the actual proof that encryption was applied.
+ plain_engine = create_engine(f"sqlite:///{db_path}")
+ with pytest.raises(DatabaseError):
+ with plain_engine.connect() as conn:
+ conn.execute(text("SELECT name FROM sqlite_master"))
finally:
- if bad_engine is not None:
- bad_engine.dispose()
- if engine is not None:
- engine.dispose()
+ if plain_engine is not None:
+ plain_engine.dispose()
+ manager.close_user_database(username)
def test_database_schema_completeness(self, db_engine):
"""Test that all expected tables and columns are created."""