This repository has been archived on 2026-09-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
zhiyi/tests/conftest.py
T
小唯 A06 a05d13e209 feat(v3.1): P0-P3全面优化完成
P0稳定性:
- pytest测试框架 + conftest.py(87测试全通过)
- API Key认证中间件(X-API-Key Header)
- Pydantic输入验证增强

P1可靠性:
- 结构化日志(JSON/彩色双模式,commit/recall/redis关键路径)
- 健康检查增强(Redis/磁盘空间/索引完整性/实例状态)
- 备份脚本(data/+Redis RDB,保留10份)

P2性能/体验:
- FAISS IVFFlat升级(doc>1000自动触发)
- OpenAPI文档完整化(/docs, /redoc)
- 批量API(/commit/batch, /recall/batch已存在)
- 同义词Query扩展(42组同义词,recall路由集成)

P3调研:
- GPU加速调研(RTX 3050方案)
- 图谱可视化调研(3362节点可视图)
- 自然语言查询调研

其他:
- logger.py/StructuredLogger兼容
- Health check返回degraded状态
- 版本升至3.1
2026-05-26 17:39:07 +08:00

87 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
pytest configuration and shared fixtures for zhiyi tests.
"""
import sys
from pathlib import Path
# Add src to path for imports
sys.path.insert(0, str(Path(__file__).parent.parent / 'src'))
import pytest
import pytest_asyncio
from datetime import datetime
from typing import List
from models.episode import Episode
from models.distilled import Distilled, TYPE_FACT
# ---------------------------------------------------------------------------
# Fake embedder (list-based, no real bge-m3 model)
# ---------------------------------------------------------------------------
class FakeEmbedder:
"""Simple list-based fake embedder for fast tests.
Returns a fixed-size vector of ones. The embedding dimension is
configurable (default 4) so tests run fast without loading the real
bge-m3 model.
"""
def __init__(self, dim: int = 4):
self.dim = dim
def encode(self, texts: List[str], **kwargs) -> List[List[float]]:
"""Return fake vectors – one per input text."""
return [[1.0] * self.dim for _ in texts]
async def encode_async(self, texts: List[str], **kwargs) -> List[List[float]]:
"""Async wrapper – delegates to encode()."""
return self.encode(texts, **kwargs)
@pytest.fixture
def fake_embedder():
"""Provides a FakeEmbedder instance."""
return FakeEmbedder(dim=4)
# ---------------------------------------------------------------------------
# Shared data fixtures
# ---------------------------------------------------------------------------
@pytest.fixture
def sample_episode():
"""A basic Episode instance for use across tests."""
return Episode.create(
content='Alice met Bob at the cafe yesterday.',
source='test',
entities=['Alice', 'Bob'],
facts=['Alice met Bob at a cafe'],
)
@pytest.fixture
def sample_distilled():
"""A basic Distilled instance for use across tests."""
ep = Episode.create(content='Test content')
return Distilled(
id='distilled-1',
episode_id=ep.id,
type=TYPE_FACT,
summary='Test summary of the distilled content.',
importance=0.5,
)
# ---------------------------------------------------------------------------
# Async event loop fixture
# ---------------------------------------------------------------------------
@pytest_asyncio.fixture
async def async_event_loop():
"""Provides a fresh event loop for each async test."""
import asyncio
loop = asyncio.new_event_loop()
yield loop
loop.close()