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(journal_quality): pin close-before-unlink ordering in _validate_existing_db (#6897)

LearningCircuit4995762fa89d
diff --git a/tests/journal_quality/test_db_accessors.py b/tests/journal_quality/test_db_accessors.py
index 7e45330438..c9975dd259 100644
--- a/tests/journal_quality/test_db_accessors.py
+++ b/tests/journal_quality/test_db_accessors.py
@@ -378,6 +378,35 @@ class TestValidateExistingDb:
assert _uninitialized_db()._validate_existing_db(db_path) is False
+ def test_close_happens_before_unlink_on_unusable_db(self, tmp_path):
+ """Windows-motivated ordering invariant (#6299): the SQLite
+ connection must be closed BEFORE the unusable file is unlinked —
+ unlinking first fails with "file in use" on Windows and breaks
+ the rebuild that follows. Linux CI cannot show the failure
+ itself, so pin the call sequence directly."""
+ from unittest.mock import patch
+
+ db_path = tmp_path / "test.db"
+ db_path.write_text("this is not a database")
+
+ calls = []
+ db = _uninitialized_db()
+
+ with (
+ patch(
+ "local_deep_research.utilities.resource_utils.safe_close",
+ side_effect=lambda conn, ctx: calls.append("close"),
+ ),
+ patch.object(
+ JournalQualityDB,
+ "_unlink_unusable_db",
+ side_effect=lambda path: calls.append("unlink"),
+ ),
+ ):
+ assert db._validate_existing_db(db_path) is False
+
+ assert calls == ["close", "unlink"]
+
def test_missing_file_returns_false(self, tmp_path):
db_path = tmp_path / "nonexistent.db"