@@ -28,8 +28,7 @@ async def test_config_import_from():
2828 os .makedirs (db_path , exist_ok = True )
2929 config_dict : Dict [str , Any ] = {
3030 "db_path" : db_path ,
31- "host" : "test_host" ,
32- "port" : 1234 ,
31+ "db_url" : "http://test_host:1234" ,
3332 "embedding_function" : "TestEmbedding" ,
3433 "embedding_params" : {"param1" : "value1" },
3534 "chunk_size" : 512 ,
@@ -42,8 +41,7 @@ async def test_config_import_from():
4241 config = await Config .import_from (config_dict )
4342 assert config .db_path == db_path
4443 assert config .db_log_path == os .path .expanduser ("~/.local/share/vectorcode/" )
45- assert config .host == "test_host"
46- assert config .port == 1234
44+ assert config .db_url == "http://test_host:1234"
4745 assert config .embedding_function == "TestEmbedding"
4846 assert config .embedding_params == {"param1" : "value1" }
4947 assert config .chunk_size == 512
@@ -54,6 +52,14 @@ async def test_config_import_from():
5452 assert config .db_settings == {"db_setting1" : "db_value1" }
5553
5654
55+ @pytest .mark .asyncio
56+ async def test_config_import_from_fallback_host_port ():
57+ conf = {"host" : "test_host" }
58+ assert (await Config .import_from (conf )).db_url == "http://test_host:8000"
59+ conf = {"port" : 114514 }
60+ assert (await Config .import_from (conf )).db_url == "http://127.0.0.1:114514"
61+
62+
5763@pytest .mark .asyncio
5864async def test_config_import_from_invalid_path ():
5965 config_dict : Dict [str , Any ] = {"db_path" : "/path/does/not/exist" }
@@ -75,22 +81,20 @@ async def test_config_import_from_db_path_is_file():
7581
7682@pytest .mark .asyncio
7783async def test_config_merge_from ():
78- config1 = Config (host = " host1" , port = 8001 , n_result = 5 )
79- config2 = Config (host = " host2" , port = None , query = ["test" ])
84+ config1 = Config (db_url = "http:// host1: 8001" , n_result = 5 )
85+ config2 = Config (db_url = "http:// host2:8002" , query = ["test" ])
8086 merged_config = await config1 .merge_from (config2 )
81- assert merged_config .host == "host2"
82- assert merged_config .port == 8001 # port from config1 should be retained
87+ assert merged_config .db_url == "http://host2:8002"
8388 assert merged_config .n_result == 5
8489 assert merged_config .query == ["test" ]
8590
8691
8792@pytest .mark .asyncio
8893async def test_config_merge_from_new_fields ():
89- config1 = Config (host = " host1" , port = 8001 )
94+ config1 = Config (db_url = "http:// host1: 8001" )
9095 config2 = Config (query = ["test" ], n_result = 10 , recursive = True )
9196 merged_config = await config1 .merge_from (config2 )
92- assert merged_config .host == "host1"
93- assert merged_config .port == 8001
97+ assert merged_config .db_url == "http://host1:8001"
9498 assert merged_config .query == ["test" ]
9599 assert merged_config .n_result == 10
96100 assert merged_config .recursive
@@ -104,8 +108,7 @@ async def test_config_import_from_missing_keys():
104108 # Assert that default values are used
105109 assert config .embedding_function == "SentenceTransformerEmbeddingFunction"
106110 assert config .embedding_params == {}
107- assert config .host == "localhost"
108- assert config .port == 8000
111+ assert config .db_url == "http://127.0.0.1:8000"
109112 assert config .db_path == os .path .expanduser ("~/.local/share/vectorcode/chromadb/" )
110113 assert config .chunk_size == 2500
111114 assert config .overlap_ratio == 0.2
@@ -318,7 +321,7 @@ def test_find_project_root():
318321async def test_get_project_config_no_local_config ():
319322 with tempfile .TemporaryDirectory () as temp_dir :
320323 config = await get_project_config (temp_dir )
321- assert config .host in { "127.0.0.1" , "localhost" }
324+ assert config .chunk_size == Config (). chunk_size , "Should load default value."
322325
323326
324327@pytest .mark .asyncio
@@ -394,36 +397,28 @@ async def test_parse_cli_args_vectorise_no_files():
394397
395398@pytest .mark .asyncio
396399async def test_get_project_config_local_config (tmp_path ):
397- # Create a temporary directory and a .vectorcode subdirectory
398400 project_root = tmp_path / "project"
399401 vectorcode_dir = project_root / ".vectorcode"
400402 vectorcode_dir .mkdir (parents = True )
401403
402- # Create a config.json file inside .vectorcode with some custom settings
403404 config_file = vectorcode_dir / "config.json"
404- config_file .write_text ('{"host ": "test_host", "port": 9999}' )
405+ config_file .write_text ('{"db_url ": "http:// test_host: 9999" }' )
405406
406- # Call get_project_config and check if it returns the custom settings
407407 config = await get_project_config (project_root )
408- assert config .host == "test_host"
409- assert config .port == 9999
408+ assert config .db_url == "http://test_host:9999"
410409
411410
412411@pytest .mark .asyncio
413412async def test_get_project_config_local_config_json5 (tmp_path ):
414- # Create a temporary directory and a .vectorcode subdirectory
415413 project_root = tmp_path / "project"
416414 vectorcode_dir = project_root / ".vectorcode"
417415 vectorcode_dir .mkdir (parents = True )
418416
419- # Create a config.json file inside .vectorcode with some custom settings
420417 config_file = vectorcode_dir / "config.json5"
421- config_file .write_text ('{"host ": "test_host", "port": 9999}' )
418+ config_file .write_text ('{"db_url ": "http:// test_host: 9999" }' )
422419
423- # Call get_project_config and check if it returns the custom settings
424420 config = await get_project_config (project_root )
425- assert config .host == "test_host"
426- assert config .port == 9999
421+ assert config .db_url == "http://test_host:9999"
427422
428423
429424def test_find_project_root_file_input (tmp_path ):
@@ -512,11 +507,9 @@ async def test_config_import_from_hnsw():
512507
513508@pytest .mark .asyncio
514509async def test_hnsw_config_merge ():
515- config1 = Config (host = "host1" , port = 8001 , hnsw = {"space" : "ip" })
516- config2 = Config (host = "host2" , port = None , hnsw = {"ef_construction" : 200 })
510+ config1 = Config (hnsw = {"space" : "ip" })
511+ config2 = Config (hnsw = {"ef_construction" : 200 })
517512 merged_config = await config1 .merge_from (config2 )
518- assert merged_config .host == "host2"
519- assert merged_config .port == 8001
520513 assert merged_config .hnsw ["space" ] == "ip"
521514 assert merged_config .hnsw ["ef_construction" ] == 200
522515
0 commit comments