From e4b63d61b9db846b7f890431a803111afd6a3468 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Mon, 30 Mar 2026 16:06:09 -0700 Subject: [PATCH] Fix: ensure index dir exists before open, fix test isolation gaps - `open_or_rebuild_index` now calls `index_dir.mkdir(parents=True, exist_ok=True)` so a missing index directory is created on demand rather than crashing on `iterdir()` inside `wipe_index` - `TestTagHierarchy.setUp` calls `super().setUp()` so `DirectoriesMixin` runs and `self.dirs` is set before teardown tries to clean up - `test_search_more_like` d4 content changed to words with no overlap with d2/d3 to avoid spurious MLT hits from shared stop words at `min_doc_frequency=1` Co-Authored-By: Claude Sonnet 4.6 --- src/documents/search/_schema.py | 1 + src/documents/tests/test_api_search.py | 4 ++-- src/documents/tests/test_tag_hierarchy.py | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/documents/search/_schema.py b/src/documents/search/_schema.py index 18575cb4c..405be0761 100644 --- a/src/documents/search/_schema.py +++ b/src/documents/search/_schema.py @@ -161,6 +161,7 @@ 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 needs_rebuild(index_dir): wipe_index(index_dir) idx = tantivy.Index(build_schema(), path=str(index_dir)) diff --git a/src/documents/tests/test_api_search.py b/src/documents/tests/test_api_search.py index d8e22b220..db0e9509f 100644 --- a/src/documents/tests/test_api_search.py +++ b/src/documents/tests/test_api_search.py @@ -768,8 +768,8 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase): checksum="C", ) d4 = Document.objects.create( - title="Monty Python & the Holy Grail", - content="And now for something completely different", + title="Quarterly Report", + content="quarterly revenue profit margin earnings growth", pk=4, checksum="ABC", ) diff --git a/src/documents/tests/test_tag_hierarchy.py b/src/documents/tests/test_tag_hierarchy.py index 12e5475f3..57aa27e3a 100644 --- a/src/documents/tests/test_tag_hierarchy.py +++ b/src/documents/tests/test_tag_hierarchy.py @@ -11,10 +11,12 @@ from documents.models import WorkflowAction from documents.models import WorkflowTrigger from documents.serialisers import TagSerializer from documents.signals.handlers import run_workflows +from documents.tests.utils import DirectoriesMixin -class TestTagHierarchy(APITestCase): +class TestTagHierarchy(DirectoriesMixin, APITestCase): def setUp(self) -> None: + super().setUp() self.user = User.objects.create_superuser(username="admin") self.client.force_authenticate(user=self.user)