fix(test): use tmp_path for full-stack invariant test (Windows CI)

`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.
This commit is contained in:
Igor Lins e Silva
2026-04-24 19:41:19 -03:00
parent 133dfbfb41
commit ec5f4eba9d
+15 -10
View File
@@ -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")