11import unittest
2+ from unittest .mock import AsyncMock , patch
23
3- from pageindex .page_index_md import extract_nodes_from_markdown
4+ from pageindex .page_index_md import extract_nodes_from_markdown , get_node_summary
45
56
67class ExtractNodesFromMarkdownTest (unittest .TestCase ):
@@ -19,5 +20,31 @@ def test_skips_bold_heading_with_only_whitespace(self):
1920 )
2021
2122
23+ class GetNodeSummaryTest (unittest .IsolatedAsyncioTestCase ):
24+ async def test_below_threshold_uses_node_text_without_calling_llm (self ):
25+ node = {"text" : "short section" }
26+
27+ with patch ("pageindex.page_index_md.count_tokens" , return_value = 199 ), patch (
28+ "pageindex.page_index_md.generate_node_summary" , new_callable = AsyncMock
29+ ) as generate_summary :
30+ summary = await get_node_summary (node , summary_token_threshold = 200 )
31+
32+ self .assertEqual (summary , node ["text" ])
33+ generate_summary .assert_not_awaited ()
34+
35+ async def test_threshold_boundary_generates_a_summary (self ):
36+ node = {"text" : "boundary section" }
37+
38+ with patch ("pageindex.page_index_md.count_tokens" , return_value = 200 ), patch (
39+ "pageindex.page_index_md.generate_node_summary" ,
40+ new_callable = AsyncMock ,
41+ return_value = "generated summary" ,
42+ ) as generate_summary :
43+ summary = await get_node_summary (node , summary_token_threshold = 200 )
44+
45+ self .assertEqual (summary , "generated summary" )
46+ generate_summary .assert_awaited_once_with (node , model = None )
47+
48+
2249if __name__ == "__main__" :
2350 unittest .main ()
0 commit comments