test: 添加 PromptManager 和 Web API 基础测试
- test_prompt_manager.py: 验证系统提示词包含5步流程、所有工具列表、无Python函数注记 - test_web_api.py: 验证关键API端点存在、静态文件路径正确、提示词可加载
This commit is contained in:
88
tests/test_core/test_prompt_manager.py
Normal file
88
tests/test_core/test_prompt_manager.py
Normal file
@ -0,0 +1,88 @@
|
||||
"""Tests for PromptManager - system prompt loading"""
|
||||
|
||||
from core.prompts import PromptManager
|
||||
|
||||
|
||||
def test_get_system_prompt_not_empty():
|
||||
"""系统提示词不应为空"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert prompt is not None
|
||||
assert len(prompt) > 100
|
||||
|
||||
|
||||
def test_system_prompt_contains_identity():
|
||||
"""系统提示词应包含核心身份"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert "TrulyMEM" in prompt
|
||||
|
||||
|
||||
def test_system_prompt_has_execution_order():
|
||||
"""系统提示词应包含强制执行顺序"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert "强制执行顺序" in prompt
|
||||
|
||||
|
||||
def test_system_prompt_has_memory_commit_step():
|
||||
"""系统提示词应包含 memory_commit 写入步骤"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert "memory_commit (写入关键信息)" in prompt
|
||||
|
||||
|
||||
def test_system_prompt_has_five_steps():
|
||||
"""系统提示词应有5个执行步骤"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
# 检查步骤个数
|
||||
steps = [l for l in prompt.split('\n') if l.strip().startswith('步骤')]
|
||||
assert len(steps) == 5, f"期望5个步骤,实际{len(steps)}个"
|
||||
|
||||
|
||||
def test_system_prompt_has_triplet_rules():
|
||||
"""系统提示词应包含三元组规范"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert "三元组规范" in prompt or "短关键字" in prompt
|
||||
|
||||
|
||||
def test_system_prompt_has_memory_tools():
|
||||
"""系统提示词应列出记忆工具"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert "memory_recall" in prompt
|
||||
assert "memory_commit" in prompt
|
||||
assert "memory_purge" in prompt
|
||||
|
||||
|
||||
def test_system_prompt_has_persona_tools():
|
||||
"""系统提示词应列出人设工具"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert "persona_update" in prompt
|
||||
assert "persona_clear" in prompt
|
||||
|
||||
|
||||
def test_system_prompt_has_task_tools():
|
||||
"""系统提示词应列出任务工具"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert "task_create" in prompt
|
||||
assert "task_set_state" in prompt
|
||||
assert "task_delete" in prompt
|
||||
|
||||
|
||||
def test_system_prompt_no_python_function_notes():
|
||||
"""系统提示词不应包含Python函数实现注记"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert "Python函数" not in prompt
|
||||
|
||||
|
||||
def test_system_prompt_has_memory_principles():
|
||||
"""系统提示词应包含记忆原则"""
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert "明确内容必须写入" in prompt
|
||||
51
tests/test_core/test_web_api.py
Normal file
51
tests/test_core/test_web_api.py
Normal file
@ -0,0 +1,51 @@
|
||||
"""Tests for Web API endpoints"""
|
||||
|
||||
|
||||
def test_web_api_imports():
|
||||
"""Web API 模块应能正常导入"""
|
||||
from core import web_api
|
||||
assert web_api is not None
|
||||
|
||||
|
||||
def test_web_api_has_endpoints():
|
||||
"""Web API 应定义关键端点"""
|
||||
from core.web_api import app
|
||||
rules = [r.rule for r in app.url_map.iter_rules()]
|
||||
expected_endpoints = [
|
||||
'/api/settings',
|
||||
'/api/message',
|
||||
'/api/tools/execute',
|
||||
'/api/status',
|
||||
'/api/history',
|
||||
'/api/check-auth',
|
||||
]
|
||||
for endpoint in expected_endpoints:
|
||||
assert endpoint in rules, f"缺少端点: {endpoint}"
|
||||
|
||||
|
||||
def test_web_api_static_files():
|
||||
"""Web API 应正确配置静态文件路径"""
|
||||
from core.web_api import app
|
||||
assert app.static_folder is not None
|
||||
assert 'graph.html' in app.static_url_path or app.static_folder is not None
|
||||
|
||||
|
||||
def test_ui_index_exists():
|
||||
"""Web UI 的核心页面应存在"""
|
||||
import os
|
||||
from core.web_api import _ui_dir
|
||||
for page in ['graph.html', 'index.html']:
|
||||
path = os.path.join(_ui_dir, 'static', page)
|
||||
assert os.path.exists(path), f"缺少静态页面: {page}"
|
||||
for template in ['login.html', 'settings.html', 'setup.html']:
|
||||
path = os.path.join(_ui_dir, 'templates', template)
|
||||
assert os.path.exists(path), f"缺少模板: {template}"
|
||||
|
||||
|
||||
def test_system_prompt_integration():
|
||||
"""系统提示词应能被后端正确加载"""
|
||||
from core.prompts import PromptManager
|
||||
pm = PromptManager()
|
||||
prompt = pm.get_system_prompt()
|
||||
assert prompt is not None
|
||||
assert len(prompt) > 200
|
||||
Reference in New Issue
Block a user