From ec5f4eba9dd9095fa341b397091c01ec90e63c8b Mon Sep 17 00:00:00 2001 From: Igor Lins e Silva <4753812+igorls@users.noreply.github.com> Date: Fri, 24 Apr 2026 19:41:19 -0300 Subject: [PATCH] fix(test): use tmp_path for full-stack invariant test (Windows CI) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `test_fresh_palace_via_full_stack_gets_cosine` used `tempfile.Temporary- Directory()` as a context manager, which tries to delete the temp path on exit. On Windows, ChromaDB still holds SQLite file handles to `chroma.sqlite3` when the context closes, producing: PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '...\\chroma.sqlite3' NotADirectoryError: [WinError 267] The directory name is invalid Other tests in the same file use pytest's `tmp_path` fixture, which defers cleanup to session end (when the process is exiting and the file-lock contention is moot). Align this one with the rest of the file. CLAUDE.md already documents the 80% Windows coverage allowance due to "ChromaDB file lock cleanup" — the fix is to stop fighting the lock. --- tests/test_collection_metric_invariant.py | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/test_collection_metric_invariant.py b/tests/test_collection_metric_invariant.py index 851711e..e56dca5 100644 --- a/tests/test_collection_metric_invariant.py +++ b/tests/test_collection_metric_invariant.py @@ -12,8 +12,6 @@ This test file locks the invariant so a future refactor that drops the gets caught at test time rather than silently degrading search quality. """ -import tempfile - from mempalace.backends.chroma import ChromaBackend from mempalace.palace import get_collection @@ -70,13 +68,20 @@ def test_reopening_cosine_palace_preserves_metric(tmp_path): _assert_cosine(col, "re-opened palace") -def test_fresh_palace_via_full_stack_gets_cosine(): +def test_fresh_palace_via_full_stack_gets_cosine(tmp_path): """End-to-end: build a palace with the public API the way a new user - would, confirm the resulting collection uses cosine distance.""" - with tempfile.TemporaryDirectory() as tmp: - col = get_collection(tmp, "mempalace_drawers", create=True) - _assert_cosine(col, "full-stack new palace") + would, confirm the resulting collection uses cosine distance. - # And the closets collection too - closets = get_collection(tmp, "mempalace_closets", create=True) - _assert_cosine(closets, "full-stack new closets") + Uses the ``tmp_path`` fixture rather than ``tempfile.TemporaryDirectory`` + so ChromaDB's persistent SQLite file handles aren't asked to release + during the test body — pytest cleans the path at session end, by which + point the process is exiting and Windows' file-lock contention is + moot. Matches the cleanup strategy used by the rest of this file and + the project's 80% Windows coverage note in CLAUDE.md. + """ + col = get_collection(str(tmp_path), "mempalace_drawers", create=True) + _assert_cosine(col, "full-stack new palace") + + # And the closets collection too + closets = get_collection(str(tmp_path), "mempalace_closets", create=True) + _assert_cosine(closets, "full-stack new closets")