test: add DELETE endpoint tests and ingest integration tests

This commit is contained in:
2026-07-05 01:38:50 +08:00
parent 4114a168b4
commit 441ba8ab86
3 changed files with 63 additions and 1 deletions
+34
View File
@@ -85,3 +85,37 @@ class TestDocumentIngestor:
content = Path(temp_md_dir + "/test.md").read_text(encoding="utf-8")
assert "测试" in content
assert "这是测试内容" in content
class TestIngestorIntegration:
"""入库器集成测试 (使用真实 embedder)."""
def test_ingest_content_real(self, tmp_path):
"""真实入库: 分块→嵌入→入库."""
from src.core.config import EmbedConfig
from src.core.db import VectorDB
from src.core.embedder import create_embedder
from src.core.ingest import DocumentIngestor
db = VectorDB(persist_dir=str(tmp_path))
embedder = create_embedder(EmbedConfig(mode="local"))
ingestor = DocumentIngestor(db, embedder, "test_integration")
count = ingestor.ingest_content("# Hello\nWorld.", "hello.md")
assert count > 0
assert ingestor.collection.count() == count
def test_ingest_deduplicates(self, tmp_path):
"""重复入库同一文件会去重."""
from src.core.config import EmbedConfig
from src.core.db import VectorDB
from src.core.embedder import create_embedder
from src.core.ingest import DocumentIngestor
db = VectorDB(persist_dir=str(tmp_path))
embedder = create_embedder(EmbedConfig(mode="local"))
ingestor = DocumentIngestor(db, embedder, "test_dedup")
c1 = ingestor.ingest_content("# A", "dup.md")
c2 = ingestor.ingest_content("# B", "dup.md")
assert ingestor.collection.count() == c2