From b48b1a7d083c700130f3329b681d042db5fec03b Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Mon, 17 Aug 2026 20:27:33 -0700 Subject: [PATCH] test: assert unregistered id-field queries actually match nothing test_unregistered_id_field_folds_to_literal_text_not_error only checked that parse_user_query() didn't raise for a query like tag_id:5. Add a result-level acceptance test (matching test_acceptance.py's _matched_ids pattern, indexed against real documents) that asserts the matched-document-ID set is genuinely empty, not just that the parse step succeeds. --- src/documents/tests/search/test_acceptance.py | 16 ++++++++++++++++ src/documents/tests/search/test_query.py | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/documents/tests/search/test_acceptance.py b/src/documents/tests/search/test_acceptance.py index efbc890a2..b19e2524a 100644 --- a/src/documents/tests/search/test_acceptance.py +++ b/src/documents/tests/search/test_acceptance.py @@ -245,3 +245,19 @@ class TestMultitokenInNestedOr: backend.add_or_update(doc_b) matched = _matched_ids(backend, 'tag:"multi word tag" OR title:B') assert matched == {doc_a.pk, doc_b.pk} + + +class TestUnregisteredIdFieldFoldsToLiteralText: + """tag_id, owner_id, etc. are intentionally excluded from the + FieldRegistry - whoosh-compat parity leniency folds them into a literal + text search rather than raising a diagnostic/400 (see docs/usage.md's + advanced-search section). Prove the fold is inert against real data, not + just that parsing doesn't raise.""" + + def test_tag_id_query_matches_nothing( + self, + backend: TantivyBackend, + indexed_documents: dict[str, int], + ) -> None: + matched = _matched_ids(backend, "tag_id:5") + assert matched == set() diff --git a/src/documents/tests/search/test_query.py b/src/documents/tests/search/test_query.py index a1c63bd6e..fcb9c9286 100644 --- a/src/documents/tests/search/test_query.py +++ b/src/documents/tests/search/test_query.py @@ -152,6 +152,9 @@ class TestParseUserQuery: ) -> None: # tag_id is intentionally excluded from the FieldRegistry — whoosh-compat # parity leniency folds it into literal text, not a diagnostic/400. + # A result-level assertion that this fold actually matches nothing + # against real documents lives in + # test_acceptance.py::TestUnregisteredIdFieldFoldsToLiteralText. q = parse_user_query(query_index, "tag_id:5", UTC) assert isinstance(q, tantivy.Query)