@@ -25,9 +25,8 @@ async def test_list_collections_success():
2525 patch ("vectorcode.common.ClientManager" ) as MockClientManager ,
2626 ):
2727 mock_client = AsyncMock ()
28- mock_client_manager_instance = MockClientManager .return_value
29- mock_client_manager_instance .get_client = asynccontextmanager (
30- AsyncMock (return_value = mock_client )
28+ MockClientManager .return_value ._create_client = AsyncMock (
29+ return_value = mock_client
3130 )
3231
3332 mock_collection1 = AsyncMock ()
@@ -52,8 +51,7 @@ async def test_list_collections_no_metadata():
5251 patch ("vectorcode.common.ClientManager" ) as MockClientManager ,
5352 ):
5453 mock_client = AsyncMock ()
55- mock_client_manager_instance = MockClientManager .return_value
56- mock_client_manager_instance .get_client = asynccontextmanager (
54+ MockClientManager .return_value ._create_client = asynccontextmanager (
5755 AsyncMock (return_value = mock_client )
5856 )
5957 mock_collection1 = AsyncMock ()
@@ -105,9 +103,8 @@ async def test_query_tool_success():
105103 mock_load_config_file .return_value = mock_config
106104 mock_get_project_config .return_value = mock_config
107105 mock_client = AsyncMock ()
108- mock_client_manager_instance = MockClientManager .return_value
109- mock_client_manager_instance .get_client = asynccontextmanager (
110- AsyncMock (return_value = mock_client )
106+ MockClientManager .return_value ._create_client = AsyncMock (
107+ return_value = mock_client
111108 )
112109
113110 # Mock the collection's query method to return a valid QueryResult
@@ -144,14 +141,11 @@ async def test_query_tool_collection_access_failure():
144141 patch ("vectorcode.mcp_main.get_collection" ), # Still mock get_collection
145142 patch ("vectorcode.common.ClientManager" ) as MockClientManager ,
146143 ):
147- mock_client_manager_instance = MockClientManager .return_value
148144
149145 async def failing_get_client (* args , ** kwargs ):
150146 raise Exception ("Failed to connect" )
151147
152- mock_client_manager_instance .get_client = asynccontextmanager (
153- failing_get_client
154- )
148+ MockClientManager .return_value ._create_client .side_effect = failing_get_client
155149
156150 with pytest .raises (McpError ) as exc_info :
157151 await query_tool (
@@ -175,10 +169,7 @@ async def test_query_tool_no_collection():
175169 ) as mock_get_collection , # Still mock get_collection
176170 patch ("vectorcode.common.ClientManager" ) as MockClientManager ,
177171 ):
178- mock_client_manager_instance = MockClientManager .return_value
179- mock_client_manager_instance .get_client = asynccontextmanager (
180- AsyncMock ()
181- ) # Provide a working get_client
172+ MockClientManager .return_value ._create_client .return_value = AsyncMock ()
182173 mock_get_collection .return_value = None
183174
184175 with pytest .raises (McpError ) as exc_info :
@@ -223,15 +214,10 @@ async def test_vectorise_files_success():
223214 mock_get_project_config .return_value = mock_config
224215 mock_client = AsyncMock ()
225216
226- mock_client_manager_instance = MockClientManager .return_value
227217 # Ensure ClientManager's internal client creation method returns our mock.
228- mock_client_manager_instance ._create_client = AsyncMock (
218+ MockClientManager . return_value ._create_client = AsyncMock (
229219 return_value = mock_client
230220 )
231- # Ensure ClientManager's get_client context manager yields our mock.
232- mock_client_manager_instance .get_client = asynccontextmanager (
233- AsyncMock (return_value = mock_client )
234- )
235221
236222 mock_collection = AsyncMock ()
237223 mock_collection .get .return_value = {"ids" : [], "metadatas" : []}
@@ -257,14 +243,12 @@ async def test_vectorise_files_collection_access_failure(): # Removed client_ma
257243 ) as MockClientManager , # Patch ClientManager class
258244 patch ("vectorcode.mcp_main.get_collection" ),
259245 ):
260- mock_client_manager_instance = MockClientManager .return_value
261246
262247 async def failing_get_client (* args , ** kwargs ):
263248 raise Exception ("Client error" )
264249
265- mock_client_manager_instance .get_client = asynccontextmanager (
266- failing_get_client
267- )
250+ MockClientManager .return_value ._create_client = failing_get_client
251+
268252 with pytest .raises (McpError ) as exc_info :
269253 await vectorise_files (paths = ["file.py" ], project_root = "/valid/path" )
270254
@@ -317,13 +301,10 @@ def mock_open_side_effect(filename, *args, **kwargs):
317301 mock_config = Config (project_root = temp_dir )
318302 mock_get_project_config .return_value = mock_config
319303 mock_client = AsyncMock ()
320- mock_client_manager_instance = MockClientManager .return_value
321- mock_client_manager_instance ._create_client = AsyncMock (
304+ MockClientManager .return_value ._create_client = AsyncMock (
322305 return_value = mock_client
323306 )
324- mock_client_manager_instance .get_client = asynccontextmanager (
325- AsyncMock (return_value = mock_client )
326- )
307+
327308 mock_collection = AsyncMock ()
328309 mock_collection .get .return_value = {"ids" : [], "metadatas" : []}
329310 mock_get_collection .return_value = mock_collection
@@ -354,10 +335,8 @@ async def test_mcp_server():
354335 mock_find_project_config_dir .return_value = "/path/to/config"
355336 mock_load_config_file .return_value = Config (project_root = "/path/to/project" )
356337 mock_client = AsyncMock ()
357- mock_client_manager_instance = MockClientManager .return_value
358- mock_client_manager_instance .get_client = asynccontextmanager (
359- AsyncMock (return_value = mock_client )
360- )
338+
339+ MockClientManager .return_value .get_client = AsyncMock (return_value = mock_client )
361340 mock_collection = AsyncMock ()
362341 mock_get_collection .return_value = mock_collection
363342
@@ -387,9 +366,9 @@ async def test_mcp_server_ls_on_start():
387366 mock_find_project_config_dir .return_value = "/path/to/config"
388367 mock_load_config_file .return_value = Config (project_root = "/path/to/project" )
389368 mock_client = AsyncMock ()
390- mock_client_manager_instance = MockClientManager . return_value
391- mock_client_manager_instance . get_client = asynccontextmanager (
392- AsyncMock ( return_value = mock_client )
369+
370+ MockClientManager . return_value . _create_client = AsyncMock (
371+ return_value = mock_client
393372 )
394373 mock_collection = AsyncMock ()
395374 mock_collection .metadata = {"path" : "/path/to/project" }
0 commit comments