@@ -207,6 +207,52 @@ async def test_load_config_file_invalid_json():
207207 await load_config_file (config_path )
208208
209209
210+ @pytest .mark .asyncio
211+ async def test_load_config_file_merging ():
212+ with tempfile .TemporaryDirectory () as dummy_home :
213+ global_config_dir = os .path .join (dummy_home , ".config" , "vectorcode" )
214+ os .makedirs (global_config_dir , exist_ok = True )
215+ with open (os .path .join (global_config_dir , "config.json" ), mode = "w" ) as fin :
216+ fin .writelines (['{"embedding_function": "DummyEmbeddingFunction"}' ])
217+
218+ with tempfile .TemporaryDirectory (dir = dummy_home ) as proj_root :
219+ os .makedirs (os .path .join (proj_root , ".vectorcode" ), exist_ok = True )
220+ with open (
221+ os .path .join (proj_root , ".vectorcode" , "config.json" ), mode = "w"
222+ ) as fin :
223+ fin .writelines (
224+ ['{"embedding_function": "AnotherDummyEmbeddingFunction"}' ]
225+ )
226+
227+ with patch (
228+ "vectorcode.cli_utils.GLOBAL_CONFIG_DIR" , new = str (global_config_dir )
229+ ):
230+ assert (
231+ await load_config_file ()
232+ ).embedding_function == "DummyEmbeddingFunction"
233+ assert (
234+ await load_config_file (proj_root )
235+ ).embedding_function == "AnotherDummyEmbeddingFunction"
236+
237+
238+ @pytest .mark .asyncio
239+ async def test_load_config_file_with_envs ():
240+ with tempfile .TemporaryDirectory () as proj_root :
241+ os .makedirs (os .path .join (proj_root , ".vectorcode" ), exist_ok = True )
242+ with (
243+ open (
244+ os .path .join (proj_root , ".vectorcode" , "config.json" ), mode = "w"
245+ ) as fin ,
246+ ):
247+ fin .writelines (['{"embedding_function": "$DUMMY_EMBEDDING_FUNCTION"}' ])
248+ with patch .dict (
249+ os .environ , {"DUMMY_EMBEDDING_FUNCTION" : "DummyEmbeddingFunction" }
250+ ):
251+ assert (
252+ await load_config_file (proj_root )
253+ ).embedding_function == "DummyEmbeddingFunction"
254+
255+
210256@pytest .mark .asyncio
211257async def test_load_from_default_config ():
212258 for name in ("config.json5" , "config.json" ):
0 commit comments