File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
72697279class MCPGetCorpusInfoLabelsTest (TestCase ):
72707280 """get_corpus_info surfaces only labels actually used on annotations (#1861)."""
Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments