@@ -370,9 +370,7 @@ async def test_vectorise(capsys):
370370
371371 with ExitStack () as stack :
372372 stack .enter_context (
373- patch (
374- "vectorcode.subcommands.vectorise.get_client" , return_value = mock_client
375- )
373+ patch ("vectorcode.subcommands.vectorise.ClientManager" ),
376374 )
377375 stack .enter_context (patch ("os.path.isfile" , return_value = False ))
378376 stack .enter_context (
@@ -427,7 +425,7 @@ async def mock_chunked_add(*args, **kwargs):
427425 "vectorcode.subcommands.vectorise.chunked_add" , side_effect = mock_chunked_add
428426 ) as mock_add ,
429427 patch ("sys.stderr" ) as mock_stderr ,
430- patch ("vectorcode.subcommands.vectorise.get_client" , return_value = mock_client ) ,
428+ patch ("vectorcode.subcommands.vectorise.ClientManager" ) as MockClientManager ,
431429 patch (
432430 "vectorcode.subcommands.vectorise.get_collection" ,
433431 return_value = mock_collection ,
@@ -438,6 +436,7 @@ async def mock_chunked_add(*args, **kwargs):
438436 lambda x : not (x .endswith ("gitignore" ) or x .endswith ("vectorcode.exclude" )),
439437 ),
440438 ):
439+ MockClientManager .return_value ._create_client .return_value = mock_client
441440 result = await vectorise (configs )
442441 assert result == 1
443442 mock_add .assert_called_once ()
@@ -458,7 +457,7 @@ async def test_vectorise_orphaned_files():
458457 pipe = False ,
459458 )
460459
461- mock_client = AsyncMock ()
460+ AsyncMock ()
462461 mock_collection = AsyncMock ()
463462
464463 # Define a mock response for collection.get in vectorise
@@ -494,7 +493,7 @@ def is_file_side_effect(path):
494493 "vectorcode.subcommands.vectorise.TreeSitterChunker" ,
495494 return_value = mock_chunker ,
496495 ),
497- patch ("vectorcode.subcommands.vectorise.get_client" , return_value = mock_client ),
496+ patch ("vectorcode.subcommands.vectorise.ClientManager" ),
498497 patch (
499498 "vectorcode.subcommands.vectorise.get_collection" ,
500499 return_value = mock_collection ,
@@ -532,10 +531,11 @@ async def test_vectorise_collection_index_error():
532531 mock_client = AsyncMock ()
533532
534533 with (
535- patch ("vectorcode.subcommands.vectorise.get_client" , return_value = mock_client ) ,
534+ patch ("vectorcode.subcommands.vectorise.ClientManager" ) as MockClientManager ,
536535 patch ("vectorcode.subcommands.vectorise.get_collection" ) as mock_get_collection ,
537536 patch ("os.path.isfile" , return_value = False ),
538537 ):
538+ MockClientManager .return_value ._create_client .return_value = mock_client
539539 mock_get_collection .side_effect = IndexError ("Collection not found" )
540540 result = await vectorise (configs )
541541 assert result == 1
@@ -558,14 +558,15 @@ async def test_vectorise_verify_ef_false():
558558 mock_collection = AsyncMock ()
559559
560560 with (
561- patch ("vectorcode.subcommands.vectorise.get_client" , return_value = mock_client ) ,
561+ patch ("vectorcode.subcommands.vectorise.ClientManager" ) as MockClientManager ,
562562 patch (
563563 "vectorcode.subcommands.vectorise.get_collection" ,
564564 return_value = mock_collection ,
565565 ),
566566 patch ("vectorcode.subcommands.vectorise.verify_ef" , return_value = False ),
567567 patch ("os.path.isfile" , return_value = False ),
568568 ):
569+ MockClientManager .return_value ._create_client .return_value = mock_client
569570 result = await vectorise (configs )
570571 assert result == 1
571572
@@ -588,7 +589,7 @@ async def test_vectorise_gitignore():
588589 mock_collection .get .return_value = {"metadatas" : []}
589590
590591 with (
591- patch ("vectorcode.subcommands.vectorise.get_client" , return_value = mock_client ) ,
592+ patch ("vectorcode.subcommands.vectorise.ClientManager" ) as MockClientManager ,
592593 patch (
593594 "vectorcode.subcommands.vectorise.get_collection" ,
594595 return_value = mock_collection ,
@@ -608,6 +609,7 @@ async def test_vectorise_gitignore():
608609 "vectorcode.subcommands.vectorise.exclude_paths_by_spec"
609610 ) as mock_exclude_paths ,
610611 ):
612+ MockClientManager .return_value ._create_client .return_value = mock_client
611613 await vectorise (configs )
612614 mock_exclude_paths .assert_called_once ()
613615
@@ -635,7 +637,7 @@ async def test_vectorise_exclude_file(tmpdir):
635637 mock_collection .get .return_value = {"ids" : []}
636638
637639 with (
638- patch ("vectorcode.subcommands.vectorise.get_client" , return_value = mock_client ) ,
640+ patch ("vectorcode.subcommands.vectorise.ClientManager" ) as MockClientManager ,
639641 patch (
640642 "vectorcode.subcommands.vectorise.get_collection" ,
641643 return_value = mock_collection ,
@@ -652,6 +654,7 @@ async def test_vectorise_exclude_file(tmpdir):
652654 ),
653655 patch ("vectorcode.subcommands.vectorise.chunked_add" ) as mock_chunked_add ,
654656 ):
657+ MockClientManager .return_value ._create_client .return_value = mock_client
655658 await vectorise (configs )
656659 # Assert that chunked_add is only called for test_file.py, not excluded_file.py
657660 call_args = [call [0 ][0 ] for call in mock_chunked_add .call_args_list ]
@@ -664,7 +667,6 @@ async def test_vectorise_exclude_file(tmpdir):
664667
665668
666669@pytest .mark .asyncio
667- @patch ("vectorcode.subcommands.vectorise.get_client" , new_callable = AsyncMock )
668670@patch ("vectorcode.subcommands.vectorise.get_collection" , new_callable = AsyncMock )
669671@patch ("vectorcode.subcommands.vectorise.expand_globs" , new_callable = AsyncMock )
670672@patch ("vectorcode.subcommands.vectorise.chunked_add" , new_callable = AsyncMock )
@@ -681,7 +683,6 @@ async def test_vectorise_uses_global_exclude_when_local_missing(
681683 mock_chunked_add ,
682684 mock_expand_globs ,
683685 mock_get_collection ,
684- mock_get_client ,
685686 tmp_path ,
686687):
687688 """
@@ -712,14 +713,20 @@ def isfile_side_effect(p):
712713
713714 global_exclude_content = "*.bin"
714715 m_open = mock_open (read_data = global_exclude_content )
715- with patch ("builtins.open" , m_open ):
716+ with (
717+ patch ("builtins.open" , m_open ),
718+ patch ("vectorcode.subcommands.vectorise.ClientManager" ) as MockClientManager ,
719+ ):
716720 mock_spec_instance = MagicMock ()
717721 mock_spec_instance .match_file = lambda path : str (path ).endswith (".bin" )
718722 mock_gitignore_spec .from_lines .return_value = mock_spec_instance
719723
720724 mock_client_instance = AsyncMock ()
721725 mock_client_instance .get_max_batch_size = AsyncMock (return_value = 100 )
722- mock_get_client .return_value = mock_client_instance
726+
727+ MockClientManager .return_value ._create_client .return_value = (
728+ mock_client_instance
729+ )
723730
724731 mock_collection_instance = AsyncMock ()
725732 mock_collection_instance .get = AsyncMock (
0 commit comments