@@ -217,6 +217,123 @@ async def test_execute_command_ls(mock_language_server, mock_config):
217217 mock_language_server .progress .end .assert_called ()
218218
219219
220+ @pytest .mark .asyncio
221+ async def test_execute_command_vectorise (mock_language_server , mock_config : Config ):
222+ mock_config .action = CliAction .vectorise # Set action to vectorise
223+ mock_config .project_root = "/test/project" # Ensure project_root is set
224+ mock_config .files = None # Simulate no files explicitly passed, so load_files_from_include is called
225+ mock_config .recursive = True
226+ mock_config .include_hidden = False
227+ mock_config .force = False # To test exclude_paths_by_spec path
228+
229+ # Files that load_files_from_include will return and expand_globs will process
230+ dummy_initial_files = ["file_a.py" , "file_b.txt" ]
231+ # Files after expand_globs
232+ dummy_expanded_files = ["/test/project/file_a.py" , "/test/project/file_b.txt" ]
233+
234+ # Mock dependencies
235+ with (
236+ patch (
237+ "vectorcode.lsp_main.parse_cli_args" , new_callable = AsyncMock
238+ ) as mock_parse_cli_args ,
239+ patch (
240+ "vectorcode.lsp_main.get_client" , new_callable = AsyncMock
241+ ) as mock_get_client ,
242+ patch (
243+ "vectorcode.lsp_main.get_collection" , new_callable = AsyncMock
244+ ) as mock_get_collection ,
245+ patch (
246+ "vectorcode.lsp_main.expand_globs" , new_callable = AsyncMock
247+ ) as mock_expand_globs ,
248+ patch (
249+ "vectorcode.lsp_main.find_exclude_specs" , return_value = []
250+ ) as mock_find_exclude_specs ,
251+ patch (
252+ "vectorcode.lsp_main.exclude_paths_by_spec" ,
253+ side_effect = lambda files , spec : files ,
254+ ) as mock_exclude_paths_by_spec ,
255+ patch (
256+ "vectorcode.lsp_main.chunked_add" , new_callable = AsyncMock
257+ ) as mock_chunked_add ,
258+ patch ("vectorcode.lsp_main.try_server" , return_value = True ),
259+ patch ("vectorcode.lsp_main.cached_project_configs" , {}),
260+ patch (
261+ "vectorcode.lsp_main.load_files_from_include" ,
262+ return_value = dummy_initial_files ,
263+ ) as mock_load_files_from_include ,
264+ patch ("os.cpu_count" , return_value = 1 ), # For asyncio.Semaphore
265+ patch (
266+ "vectorcode.lsp_main.make_caches" , new_callable = AsyncMock
267+ ), # Mock make_caches to avoid actual file system ops
268+ ):
269+ from unittest .mock import ANY
270+
271+ from lsprotocol import types
272+
273+ from vectorcode .lsp_main import cached_project_configs
274+
275+ cached_project_configs .clear ()
276+ cached_project_configs ["/test/project" ] = mock_config # Add config to cache
277+
278+ # Set return values for mocks
279+ mock_parse_cli_args .return_value = mock_config
280+ mock_client = AsyncMock ()
281+ mock_get_client .return_value = mock_client
282+ mock_collection = MagicMock ()
283+ mock_get_collection .return_value = mock_collection
284+ mock_client .get_max_batch_size .return_value = 100 # Mock batch size
285+
286+ mock_expand_globs .return_value = (
287+ dummy_expanded_files # What expand_globs should return
288+ )
289+
290+ # Mock merge_from as it's called
291+ mock_config .merge_from = AsyncMock (return_value = mock_config )
292+
293+ # Execute the command
294+ await execute_command (mock_language_server , ["vectorise" , "/test/project" ])
295+
296+ # Assertions
297+ mock_language_server .progress .create_async .assert_called_once ()
298+ mock_language_server .progress .begin .assert_called_once_with (
299+ ANY , # progress_token
300+ types .WorkDoneProgressBegin (
301+ title = "VectorCode" , message = "Vectorising files..." , percentage = 0
302+ ),
303+ )
304+
305+ mock_load_files_from_include .assert_called_once_with (
306+ str (mock_config .project_root )
307+ )
308+ mock_expand_globs .assert_called_once_with (
309+ dummy_initial_files , # Should be the result of load_files_from_include
310+ recursive = mock_config .recursive ,
311+ include_hidden = mock_config .include_hidden ,
312+ )
313+ mock_find_exclude_specs .assert_called_once_with (mock_config )
314+ mock_exclude_paths_by_spec .assert_not_called () # Because mock_find_exclude_specs returns empty list (no specs to exclude by)
315+ mock_client .get_max_batch_size .assert_called_once ()
316+
317+ # Check chunked_add calls
318+ assert mock_chunked_add .call_count == len (dummy_expanded_files )
319+ for file_path in dummy_expanded_files :
320+ mock_chunked_add .assert_any_call (
321+ file_path ,
322+ mock_collection ,
323+ ANY , # asyncio.Lock object
324+ ANY , # stats dict
325+ ANY , # stats_lock
326+ mock_config ,
327+ 100 , # max_batch_size
328+ ANY , # semaphore
329+ )
330+ # Check progress report calls
331+ assert mock_language_server .progress .report .call_count == len (
332+ dummy_expanded_files
333+ )
334+ mock_language_server .progress .end .assert_called_once ()
335+
336+
220337@pytest .mark .asyncio
221338async def test_execute_command_unsupported_action (
222339 mock_language_server , mock_config , capsys
0 commit comments