From 7a9cb8738b349e69e387de98214dd676a02236ef Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:29:42 -0700 Subject: [PATCH] test(search): unify the two Schema.__reduce__() introspection sites _schema_field_names and TestFastFlagAgreement each independently reached into Schema.__reduce__()[1][0] - the one fragile, version-coupled expression this test suite depends on. Rename to _schema_fields, return {name: field-state} instead of just names, and have both call sites use it, so a tantivy-py upgrade that changes this shape breaks in one place. --- src/documents/tests/search/test_schema.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/documents/tests/search/test_schema.py b/src/documents/tests/search/test_schema.py index ac8798139..9e946d1a9 100644 --- a/src/documents/tests/search/test_schema.py +++ b/src/documents/tests/search/test_schema.py @@ -84,8 +84,8 @@ class TestNeedsRebuild: assert needs_rebuild(index_dir) is True -def _schema_field_names(schema: tantivy.Schema) -> set[str]: - """Return the set of field names declared on a tantivy Schema. +def _schema_fields(schema: tantivy.Schema) -> dict[str, dict]: + """{name: field-state} for every field declared on a tantivy Schema. tantivy-py 0.26 exposes no public introspection API on Schema (no __iter__, get_field, to_json, etc.) -- __reduce__() (used internally for @@ -93,13 +93,13 @@ def _schema_field_names(schema: tantivy.Schema) -> set[str]: here for test assertions only. """ state = schema.__reduce__()[1][0] - return {field["name"] for field in state["inner"]} + return {field["name"]: field for field in state["inner"]} class TestSchemaMatchesPublicFields: def test_every_public_field_is_in_the_schema(self) -> None: schema = build_schema() - schema_field_names = _schema_field_names(schema) + schema_field_names = set(_schema_fields(schema)) for field in PUBLIC_FIELDS: assert field.name in schema_field_names, ( f"{field.name} is in PUBLIC_FIELDS but missing from build_schema()" @@ -138,10 +138,9 @@ class TestFastFlagAgreement: # pins the agreement for EVERY kind: a future fast=True # TEXT/KEYWORD/JSON entry the builder silently ignores fails here # instead of at a user's query. - state = build_schema().__reduce__()[1][0] schema_fast = { - field["name"]: bool(field["options"].get("fast", False)) - for field in state["inner"] + name: bool(field["options"].get("fast", False)) + for name, field in _schema_fields(build_schema()).items() } for public_field in PUBLIC_FIELDS: assert schema_fast[public_field.name] == public_field.fast, (