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/test_models.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

47 lines
1.5 KiB
Python

import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent / 'src'))
from datetime import datetime
from models.episode import Episode
from models.distilled import Distilled, TYPE_FACT
def test_episode_to_dict_from_dict():
ep = Episode.create(content='test content', source='test', entities=['entity1'], facts=['fact1'])
d = ep.to_dict()
assert d['content'] == 'test content'
assert d['source'] == 'test'
ep2 = Episode.from_dict(d)
assert ep2.content == ep.content
assert ep2.id == ep.id
def test_episode_create():
ep = Episode.create(content='hello')
assert ep.id is not None
assert ep.content == 'hello'
assert ep.source == 'hermes'
assert isinstance(ep.timestamp, datetime)
def test_distilled_to_dict_from_dict():
ep = Episode.create(content='test')
d = Distilled(
id='d1', episode_id=ep.id, type=TYPE_FACT,
summary='a summary', importance=0.8
)
dd = d.to_dict()
assert dd['type'] == TYPE_FACT
assert dd['importance'] == 0.8
d2 = Distilled.from_dict(dd)
assert d2.id == d.id
assert d2.type == d.type
def test_distilled_defaults():
d = Distilled(id='d1', episode_id='e1', type=TYPE_FACT, summary='s')
assert d.importance == 0.0
assert d.tier == 'normal'
if __name__ == '__main__':
test_episode_to_dict_from_dict()
test_episode_create()
test_distilled_to_dict_from_dict()
test_distilled_defaults()
print('All model tests passed!')