Skip to content

Commit 8274cc3

Browse files
qin-ctxclaude
andauthored
fix: 修复单测以适配 vectordb 接口重构,统一测试数据路径 (#333)
- 修复 filesystem stat 错误匹配,增加 "not found" 判断 - 为 AddResourceRequest 添加 model_validator 校验 path 参数 - 处理 queue manager 未初始化时 ObserverService 的异常 - 简化 vectordb record ID 生成逻辑,移除 owner_space - 捕获 HTTP client close 时的 RuntimeError - 统一测试数据路径至 test_data/ 目录 - 更新测试用例使用 get_context_by_uri() 等新接口 - 移除测试 mock 对 VikingDBInterface 的依赖 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 38a29c0 commit 8274cc3

26 files changed

+77
-70
lines changed

.gitignore

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,6 @@ dmypy.json
157157
cython_debug/
158158
openviking/bin/
159159
test_scripts/
160-
test_large_scale_collection/
161-
162-
# Test-generated directories
163-
.tmp_*/
164-
db_test_*/
165-
test_recall_collection/
166-
test_db_*/
167-
test_project_root/
168-
benchmark_stress_db/
169160
examples/data/
170161
openviking/_version.py
171162
specs/

openviking/server/routers/filesystem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ async def stat(
7474
result = await service.fs.stat(uri, ctx=_ctx)
7575
return Response(status="ok", result=result)
7676
except AGFSClientError as e:
77-
if "no such file or directory" in str(e).lower():
77+
err_msg = str(e).lower()
78+
if "not found" in err_msg or "no such file or directory" in err_msg:
7879
raise NotFoundError(uri, "file")
7980
raise
8081

openviking/server/routers/resources.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Optional
99

1010
from fastapi import APIRouter, Depends, File, UploadFile
11-
from pydantic import BaseModel
11+
from pydantic import BaseModel, model_validator
1212

1313
from openviking.server.auth import get_request_context
1414
from openviking.server.dependencies import get_service
@@ -35,6 +35,12 @@ class AddResourceRequest(BaseModel):
3535
exclude: Optional[str] = None
3636
directly_upload_media: bool = True
3737

38+
@model_validator(mode="after")
39+
def check_path_or_temp_path(self):
40+
if not self.path and not self.temp_path:
41+
raise ValueError("Either 'path' or 'temp_path' must be provided")
42+
return self
43+
3844

3945
class AddSkillRequest(BaseModel):
4046
"""Request model for add_skill."""

openviking/service/debug_service.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ def _dependencies_ready(self) -> bool:
8181
@property
8282
def queue(self) -> ComponentStatus:
8383
"""Get queue status."""
84-
observer = QueueObserver(get_queue_manager())
84+
try:
85+
qm = get_queue_manager()
86+
except Exception:
87+
return ComponentStatus(
88+
name="queue",
89+
is_healthy=False,
90+
has_errors=True,
91+
status="Not initialized",
92+
)
93+
observer = QueueObserver(qm)
8594
return ComponentStatus(
8695
name="queue",
8796
is_healthy=observer.is_healthy(),

openviking/storage/collection_schemas.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ async def on_dequeue(self, data: Optional[Dict[str, Any]]) -> Optional[Dict[str,
204204
uri = inserted_data.get("uri")
205205
if uri:
206206
account_id = inserted_data.get("account_id", "default")
207-
owner_space = inserted_data.get("owner_space", "")
208-
id_seed = f"{account_id}:{owner_space}:{uri}"
207+
id_seed = f"{account_id}:{uri}"
209208
inserted_data["id"] = hashlib.md5(id_seed.encode("utf-8")).hexdigest()
210209

211210
record_id = await self._vikingdb.upsert(inserted_data)

openviking_cli/client/http.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ async def initialize(self) -> None:
183183
async def close(self) -> None:
184184
"""Close the HTTP client."""
185185
if self._http:
186-
await self._http.aclose()
186+
try:
187+
await self._http.aclose()
188+
except RuntimeError:
189+
pass
187190
self._http = None
188191

189192
# ============= Internal Helpers =============

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from openviking import AsyncOpenViking
1515

1616
# Test data root directory
17-
TEST_ROOT = Path(__file__).parent
18-
TEST_TMP_DIR = TEST_ROOT / ".tmp"
17+
PROJECT_ROOT = Path(__file__).parent.parent
18+
TEST_TMP_DIR = PROJECT_ROOT / "test_data" / "tmp"
1919

2020

2121
@pytest.fixture(scope="session")

tests/eval/test_ragas_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def test_generator_initialization():
3030

3131

3232
def test_pipeline_initialization():
33-
pipeline = RAGQueryPipeline(config_path="./test.conf", data_path="./test_data")
33+
pipeline = RAGQueryPipeline(config_path="./test.conf", data_path="./test_data/test_ragas")
3434
assert pipeline.config_path == "./test.conf"
35-
assert pipeline.data_path == "./test_data"
35+
assert pipeline.data_path == "./test_data/test_ragas"
3636
assert pipeline._client is None
3737

3838

tests/eval/test_ragas_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def test_pipeline_initialization():
105105

106106
from openviking.eval.ragas.pipeline import RAGQueryPipeline
107107

108-
pipeline = RAGQueryPipeline(config_path="./test.conf", data_path="./test_data")
108+
pipeline = RAGQueryPipeline(config_path="./test.conf", data_path="./test_data/test_ragas")
109109

110110
assert pipeline.config_path == "./test.conf"
111-
assert pipeline.data_path == "./test_data"
111+
assert pipeline.data_path == "./test_data/test_ragas"
112112
assert pipeline._client is None
113113

114114
print(" ✅ RAGQueryPipeline initialized successfully")

tests/integration/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from openviking.service.core import OpenVikingService
2323
from openviking_cli.session.user_id import UserIdentifier
2424

25-
TEST_ROOT = Path(__file__).parent
26-
TEST_TMP_DIR = TEST_ROOT / ".tmp_integration"
25+
PROJECT_ROOT = Path(__file__).parent.parent.parent
26+
TEST_TMP_DIR = PROJECT_ROOT / "test_data" / "tmp_integration"
2727

2828

2929
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)