~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
test: add old->new pragma order backwards compatibility tests
LearningCircuit58d51faec81d
diff --git a/tests/auth_tests/test_sqlcipher_backwards_compat.py b/tests/auth_tests/test_sqlcipher_backwards_compat.pyindex 71d97a1f03..17cc3dcdf9 100644--- a/tests/auth_tests/test_sqlcipher_backwards_compat.py+++ b/tests/auth_tests/test_sqlcipher_backwards_compat.py@@ -348,3 +348,232 @@ class TestLargeDataPersistence:)conn2.close()+++class TestOldToNewPragmaOrderMigration:+ """+ Tests for backwards compatibility when migrating from OLD pragma order+ (key first, then cipher settings) to NEW pragma order (cipher_default_*+ before key).++ This is the critical test for ensuring existing databases created with+ the pre-PR code can still be opened after the PR changes.+ """++ def _create_connection_old_order(self, sqlcipher_module, db_path, password):+ """+ Create a connection using the OLD pragma order (pre-PR behavior).++ OLD order: key -> cipher_page_size -> cipher_hmac_algorithm -> kdf_iter+ This simulates how databases were created before this PR.+ """+ from src.local_deep_research.database.sqlcipher_utils import (+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )++ conn = sqlcipher_module.connect(str(db_path))+ cursor = conn.cursor()++ # OLD ORDER: Set key FIRST+ set_sqlcipher_key(cursor, password)++ # OLD ORDER: Then set cipher settings AFTER the key+ settings = get_sqlcipher_settings()+ cursor.execute(f"PRAGMA cipher_page_size = {settings['page_size']}")+ cursor.execute(+ f"PRAGMA cipher_hmac_algorithm = {settings['hmac_algorithm']}"+ )+ cursor.execute(f"PRAGMA kdf_iter = {settings['kdf_iterations']}")++ cursor.close()+ return conn++ def _create_connection_new_order(self, sqlcipher_module, db_path, password):+ """+ Create a connection using the NEW pragma order (post-PR behavior).++ NEW order: cipher_default_* -> key -> kdf_iter+ This is the new code path introduced by this PR.+ """+ return create_configured_connection(sqlcipher_module, db_path, password)++ def test_old_db_opens_with_new_code(self, sqlcipher_module, temp_db_path):+ """+ CRITICAL: Verify database created with OLD pragma order can be+ opened with NEW pragma order.++ This is the main backwards compatibility test requested by the+ code reviewer.+ """+ password = "old_to_new_migration"++ # Create database using OLD pragma order (simulating pre-PR code)+ conn1 = self._create_connection_old_order(+ sqlcipher_module, temp_db_path, password+ )+ conn1.execute(+ "CREATE TABLE migration_test (id INTEGER PRIMARY KEY, data TEXT)"+ )+ conn1.execute(+ "INSERT INTO migration_test VALUES (1, 'created_with_old_code')"+ )+ conn1.execute("INSERT INTO migration_test VALUES (2, 'should_persist')")+ conn1.commit()+ conn1.close()++ # Reopen using NEW pragma order (simulating post-PR code)+ conn2 = self._create_connection_new_order(+ sqlcipher_module, temp_db_path, password+ )++ # Verify data is accessible+ result = conn2.execute(+ "SELECT data FROM migration_test WHERE id = 1"+ ).fetchone()+ assert result[0] == "created_with_old_code", (+ "Data created with old pragma order should be readable with new order"+ )++ # Verify all rows+ all_rows = conn2.execute(+ "SELECT id, data FROM migration_test ORDER BY id"+ ).fetchall()+ assert len(all_rows) == 2, f"Expected 2 rows, got {len(all_rows)}"+ assert all_rows[0] == (1, "created_with_old_code")+ assert all_rows[1] == (2, "should_persist")++ conn2.close()++ def test_old_db_can_be_modified_with_new_code(+ self, sqlcipher_module, temp_db_path+ ):+ """+ Verify database created with OLD pragma order can be modified+ after opening with NEW pragma order.+ """+ password = "old_to_new_modify"++ # Create database using OLD pragma order+ conn1 = self._create_connection_old_order(+ sqlcipher_module, temp_db_path, password+ )+ conn1.execute(+ "CREATE TABLE data (id INTEGER PRIMARY KEY, value INTEGER)"+ )+ conn1.execute("INSERT INTO data VALUES (1, 100)")+ conn1.commit()+ conn1.close()++ # Open with NEW pragma order and modify+ conn2 = self._create_connection_new_order(+ sqlcipher_module, temp_db_path, password+ )+ conn2.execute("UPDATE data SET value = 200 WHERE id = 1")+ conn2.execute("INSERT INTO data VALUES (2, 300)")+ conn2.commit()+ conn2.close()++ # Reopen with NEW pragma order and verify changes persisted+ conn3 = self._create_connection_new_order(+ sqlcipher_module, temp_db_path, password+ )+ results = conn3.execute(+ "SELECT id, value FROM data ORDER BY id"+ ).fetchall()++ assert results == [(1, 200), (2, 300)], (+ f"Modifications should persist. Got: {results}"+ )+ conn3.close()++ def test_old_db_schema_migration_with_new_code(+ self, sqlcipher_module, temp_db_path+ ):+ """+ Verify schema changes work on databases created with OLD pragma order+ when opened with NEW pragma order.+ """+ password = "old_to_new_schema"++ # Create database using OLD pragma order+ conn1 = self._create_connection_old_order(+ sqlcipher_module, temp_db_path, password+ )+ conn1.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)")+ conn1.execute("INSERT INTO users VALUES (1, 'Alice')")+ conn1.commit()+ conn1.close()++ # Open with NEW pragma order and modify schema+ conn2 = self._create_connection_new_order(+ sqlcipher_module, temp_db_path, password+ )+ conn2.execute("ALTER TABLE users ADD COLUMN email TEXT")+ conn2.execute(+ "UPDATE users SET email = '[email protected]' WHERE id = 1"+ )+ conn2.execute("CREATE INDEX idx_users_email ON users(email)")+ conn2.commit()+ conn2.close()++ # Verify schema changes persisted+ conn3 = self._create_connection_new_order(+ sqlcipher_module, temp_db_path, password+ )++ # Check data+ result = conn3.execute(+ "SELECT name, email FROM users WHERE id = 1"+ ).fetchone()+ assert result == ("Alice", "[email protected]")++ # Check index exists+ indexes = conn3.execute(+ "SELECT name FROM sqlite_master WHERE type='index' AND tbl_name='users'"+ ).fetchall()+ index_names = [idx[0] for idx in indexes]+ assert "idx_users_email" in index_names, (+ f"Index should persist. Found indexes: {index_names}"+ )++ conn3.close()++ def test_settings_consistent_across_migration(+ self, sqlcipher_module, temp_db_path+ ):+ """+ Verify SQLCipher settings remain consistent when migrating from+ OLD to NEW pragma order.+ """+ password = "settings_migration"++ # Create database using OLD pragma order+ conn1 = self._create_connection_old_order(+ sqlcipher_module, temp_db_path, password+ )+ conn1.execute("CREATE TABLE test (id INTEGER)")+ conn1.commit()++ # Capture settings from old-order connection+ old_page_size = conn1.execute("PRAGMA cipher_page_size").fetchone()[0]+ old_hmac = conn1.execute("PRAGMA cipher_hmac_algorithm").fetchone()[0]+ conn1.close()++ # Open with NEW pragma order+ conn2 = self._create_connection_new_order(+ sqlcipher_module, temp_db_path, password+ )++ # Verify settings match+ new_page_size = conn2.execute("PRAGMA cipher_page_size").fetchone()[0]+ new_hmac = conn2.execute("PRAGMA cipher_hmac_algorithm").fetchone()[0]++ assert str(new_page_size) == str(old_page_size), (+ f"Page size mismatch after migration: {old_page_size} -> {new_page_size}"+ )+ assert new_hmac == old_hmac, (+ f"HMAC algorithm mismatch after migration: {old_hmac} -> {new_hmac}"+ )++ conn2.close()