1- """Unit tests for internal helper methods of ``CompositeRetriever``.
1+ """Test internal helper methods of ``CompositeRetriever``.
22
33The goal of these tests is to verify the transformation semantics of:
44 - _use_summaries
@@ -40,6 +40,10 @@ def _mk_doc(
4040
4141@pytest .mark .asyncio
4242async def test_use_summaries_expands_and_removes_summary ():
43+ """Expand a summary into its related documents.
44+
45+ Verify that summary documents are removed and replaced by their related underlying documents.
46+ """
4347 # Summary references an underlying doc not in initial results.
4448 underlying = _mk_doc ("doc1" , score = 0.9 )
4549 summary = _mk_doc ("sum1" , doc_type = ContentType .SUMMARY , related = ["doc1" ]) # type: ignore[arg-type]
@@ -57,6 +61,10 @@ async def test_use_summaries_expands_and_removes_summary():
5761
5862
5963def test_use_summaries_only_summary_no_related ():
64+ """Drop a summary document that has no related documents.
65+
66+ Verify that the returned result is empty when no related ids are present.
67+ """
6068 summary = _mk_doc ("sum1" , doc_type = ContentType .SUMMARY , related = []) # type: ignore[arg-type]
6169 retriever = MockRetrieverQuark ([summary ])
6270 cr = CompositeRetriever (retrievers = [retriever ], reranker = None , reranker_enabled = False )
@@ -66,6 +74,10 @@ def test_use_summaries_only_summary_no_related():
6674
6775
6876def test_remove_duplicates_preserves_first_occurrence ():
77+ """Preserve the first occurrence when duplicate ids are present.
78+
79+ Verify that duplicate documents are removed while maintaining the original order.
80+ """
6981 d1a = _mk_doc ("a" )
7082 d1b = _mk_doc ("a" ) # duplicate id
7183 d2 = _mk_doc ("b" )
@@ -76,6 +88,10 @@ def test_remove_duplicates_preserves_first_occurrence():
7688
7789
7890def test_early_pruning_sorts_by_score_when_all_have_score ():
91+ """Sort by score and keep only the top-k documents.
92+
93+ Verify that documents are sorted descending by score when all documents include scores.
94+ """
7995 docs = [_mk_doc ("a" , score = 0.7 ), _mk_doc ("b" , score = 0.9 ), _mk_doc ("c" , score = 0.8 )]
8096 retriever = MockRetrieverQuark (docs )
8197 cr = CompositeRetriever (
@@ -87,6 +103,10 @@ def test_early_pruning_sorts_by_score_when_all_have_score():
87103
88104
89105def test_early_pruning_preserves_order_without_scores ():
106+ """Preserve input order when pruning without score metadata.
107+
108+ Verify that pruning keeps the original order when scores are absent.
109+ """
90110 docs = [_mk_doc ("a" ), _mk_doc ("b" ), _mk_doc ("c" )] # no scores
91111 retriever = MockRetrieverQuark (docs )
92112 cr = CompositeRetriever (
@@ -98,6 +118,10 @@ def test_early_pruning_preserves_order_without_scores():
98118
99119@pytest .mark .asyncio
100120async def test_arerank_pruning_invokes_reranker_when_needed ():
121+ """Invoke the reranker when more than k documents are retrieved.
122+
123+ Verify that the reranker is called and that the returned list is trimmed to ``reranker_k_documents``.
124+ """
101125 docs = [_mk_doc ("a" , score = 0.5 ), _mk_doc ("b" , score = 0.7 ), _mk_doc ("c" , score = 0.9 )]
102126 retriever = MockRetrieverQuark (docs )
103127 reranker = MockReranker ()
@@ -116,6 +140,10 @@ async def test_arerank_pruning_invokes_reranker_when_needed():
116140
117141@pytest .mark .asyncio
118142async def test_arerank_pruning_skips_when_not_needed ():
143+ """Skip reranking when the retrieved docs are already within k.
144+
145+ Verify that the reranker is not invoked when no pruning is required.
146+ """
119147 docs = [_mk_doc ("a" , score = 0.5 ), _mk_doc ("b" , score = 0.7 )] # already <= k
120148 retriever = MockRetrieverQuark (docs )
121149 reranker = MockReranker ()
0 commit comments