~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
"""Real salt-file I/O, also run on native Windows without pytest fixtures.
Only the random salt source is controlled. File descriptors, binary/text
translation and SQLCipher are real; a missing encryption driver fails the run.
"""
from contextlib import closing
import os
from pathlib import Path
import tempfile
from types import SimpleNamespace
import unittest
from unittest.mock import Mock, patch
from local_deep_research.database import sqlcipher_utils
from local_deep_research.database.sqlcipher_compat import get_sqlcipher_module
SALTS = (
b"\x00\x1a\xff\r\n\r\r\n" + bytes(range(24)),
b"\n" * 32,
b"\r\n" * 16,
)
class NativeSaltTests(unittest.TestCase):
def setUp(self):
temporary = tempfile.TemporaryDirectory(prefix="ldr-native-salt-")
self.addCleanup(temporary.cleanup)
self.root = Path(temporary.name) / "original's café data"
self.root.mkdir()
environment = patch.dict(
os.environ,
{
"LDR_DATA_DIR": str(self.root),
"LDR_TEST_MODE": "false",
"LDR_DB_CONFIG_KDF_ITERATIONS": "256000",
},
)
environment.start()
self.addCleanup(environment.stop)
self.assertEqual(
sqlcipher_utils.get_sqlcipher_settings()["kdf_iterations"], 256000
)
self.sqlcipher = get_sqlcipher_module()
def create_salt(self, path, salt):
random_bytes = Mock(return_value=salt)
with patch.object(
sqlcipher_utils,
"secrets",
SimpleNamespace(token_bytes=random_bytes),
):
self.assertEqual(sqlcipher_utils.create_database_salt(path), salt)
random_bytes.assert_called_once_with(sqlcipher_utils.SALT_SIZE)
def test_writer_preserves_all_bytes_with_real_file_descriptors(self):
for index, salt in enumerate(SALTS):
with self.subTest(salt=index):
path = self.root / f"writer-{index}.db"
self.create_salt(path, salt)
stored = sqlcipher_utils.get_salt_file_path(path).read_bytes()
self.assertEqual(stored, salt)
self.assertEqual(len(stored), 32)
def test_existing_salt_is_never_overwritten(self):
path = self.root / "existing.db"
self.create_salt(path, SALTS[0])
with self.assertRaises(FileExistsError):
sqlcipher_utils.create_database_salt(path)
self.assertEqual(
sqlcipher_utils.get_salt_file_path(path).read_bytes(), SALTS[0]
)
def test_encrypted_database_reopens_with_a_translated_salt(self):
password = "native-salt-test-password" # noqa: S105
for index, salt in enumerate(SALTS):
with self.subTest(salt=index):
path = self.root / f"encrypted-{index}.db"
self.create_salt(path, salt)
with closing(
sqlcipher_utils.create_sqlcipher_connection(
path, password, creation_mode=True
)
) as connection:
self.assertTrue(
connection.execute("PRAGMA cipher_version").fetchone()[
0
]
)
connection.execute("CREATE TABLE canary (value TEXT)")
connection.execute(
"INSERT INTO canary VALUES (?)", ("preserved",)
)
connection.commit()
self.assertNotEqual(
path.read_bytes()[:16], b"SQLite format 3\0"
)
salt_file = sqlcipher_utils.get_salt_file_path(path)
translated = salt.replace(b"\n", b"\r\n")
salt_file.write_bytes(translated)
with closing(
sqlcipher_utils.create_sqlcipher_connection(path, password)
) as connection:
self.assertEqual(
connection.execute(
"SELECT value FROM canary"
).fetchall(),
[("preserved",)],
)
with self.assertRaises(
(ValueError, self.sqlcipher.DatabaseError)
):
with closing(
sqlcipher_utils.create_sqlcipher_connection(
path, "wrong-password"
)
):
pass
self.assertEqual(salt_file.read_bytes(), translated)
if __name__ == "__main__":
unittest.main()