@@ -355,7 +355,7 @@ async def test_query_success(mock_config):
355355 mock_collection = AsyncMock ()
356356
357357 with (
358- patch ("vectorcode.subcommands.query.get_client" , return_value = mock_client ) ,
358+ patch ("vectorcode.subcommands.query.ClientManager" ) as MockClientManager ,
359359 patch (
360360 "vectorcode.subcommands.query.get_collection" , return_value = mock_collection
361361 ),
@@ -367,6 +367,7 @@ async def test_query_success(mock_config):
367367 patch ("os.path.relpath" , return_value = "rel/path.py" ),
368368 patch ("os.path.abspath" , return_value = "/abs/path.py" ),
369369 ):
370+ MockClientManager .return_value ._create_client .return_value = mock_client
370371 # Set up the mock file paths and contents
371372 mock_get_files .return_value = ["file1.py" , "file2.py" ]
372373 mock_file_handle = MagicMock ()
@@ -396,7 +397,7 @@ async def test_query_pipe_mode(mock_config):
396397 mock_collection = AsyncMock ()
397398
398399 with (
399- patch ("vectorcode.subcommands.query.get_client" , return_value = mock_client ) ,
400+ patch ("vectorcode.subcommands.query.ClientManager" ) as MockClientManager ,
400401 patch (
401402 "vectorcode.subcommands.query.get_collection" , return_value = mock_collection
402403 ),
@@ -408,6 +409,7 @@ async def test_query_pipe_mode(mock_config):
408409 patch ("os.path.relpath" , return_value = "rel/path.py" ),
409410 patch ("os.path.abspath" , return_value = "/abs/path.py" ),
410411 ):
412+ MockClientManager .return_value ._create_client .return_value = mock_client
411413 # Set up the mock file paths and contents
412414 mock_get_files .return_value = ["file1.py" , "file2.py" ]
413415 mock_file_handle = MagicMock ()
@@ -434,7 +436,7 @@ async def test_query_absolute_path(mock_config):
434436 mock_collection = AsyncMock ()
435437
436438 with (
437- patch ("vectorcode.subcommands.query.get_client" , return_value = mock_client ) ,
439+ patch ("vectorcode.subcommands.query.ClientManager" ) as MockClientManager ,
438440 patch (
439441 "vectorcode.subcommands.query.get_collection" , return_value = mock_collection
440442 ),
@@ -445,6 +447,7 @@ async def test_query_absolute_path(mock_config):
445447 patch ("os.path.relpath" , return_value = "rel/path.py" ),
446448 patch ("os.path.abspath" , return_value = "/abs/path.py" ),
447449 ):
450+ MockClientManager .return_value ._create_client .return_value = mock_client
448451 # Set up the mock file paths and contents
449452 mock_get_files .return_value = ["file1.py" ]
450453 mock_file_handle = MagicMock ()
@@ -463,7 +466,7 @@ async def test_query_collection_not_found():
463466 config = Config (project_root = "/test/project" )
464467
465468 with (
466- patch ("vectorcode.subcommands.query.get_client " ),
469+ patch ("vectorcode.subcommands.query.ClientManager " ),
467470 patch ("vectorcode.subcommands.query.get_collection" ) as mock_get_collection ,
468471 patch ("sys.stderr" ),
469472 ):
@@ -482,7 +485,7 @@ async def test_query_invalid_collection():
482485 config = Config (project_root = "/test/project" )
483486
484487 with (
485- patch ("vectorcode.subcommands.query.get_client " ),
488+ patch ("vectorcode.subcommands.query.ClientManager " ),
486489 patch ("vectorcode.subcommands.query.get_collection" ) as mock_get_collection ,
487490 patch ("sys.stderr" ),
488491 ):
@@ -503,7 +506,7 @@ async def test_query_invalid_dimension():
503506 config = Config (project_root = "/test/project" )
504507
505508 with (
506- patch ("vectorcode.subcommands.query.get_client " ),
509+ patch ("vectorcode.subcommands.query.ClientManager " ),
507510 patch ("vectorcode.subcommands.query.get_collection" ) as mock_get_collection ,
508511 patch ("sys.stderr" ),
509512 ):
@@ -524,14 +527,15 @@ async def test_query_invalid_file(mock_config):
524527 mock_collection = AsyncMock ()
525528
526529 with (
527- patch ("vectorcode.subcommands.query.get_client" , return_value = mock_client ) ,
530+ patch ("vectorcode.subcommands.query.ClientManager" ) as MockClientManager ,
528531 patch (
529532 "vectorcode.subcommands.query.get_collection" , return_value = mock_collection
530533 ),
531534 patch ("vectorcode.subcommands.query.verify_ef" , return_value = True ),
532535 patch ("vectorcode.subcommands.query.get_query_result_files" ) as mock_get_files ,
533536 patch ("os.path.isfile" , return_value = False ),
534537 ):
538+ MockClientManager .return_value ._create_client .return_value = mock_client
535539 # Set up the mock file paths
536540 mock_get_files .return_value = ["invalid_file.py" ]
537541
@@ -549,12 +553,13 @@ async def test_query_invalid_ef(mock_config):
549553 mock_collection = AsyncMock ()
550554
551555 with (
552- patch ("vectorcode.subcommands.query.get_client" , return_value = mock_client ) ,
556+ patch ("vectorcode.subcommands.query.ClientManager" ) as MockClientManager ,
553557 patch (
554558 "vectorcode.subcommands.query.get_collection" , return_value = mock_collection
555559 ),
556560 patch ("vectorcode.subcommands.query.verify_ef" , return_value = False ),
557561 ):
562+ MockClientManager .return_value ._create_client .return_value = mock_client
558563 # Call the function
559564 result = await query (mock_config )
560565
@@ -580,13 +585,14 @@ async def test_query_chunk_mode_no_metadata_fallback(mock_config):
580585 mock_collection .get .return_value = {"ids" : []}
581586
582587 with (
583- patch ("vectorcode.subcommands.query.get_client" , return_value = mock_client ) ,
588+ patch ("vectorcode.subcommands.query.ClientManager" ) as MockClientManager ,
584589 patch (
585590 "vectorcode.subcommands.query.get_collection" , return_value = mock_collection
586591 ),
587592 patch ("vectorcode.subcommands.query.verify_ef" , return_value = True ),
588593 patch ("vectorcode.subcommands.query.build_query_results" ) as mock_build_results ,
589594 ):
595+ MockClientManager .return_value ._create_client .return_value = mock_client
590596 mock_build_results .return_value = [] # Return empty results for simplicity
591597
592598 result = await query (mock_config )
0 commit comments