From 670aba974f7fd537bc48bab63c90599972bb304c Mon Sep 17 00:00:00 2001 From: Igor Lins e Silva <4753812+igorls@users.noreply.github.com> Date: Thu, 7 May 2026 07:37:25 -0300 Subject: [PATCH] test(repair): close ChromaBackend in _seed_palace to release Windows file locks The helper opened a chromadb PersistentClient via ChromaBackend and never closed it, leaving rust-side SQLite/HNSW file locks alive after the helper returned. On Windows that blocks the in-place archive rename inside rebuild_from_sqlite with WinError 32 on data_level0.bin, causing test_rebuild_from_sqlite_in_place_archives_when_opted_in and test_rebuild_from_sqlite_raises_on_upsert_failure to fail in the test-windows CI job. No test consumes the returned collection, so closing the backend in a try/finally is safe and drops the return. --- tests/test_repair.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/test_repair.py b/tests/test_repair.py index 8ca72fb..0277d9d 100644 --- a/tests/test_repair.py +++ b/tests/test_repair.py @@ -696,20 +696,24 @@ def test_max_seq_id_rollback_on_verification_failure(tmp_path, monkeypatch): def _seed_palace(palace_path, collection_name, rows): """Build a real chromadb palace at ``palace_path`` and add ``rows``. - ``rows`` is a list of ``(id, document, metadata)`` tuples. Returns - the populated collection so callers can assert on the writer's view - of state before the SQLite read. + ``rows`` is a list of ``(id, document, metadata)`` tuples. """ from mempalace.backends.chroma import ChromaBackend backend = ChromaBackend() - col = backend.create_collection(str(palace_path), collection_name) - col.upsert( - ids=[r[0] for r in rows], - documents=[r[1] for r in rows], - metadatas=[r[2] for r in rows], - ) - return col + try: + col = backend.create_collection(str(palace_path), collection_name) + col.upsert( + ids=[r[0] for r in rows], + documents=[r[1] for r in rows], + metadatas=[r[2] for r in rows], + ) + finally: + # Release chromadb's rust-side SQLite/HNSW file locks before the + # caller proceeds. Without this, an in-place rebuild on Windows + # fails with WinError 32 on data_level0.bin during the archive + # rename (cf. PR #1310 test-windows job). + backend.close() def test_extract_via_sqlite_returns_all_rows_with_metadata(tmp_path):