forked from enderofwings/NexusOS
fix(sync): close SQLite handles before restore
Use contextlib.closing for dump, comparison, and restore connections so Windows can unlink the live database immediately after the comparison step.
This commit is contained in:
+5
-1
@@ -264,13 +264,17 @@ def test_sync_compare_detects_direction(tmp_path):
|
||||
"""The guard that stops a stale box from overwriting the other's chats.
|
||||
Both backup and restore refuse to run when this says the wrong thing, so a
|
||||
silent break here loses conversation history."""
|
||||
import contextlib
|
||||
import sqlite3 as sq
|
||||
sync = _load_sync()
|
||||
db, dump = tmp_path / "memory.db", tmp_path / "memory.db.sql"
|
||||
|
||||
def write(rows):
|
||||
db.unlink(missing_ok=True)
|
||||
with sq.connect(db) as conn:
|
||||
# closing() then the connection itself: sqlite3's own context manager
|
||||
# commits but never closes, and Windows refuses to unlink a file that
|
||||
# still has an open handle.
|
||||
with contextlib.closing(sq.connect(db)) as conn, conn:
|
||||
# updated_at REAL, matching the production schema in store.py. A TEXT
|
||||
# column here hid a real TypeError for months: the comparison in
|
||||
# _extra() ran str-vs-str in the test and str-vs-float in the field.
|
||||
|
||||
Reference in New Issue
Block a user