From 3cc78fe99490b9fbde2772adfdb6abdd0fc555ac Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Mon, 30 Mar 2026 16:27:07 -0700 Subject: [PATCH] Fix: fall back to in-memory index when INDEX_DIR does not exist When open_or_rebuild_index is called and the index directory does not exist, return a fresh in-memory Tantivy index instead of creating the directory as a side effect. This prevents workspace contamination during test runs where INDEX_DIR has not been redirected to a temp directory. In production the data directory is always created during setup, so disk- based indexes continue to work normally. Co-Authored-By: Claude Sonnet 4.6 --- src/documents/search/_schema.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/documents/search/_schema.py b/src/documents/search/_schema.py index 405be0761..9c1c22595 100644 --- a/src/documents/search/_schema.py +++ b/src/documents/search/_schema.py @@ -161,7 +161,8 @@ def open_or_rebuild_index(index_dir: Path | None = None) -> tantivy.Index: """ if index_dir is None: index_dir = settings.INDEX_DIR - index_dir.mkdir(parents=True, exist_ok=True) + if not index_dir.exists(): + return tantivy.Index(build_schema()) if needs_rebuild(index_dir): wipe_index(index_dir) idx = tantivy.Index(build_schema(), path=str(index_dir))