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(database): cover SQLCipher finalization gate (#7212)

LearningCircuit5a34578d69d8
diff --git a/tests/database/test_sqlcipher_lifecycle.py b/tests/database/test_sqlcipher_lifecycle.py
index f5913d00ea..8c5077add9 100644
--- a/tests/database/test_sqlcipher_lifecycle.py
+++ b/tests/database/test_sqlcipher_lifecycle.py
@@ -212,7 +212,19 @@ def test_child_does_not_inherit_parent_lifecycle_lock(tmp_path):
assert result == {"child": "passed"}
-def test_foreign_thread_finalization_closes_under_lifecycle_lock(tmp_path):
+ ("platform", "version", "guarded"),
+ [
+ ("posix", "3.51.0", True),
+ ("posix", "3.51.1", True),
+ ("posix", "3.50.4", False),
+ ("posix", "3.51.2", False),
+ ("nt", "3.51.1", False),
+ ],
+)
+def test_foreign_thread_finalization_respects_lifecycle_gate(
+ tmp_path, platform, version, guarded
+):
# The driver's close() refuses a foreign thread under its own
# check_same_thread, which once let the native deallocator close a
# connection finalised elsewhere with no guard held.
@@ -224,14 +236,26 @@ def test_foreign_thread_finalization_closes_under_lifecycle_lock(tmp_path):
from pathlib import Path
import sys
import threading
+ from types import SimpleNamespace
import sqlcipher3
from local_deep_research.database import sqlcipher_compat
+ # Select the compatibility gate explicitly while using real native
+ # connections and the host filesystem. Replacing this module's os
+ # reference leaves pathlib and the rest of Python on the real host.
+ sqlcipher_compat.os = SimpleNamespace(name=sys.argv[2])
+ driver = SimpleNamespace(
+ sqlite_version_info=tuple(map(int, sys.argv[3].split('.'))),
+ Connection=sqlcipher3.Connection,
+ Cursor=sqlcipher3.Cursor,
+ connect=sqlcipher3.connect,
+ )
+
path = Path(sys.argv[1]) / 'owned.db'
wal = Path(str(path) + '-wal')
key = 'PRAGMA key = "x\\\'' + ('ab' * 32) + '\\\'"'
- setup = sqlcipher_compat.connect_sqlcipher(sqlcipher3, str(path))
+ setup = sqlcipher_compat.connect_sqlcipher(driver, str(path))
setup.execute(key)
assert setup.execute('PRAGMA journal_mode=WAL').fetchone()[0] == 'wal'
setup.execute('CREATE TABLE canary (value INTEGER)')
@@ -259,7 +283,7 @@ def test_foreign_thread_finalization_closes_under_lifecycle_lock(tmp_path):
def owner():
# Default check_same_thread=True, as the backup and key-check
# sites use it.
- connection = sqlcipher_compat.connect_sqlcipher(sqlcipher3, str(path))
+ connection = sqlcipher_compat.connect_sqlcipher(driver, str(path))
connection.execute(key)
cursor = connection.cursor()
cursor.execute('SELECT value FROM canary')
@@ -274,6 +298,7 @@ def test_foreign_thread_finalization_closes_under_lifecycle_lock(tmp_path):
assert wal.exists()
connection, cursor = handed_over
handed_over.clear()
+ guarded_connection = type(connection) is not sqlcipher3.Connection
refused = []
for name, call in [
('connection.execute', lambda: connection.execute('SELECT 1')),
@@ -299,7 +324,7 @@ def test_foreign_thread_finalization_closes_under_lifecycle_lock(tmp_path):
creator.join(timeout=10)
shared = sqlcipher_compat.connect_sqlcipher(
- sqlcipher3, ':memory:', check_same_thread=False
+ driver, ':memory:', check_same_thread=False
)
shared_rows = []
worker = threading.Thread(
@@ -309,15 +334,19 @@ def test_foreign_thread_finalization_closes_under_lifecycle_lock(tmp_path):
worker.join(timeout=10)
shared.close()
print(json.dumps({
+ 'guarded_connection': guarded_connection,
'closed_under_lock': closed_under_lock,
'wal_removed': wal_removed,
'refused': refused,
'shared_rows': shared_rows,
}))
""",
+ platform,
+ version,
)
assert result == {
- "closed_under_lock": True,
+ "guarded_connection": guarded,
+ "closed_under_lock": guarded,
"wal_removed": True,
"refused": [
"connection.execute",