test(retrieval): 增加检索测试数据与单元端到端测试

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yxx
2026-08-27 19:24:20 +08:00
co-authored by Claude
parent 6b16ad1a08
commit dbcb94b413
7 changed files with 347 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
"""pytest 全局隔离:把所有测试的数据目录/数据库/Vault 重定向到临时目录。
这样测试不会读写真实的 backend/data(真实索引与笔记),也使得「默认库应为空」这类
断言在任意本机状态下都确定成立——即使开发者已在本地跑过 rebuild。
"""
from __future__ import annotations
import pytest
from app.config import get_settings
@pytest.fixture(autouse=True)
def _isolate_data_dir(tmp_path, monkeypatch):
data_dir = tmp_path / "data"
monkeypatch.setenv("APP_DATA_DIR", str(data_dir))
monkeypatch.setenv("APP_DB_PATH", str(data_dir / "app.db"))
monkeypatch.setenv("APP_VAULT_PATH", str(tmp_path / "vault"))
# 清除 lru 缓存,让本次测试内的 get_settings() 读到临时目录
get_settings.cache_clear()
yield
get_settings.cache_clear()