@@ -67,6 +67,69 @@ async def test_chunked_add():
6767 assert collection .add .call_count == 1
6868
6969
70+ @pytest .mark .asyncio
71+ async def test_chunked_add_with_existing ():
72+ file_path = "test_file.py"
73+ collection = AsyncMock ()
74+ collection .get = AsyncMock ()
75+ collection .get .return_value = {"ids" : ["id1" ]}
76+ collection_lock = asyncio .Lock ()
77+ stats = {"add" : 0 , "update" : 0 }
78+ stats_lock = asyncio .Lock ()
79+ configs = Config (chunk_size = 100 , overlap_ratio = 0.2 , project_root = "." )
80+ max_batch_size = 50
81+ semaphore = asyncio .Semaphore (1 )
82+
83+ with patch ("vectorcode.chunking.TreeSitterChunker.chunk" ) as mock_chunk :
84+ mock_chunk .return_value = [Chunk ("chunk1" , Point (1 , 0 ), Point (1 , 5 )), "chunk2" ]
85+ await chunked_add (
86+ file_path ,
87+ collection ,
88+ collection_lock ,
89+ stats ,
90+ stats_lock ,
91+ configs ,
92+ max_batch_size ,
93+ semaphore ,
94+ )
95+
96+ assert stats ["add" ] == 0
97+ assert stats ["update" ] == 1
98+ collection .add .assert_called ()
99+ assert collection .add .call_count == 1
100+ collection .delete .assert_called
101+ assert collection .delete .call_count == 1
102+
103+
104+ @pytest .mark .asyncio
105+ async def test_chunked_add_empty_file ():
106+ file_path = "test_file.py"
107+ collection = AsyncMock ()
108+ collection_lock = asyncio .Lock ()
109+ stats = {"add" : 0 , "update" : 0 }
110+ stats_lock = asyncio .Lock ()
111+ configs = Config (chunk_size = 100 , overlap_ratio = 0.2 , project_root = "." )
112+ max_batch_size = 50
113+ semaphore = asyncio .Semaphore (1 )
114+
115+ with patch ("vectorcode.chunking.TreeSitterChunker.chunk" ) as mock_chunk :
116+ mock_chunk .return_value = []
117+ await chunked_add (
118+ file_path ,
119+ collection ,
120+ collection_lock ,
121+ stats ,
122+ stats_lock ,
123+ configs ,
124+ max_batch_size ,
125+ semaphore ,
126+ )
127+
128+ assert stats ["add" ] == 0
129+ assert stats ["update" ] == 0
130+ assert collection .add .call_count == 0
131+
132+
70133@patch ("tabulate.tabulate" )
71134def test_show_stats_pipe_false (mock_tabulate , capsys ):
72135 configs = Config (pipe = False )
0 commit comments