@@ -214,51 +214,78 @@ def _clear_cache(self, monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
214214 yield
215215 _reset_db_path_mapping_cache ()
216216
217- def test_no_mapping (self ) -> None :
218- assert resolve_db_dir (Path ("/workspace/myproject" )) == Path (
219- "/workspace/myproject/.cocoindex_code"
220- )
221-
222- def test_single_mapping_match (self , monkeypatch : pytest .MonkeyPatch ) -> None :
223- monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "/workspace=/db-files" )
224- assert resolve_db_dir (Path ("/workspace/myproject" )) == Path ("/db-files/myproject" )
225-
226- def test_exact_root_match (self , monkeypatch : pytest .MonkeyPatch ) -> None :
227- monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "/workspace=/db-files" )
228- assert resolve_db_dir (Path ("/workspace" )) == Path ("/db-files" )
229-
230- def test_no_match_falls_back (self , monkeypatch : pytest .MonkeyPatch ) -> None :
231- monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "/workspace=/db-files" )
232- assert resolve_db_dir (Path ("/other/myproject" )) == Path ("/other/myproject/.cocoindex_code" )
233-
234- def test_multiple_mappings_first_wins (self , monkeypatch : pytest .MonkeyPatch ) -> None :
235- monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "/workspace=/db1,/workspace/sub=/db2" )
236- assert resolve_db_dir (Path ("/workspace/sub/proj" )) == Path ("/db1/sub/proj" )
237-
238- def test_multiple_mappings_second_matches (self , monkeypatch : pytest .MonkeyPatch ) -> None :
239- monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "/workspace=/db1,/other=/db2" )
240- assert resolve_db_dir (Path ("/other/proj" )) == Path ("/db2/proj" )
241-
242- def test_no_partial_component_match (self , monkeypatch : pytest .MonkeyPatch ) -> None :
243- monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "/workspace=/db-files" )
244- assert resolve_db_dir (Path ("/workspace2/proj" )) == Path ("/workspace2/proj/.cocoindex_code" )
217+ def test_no_mapping (self , tmp_path : Path ) -> None :
218+ project = tmp_path / "myproject"
219+ assert resolve_db_dir (project ) == project / ".cocoindex_code"
220+
221+ def test_single_mapping_match (self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
222+ src = tmp_path / "workspace"
223+ dst = tmp_path / "db-files"
224+ monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , f"{ src } ={ dst } " )
225+ assert resolve_db_dir (src / "myproject" ) == dst / "myproject"
226+
227+ def test_exact_root_match (self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
228+ src = tmp_path / "workspace"
229+ dst = tmp_path / "db-files"
230+ monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , f"{ src } ={ dst } " )
231+ assert resolve_db_dir (src ) == dst
232+
233+ def test_no_match_falls_back (self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
234+ src = tmp_path / "workspace"
235+ dst = tmp_path / "db-files"
236+ other = tmp_path / "other" / "myproject"
237+ monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , f"{ src } ={ dst } " )
238+ assert resolve_db_dir (other ) == other / ".cocoindex_code"
239+
240+ def test_multiple_mappings_first_wins (
241+ self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch
242+ ) -> None :
243+ src = tmp_path / "workspace"
244+ dst1 = tmp_path / "db1"
245+ dst2 = tmp_path / "db2"
246+ monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , f"{ src } ={ dst1 } ,{ src / 'sub' } ={ dst2 } " )
247+ assert resolve_db_dir (src / "sub" / "proj" ) == dst1 / "sub" / "proj"
248+
249+ def test_multiple_mappings_second_matches (
250+ self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch
251+ ) -> None :
252+ src1 = tmp_path / "workspace"
253+ src2 = tmp_path / "other"
254+ dst1 = tmp_path / "db1"
255+ dst2 = tmp_path / "db2"
256+ monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , f"{ src1 } ={ dst1 } ,{ src2 } ={ dst2 } " )
257+ assert resolve_db_dir (src2 / "proj" ) == dst2 / "proj"
258+
259+ def test_no_partial_component_match (
260+ self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch
261+ ) -> None :
262+ src = tmp_path / "workspace"
263+ dst = tmp_path / "db-files"
264+ other = tmp_path / "workspace2" / "proj"
265+ monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , f"{ src } ={ dst } " )
266+ assert resolve_db_dir (other ) == other / ".cocoindex_code"
245267
246268 def test_rejects_relative_source (self , monkeypatch : pytest .MonkeyPatch ) -> None :
247269 monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "relative/path=/db-files" )
248270 with pytest .raises (ValueError , match = "source path must be absolute" ):
249271 resolve_db_dir (Path ("/anything" ))
250272
251- def test_rejects_relative_target (self , monkeypatch : pytest .MonkeyPatch ) -> None :
252- monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "/workspace=relative/path" )
273+ def test_rejects_relative_target (self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
274+ src = tmp_path / "workspace"
275+ monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , f"{ src } =relative/path" )
253276 with pytest .raises (ValueError , match = "target path must be absolute" ):
254- resolve_db_dir (Path ("/anything" ))
255-
256- def test_skips_empty_entries (self , monkeypatch : pytest .MonkeyPatch ) -> None :
257- monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "/workspace=/db-files,,/other=/db2," )
258- assert resolve_db_dir (Path ("/other/proj" )) == Path ("/db2/proj" )
259-
260- def test_nested_project (self , monkeypatch : pytest .MonkeyPatch ) -> None :
261- monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , "/workspace=/db-files" )
262- assert resolve_db_dir (Path ("/workspace/org/repo/subdir" )) == Path (
263- "/db-files/org/repo/subdir"
264- )
277+ resolve_db_dir (tmp_path / "anything" )
278+
279+ def test_skips_empty_entries (self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
280+ src1 = tmp_path / "workspace"
281+ src2 = tmp_path / "other"
282+ dst1 = tmp_path / "db-files"
283+ dst2 = tmp_path / "db2"
284+ monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , f"{ src1 } ={ dst1 } ,,{ src2 } ={ dst2 } ," )
285+ assert resolve_db_dir (src2 / "proj" ) == dst2 / "proj"
286+
287+ def test_nested_project (self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
288+ src = tmp_path / "workspace"
289+ dst = tmp_path / "db-files"
290+ monkeypatch .setenv ("COCOINDEX_CODE_DB_PATH_MAPPING" , f"{ src } ={ dst } " )
291+ assert resolve_db_dir (src / "org" / "repo" / "subdir" ) == dst / "org" / "repo" / "subdir"
0 commit comments