@@ -91,6 +91,7 @@ async def test_query_tool_success():
9191 mock_client = AsyncMock ()
9292
9393 with tempfile .TemporaryDirectory () as temp_dir :
94+ os .chdir (temp_dir )
9495 # Mock the collection's query method to return a valid QueryResult
9596 mock_collection = AsyncMock ()
9697 mock_collection .query .return_value = {
@@ -103,7 +104,7 @@ async def test_query_tool_success():
103104 "distances" : [[0.1 , 0.2 ]], # Valid distances
104105 }
105106 for i in range (1 , 3 ):
106- with open (f"file{ i } .py" , "w" ) as fin :
107+ with open (os . path . join ( temp_dir , f"file{ i } .py" ) , "w" ) as fin :
107108 fin .writelines ([f"doc{ i } " ])
108109 with (
109110 patch ("vectorcode.mcp_main.get_project_config" ) as mock_get_project_config ,
@@ -126,9 +127,9 @@ async def test_query_tool_success():
126127
127128 mock_get_collection .return_value = mock_collection
128129
129- mock_get_query_result_files .return_value = ["file1.py" , "file2.py" ]
130- mock_file_handle = MagicMock ( )
131- mock_file_handle . __enter__ . return_value . read . return_value = "file content"
130+ mock_get_query_result_files .return_value = [
131+ os . path . join ( temp_dir , i ) for i in ( "file1.py" , "file2.py" )
132+ ]
132133
133134 result = await query_tool (
134135 n_query = 2 , query_messages = ["keyword1" ], project_root = temp_dir
@@ -202,7 +203,7 @@ async def test_vectorise_files_success():
202203 f .write ("def func(): pass" )
203204 mock_client = AsyncMock ()
204205
205- mock_embedding_function = AsyncMock (return_value = numpy .random .random ((100 ,)))
206+ mock_embedding_function = MagicMock (return_value = numpy .random .random ((100 ,)))
206207 with (
207208 patch ("os.path.isdir" , return_value = True ),
208209 patch ("vectorcode.mcp_main.get_project_config" ) as mock_get_project_config ,
0 commit comments