Skip to content

Commit 1983067

Browse files
committed
Address review: document structural-set tie-breaking, add no-lookup formatter test
1 parent 5ec92d8 commit 1983067

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

opencontractserver/mcp/tests/test_mcp.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7265,6 +7265,16 @@ def test_structural_passage_resolves_document_slug(self):
72657265
self.assertEqual(hit["document_slug"], self.document.slug)
72667266
self.assertEqual(hit["document_title"], self.document.title)
72677267

7268+
def test_structural_passage_without_lookup_returns_none_slug(self):
7269+
"""Without a lookup the formatter preserves the old null-slug behaviour."""
7270+
from opencontractserver.mcp.formatters import format_search_passage
7271+
7272+
result = format_search_passage(
7273+
self.struct_ann, similarity_score=None, struct_doc_lookup=None
7274+
)
7275+
self.assertIsNone(result["document_slug"])
7276+
self.assertEqual(result["document_title"], "")
7277+
72687278

72697279
class MCPGetCorpusInfoLabelsTest(TestCase):
72707280
"""get_corpus_info surfaces only labels actually used on annotations (#1861)."""

opencontractserver/mcp/tools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ def search_corpus(
427427
.order_by("structural_annotation_set_id", "slug")
428428
.distinct()
429429
):
430+
# If a structural set maps to multiple corpus documents, pick
431+
# the first alphabetically by slug — deterministic (guaranteed
432+
# by the order_by above); the edge case is rare in practice.
430433
struct_doc_lookup.setdefault(set_id, (slug, title or ""))
431434

432435
formatted.extend(

0 commit comments

Comments
 (0)