From dbb0b8217b8ed2c8a68f694e0dbd80d054067880 Mon Sep 17 00:00:00 2001 From: stumpylog <797416+stumpylog@users.noreply.github.com> Date: Thu, 20 Aug 2026 10:32:19 -0700 Subject: [PATCH] test(search): prune trivial and superseded search tests (Task 10 Prune list) - test_fields.py: reduced to test_json_fields_have_subpaths - the rest asserted properties of PUBLIC_FIELDS' 16-line literal tuple, already covered behaviourally by test_registry.py's resolve()-based tests. - test_registry.py::TestJsonSubpathCoupling: deleted - its own docstring admitted it hardcodes both sides of the comparison it claims to guard. test_acceptance.py::TestJsonSubpaths already proves the coupling against a real index, and the new test_json_subpath_completeness.py proves it exhaustively for every declared subpath. - test_query.py: dropped the asn/checksum isinstance-only parse checks, now duplicated by result-level matches in test_documented_syntax.py and test_api_search.py. - conftest.py: dropped the module-scoped `index` fixture, dead since test_translate.py was deleted. 419 passed (documents/tests/search/ + test_api_search.py + test_api_search_errors.py), down from 432 before this prune. Co-Authored-By: Claude Opus 5 --- src/documents/tests/search/conftest.py | 12 ----- src/documents/tests/search/test_fields.py | 58 --------------------- src/documents/tests/search/test_query.py | 14 ----- src/documents/tests/search/test_registry.py | 24 --------- 4 files changed, 108 deletions(-) diff --git a/src/documents/tests/search/conftest.py b/src/documents/tests/search/conftest.py index 93c560043..ccc26d695 100644 --- a/src/documents/tests/search/conftest.py +++ b/src/documents/tests/search/conftest.py @@ -1,15 +1,11 @@ from __future__ import annotations -import tempfile from typing import TYPE_CHECKING import pytest -import tantivy from documents.search._backend import TantivyBackend from documents.search._backend import reset_backend -from documents.search._schema import build_schema -from documents.search._tokenizer import register_tokenizers if TYPE_CHECKING: from collections.abc import Generator @@ -35,11 +31,3 @@ def backend() -> Generator[TantivyBackend, None, None]: finally: b.close() reset_backend() - - -@pytest.fixture(scope="module") -def index() -> tantivy.Index: - """A real Tantivy index for parse-acceptance tests (module scope for speed).""" - idx = tantivy.Index(build_schema(), path=tempfile.mkdtemp()) - register_tokenizers(idx, "english") - return idx diff --git a/src/documents/tests/search/test_fields.py b/src/documents/tests/search/test_fields.py index 210e09142..39c9d176e 100644 --- a/src/documents/tests/search/test_fields.py +++ b/src/documents/tests/search/test_fields.py @@ -1,68 +1,10 @@ -import pytest from whoosh_compat import FieldKind from documents.search._fields import PUBLIC_FIELDS -BY_NAME = {f.name: f for f in PUBLIC_FIELDS} - class TestPublicFields: - def test_every_field_has_a_whoosh_compat_kind(self) -> None: - for field in PUBLIC_FIELDS: - assert isinstance(field.kind, FieldKind) - - def test_names_are_unique(self) -> None: - names = [f.name for f in PUBLIC_FIELDS] - assert len(names) == len(set(names)) - def test_json_fields_have_subpaths(self) -> None: for field in PUBLIC_FIELDS: if field.kind is FieldKind.JSON: assert field.subpaths, f"{field.name} is JSON but has no subpaths" - - def test_non_json_fields_have_no_subpaths(self) -> None: - for field in PUBLIC_FIELDS: - if field.kind is not FieldKind.JSON: - assert not field.subpaths - - @pytest.mark.parametrize( - ("name", "attr", "expected"), - [ - pytest.param( - "document_type", - "aliases", - ("type",), - id="document_type-aliases", - ), - pytest.param( - "storage_path", - "aliases", - ("path",), - id="storage_path-aliases", - ), - pytest.param("tag", "comma_values", True, id="tag-comma_values"), - pytest.param( - "notes", - "subpaths", - {"user", "note"}, - id="notes-subpaths", - ), - pytest.param( - "custom_fields", - "subpaths", - {"name", "value"}, - id="custom_fields-subpaths", - ), - ], - ) - def test_field_attributes(self, name: str, attr: str, expected: object) -> None: - actual = getattr(BY_NAME[name], attr) - if attr == "subpaths": - actual = set(actual) - assert actual == expected - - def test_no_internal_id_fields_present(self) -> None: - # tag_id/owner_id/viewer_id/etc. are permission-filter-only fields, - # never user-query-addressable (see design spec, "Field surface"). - names = {f.name for f in PUBLIC_FIELDS} - assert not any(name.endswith("_id") for name in names) diff --git a/src/documents/tests/search/test_query.py b/src/documents/tests/search/test_query.py index f3975bbe9..caa35f365 100644 --- a/src/documents/tests/search/test_query.py +++ b/src/documents/tests/search/test_query.py @@ -129,20 +129,6 @@ class TestParseUserQuery: kinds = {type(e) for e in exc_info.value.errors} assert kinds == {InvalidDateQuery, InvalidNumberQuery} - def test_asn_field_is_query_addressable( - self, - query_index: tantivy.Index, - ) -> None: - q = parse_user_query(query_index, "asn:42", UTC) - assert isinstance(q, tantivy.Query) - - def test_checksum_field_is_query_addressable( - self, - query_index: tantivy.Index, - ) -> None: - q = parse_user_query(query_index, "checksum:abc123", UTC) - assert isinstance(q, tantivy.Query) - def test_unregistered_id_field_folds_to_literal_text_not_error( self, query_index: tantivy.Index, diff --git a/src/documents/tests/search/test_registry.py b/src/documents/tests/search/test_registry.py index f748c6360..375cd9005 100644 --- a/src/documents/tests/search/test_registry.py +++ b/src/documents/tests/search/test_registry.py @@ -3,11 +3,8 @@ from whoosh_compat import FieldKind from whoosh_compat import FieldRegistry from whoosh_compat.fields import ResolvedField -from documents.search._fields import PUBLIC_FIELDS from documents.search._registry import get_field_registry -_BY_NAME = {f.name: f for f in PUBLIC_FIELDS} - @pytest.fixture def registry() -> FieldRegistry: @@ -115,24 +112,3 @@ class TestFieldRegistry: a = get_field_registry("en") b = get_field_registry("de") assert a is not b - - -class TestJsonSubpathCoupling: - """Guards PUBLIC_FIELDS' JSON subpaths against drifting from the literal - dict keys _backend.py::_build_tantivy_doc writes. These assertions - hardcode the expected key sets rather than introspecting _build_tantivy_doc - (its dict keys are string literals with no importable symbol) — if someone - changes _build_tantivy_doc's JSON keys without updating this test too, it - will pass despite the drift. Best-effort, not a structural guarantee. - """ - - def test_notes_dict_keys_match_public_fields_subpaths(self) -> None: - # _backend.py's _build_tantivy_doc builds: - # doc.add_json("notes", {"note": ..., "user": ...}) - # These literal keys must match PUBLIC_FIELDS' "notes" subpaths exactly. - assert set(_BY_NAME["notes"].subpaths) == {"note", "user"} - - def test_custom_fields_dict_keys_match_public_fields_subpaths(self) -> None: - # _backend.py's _build_tantivy_doc builds: - # doc.add_json("custom_fields", {"name": ..., "value": ...}) - assert set(_BY_NAME["custom_fields"].subpaths) == {"name", "value"}