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.

1.7 KB
Raw Blame
"""``check_database_integrity`` must tell the truth in unencrypted-fallback mode.

``PRAGMA cipher_integrity_check`` ran unconditionally, also on the plain
SQLite engines used when ``LDR_BOOTSTRAP_ALLOW_UNENCRYPTED`` is set. Vanilla
SQLite answers with a closed result whose iteration raises, the ``except``
swallowed it, and every healthy fallback database reported "integrity check
failed" (#6357).
"""

from unittest.mock import patch

import pytest

MODULE = "local_deep_research.database.encrypted_db"


@pytest.fixture
def fallback_manager(tmp_path, monkeypatch):
    from local_deep_research.database.encrypted_db import DatabaseManager

    monkeypatch.setenv("LDR_BOOTSTRAP_ALLOW_UNENCRYPTED", "true")
    with (
        patch(
            f"{MODULE}.get_sqlcipher_module",
            side_effect=ImportError("No module named 'sqlcipher3'"),
        ),
        patch(f"{MODULE}.get_data_directory", return_value=tmp_path),
    ):
        manager = DatabaseManager()
        assert manager.has_encryption is False, (
            "Test requires the unencrypted fallback path"
        )
        yield manager
        manager.close_all_databases()


def test_healthy_unencrypted_database_passes_integrity_check(
    fallback_manager,
):
    username = "fallback_user"
    fallback_manager.create_user_database(username, "test-password-123")
    fallback_manager.close_user_database(username)
    assert (
        fallback_manager.open_user_database(username, "test-password-123")
        is not None
    )

    assert fallback_manager.check_database_integrity(username) is True


def test_unknown_user_still_fails_integrity_check(fallback_manager):
    assert fallback_manager.check_database_integrity("nobody") is False