test: 补充测试覆盖率 — DB/CLI/Search/Ingest + 修复 chromadb 异常兼容

This commit is contained in:
2026-07-11 20:02:24 +08:00
parent 10c5d3d347
commit 6b89488677
6 changed files with 108 additions and 0 deletions
+22
View File
@@ -122,3 +122,25 @@ class TestSearcher:
searcher = Searcher(db, embedder, "empty_coll")
sources = searcher.list_sources()
assert sources == []
def test_list_sources_empty():
"""空 collection 的 list_sources 返回空列表."""
from src.core.search import Searcher
class EmptyColl:
def count(self): return 0
def get(self, **kwargs):
return {"ids": [], "documents": [], "metadatas": []}
class EmptyDB:
def get_or_create_collection(self, name): return EmptyColl()
def list_collections(self): return []
class FakeEmb:
@property
def dimension(self): return 4
def embed(self, texts): return [[0.0] * 4]
s = Searcher(EmptyDB(), FakeEmb(), "empty")
assert s.list_sources() == []