mirror of
https://gitcode.com/JianFeeeee/TrulyMEM-TrueHumanMEM.git
synced 2026-10-04 00:14:26 +00:00
chore: 清理敏感信息,完善工程结构和文档
This commit is contained in:
50
tests/test_core/test_imports.py
Normal file
50
tests/test_core/test_imports.py
Normal file
@ -0,0 +1,50 @@
|
||||
"""核心逻辑导入测试"""
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_import_neo4j_graph():
|
||||
"""测试 Neo4jGraph 类导入"""
|
||||
from graph_memory_tui.core.imports import Neo4jGraph
|
||||
assert Neo4jGraph is not None
|
||||
assert hasattr(Neo4jGraph, 'recall')
|
||||
assert hasattr(Neo4jGraph, 'commit')
|
||||
assert hasattr(Neo4jGraph, 'purge')
|
||||
|
||||
|
||||
def test_import_graph_memory_client():
|
||||
"""测试 GraphMemoryClient 类导入"""
|
||||
from graph_memory_tui.core.imports import GraphMemoryClient
|
||||
assert GraphMemoryClient is not None
|
||||
assert hasattr(GraphMemoryClient, 'send_message')
|
||||
|
||||
|
||||
def test_import_tools():
|
||||
"""测试 TOOLS 定义导入"""
|
||||
from graph_memory_tui.core.imports import TOOLS
|
||||
assert TOOLS is not None
|
||||
assert isinstance(TOOLS, list)
|
||||
assert len(TOOLS) > 0
|
||||
assert any(t['function']['name'] == 'memory_recall' for t in TOOLS)
|
||||
|
||||
|
||||
def test_import_execute_tool():
|
||||
"""测试 execute_tool 函数导入"""
|
||||
from graph_memory_tui.core.imports import execute_tool
|
||||
assert execute_tool is not None
|
||||
assert callable(execute_tool)
|
||||
|
||||
|
||||
def test_import_config_vars():
|
||||
"""测试配置变量导入"""
|
||||
from graph_memory_tui.core.imports import (
|
||||
DEEPSEEK_API_KEY,
|
||||
DEEPSEEK_BASE_URL,
|
||||
MODEL_NAME,
|
||||
NEO4J_URI,
|
||||
NEO4J_USER,
|
||||
NEO4J_PASSWORD,
|
||||
)
|
||||
assert DEEPSEEK_BASE_URL is not None
|
||||
assert MODEL_NAME is not None
|
||||
assert NEO4J_URI is not None
|
||||
33
tests/test_handlers/test_focus_handler.py
Normal file
33
tests/test_handlers/test_focus_handler.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""焦点处理器测试"""
|
||||
|
||||
import pytest
|
||||
from graph_memory_tui.handlers.focus_handler import FocusHandler
|
||||
|
||||
|
||||
def test_focus_handler_creation():
|
||||
"""测试焦点处理器创建"""
|
||||
handler = FocusHandler()
|
||||
assert handler is not None
|
||||
assert handler._current_index == 0
|
||||
|
||||
|
||||
def test_focus_ring():
|
||||
"""测试焦点循环"""
|
||||
handler = FocusHandler()
|
||||
assert len(handler.FOCUS_RING) == 5
|
||||
assert "input-textarea" in handler.FOCUS_RING
|
||||
assert "cypher-textarea" in handler.FOCUS_RING
|
||||
|
||||
|
||||
def test_get_current_focus_name():
|
||||
"""测试获取当前焦点名称"""
|
||||
handler = FocusHandler()
|
||||
name = handler.get_current_focus_name()
|
||||
assert name == "Input"
|
||||
|
||||
|
||||
def test_focus_names_mapping():
|
||||
"""测试焦点名称映射"""
|
||||
handler = FocusHandler()
|
||||
assert handler.FOCUS_NAMES["input-textarea"] == "Input"
|
||||
assert handler.FOCUS_NAMES["cypher-textarea"] == "Query"
|
||||
83
tests/test_models/test_models.py
Normal file
83
tests/test_models/test_models.py
Normal file
@ -0,0 +1,83 @@
|
||||
"""数据模型测试"""
|
||||
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
from graph_memory_tui.models.message import Message, ToolCall, ToolResult
|
||||
from graph_memory_tui.models.config import AppConfig
|
||||
from graph_memory_tui.models.log_entry import LogEntry
|
||||
|
||||
|
||||
def test_message_creation(sample_message):
|
||||
"""测试消息创建"""
|
||||
assert sample_message.role == "user"
|
||||
assert sample_message.content == "测试消息"
|
||||
assert isinstance(sample_message.timestamp, datetime)
|
||||
|
||||
|
||||
def test_message_with_tool_calls():
|
||||
"""测试带工具调用的消息"""
|
||||
tool_call = ToolCall(
|
||||
id="test-id",
|
||||
name="memory_recall",
|
||||
arguments={"query_intent": "测试"}
|
||||
)
|
||||
|
||||
message = Message(
|
||||
role="assistant",
|
||||
content="测试回复",
|
||||
tool_calls=[tool_call]
|
||||
)
|
||||
|
||||
assert message.role == "assistant"
|
||||
assert message.tool_calls is not None
|
||||
assert len(message.tool_calls) == 1
|
||||
assert message.tool_calls[0].name == "memory_recall"
|
||||
|
||||
|
||||
def test_tool_call_creation(sample_tool_call):
|
||||
"""测试工具调用创建"""
|
||||
assert sample_tool_call.id == "test-call-id"
|
||||
assert sample_tool_call.name == "memory_recall"
|
||||
assert sample_tool_call.arguments == {"query_intent": "测试查询"}
|
||||
|
||||
|
||||
def test_tool_result_creation(sample_tool_result):
|
||||
"""测试工具结果创建"""
|
||||
assert sample_tool_result.tool_call_id == "test-call-id"
|
||||
assert sample_tool_result.success is True
|
||||
assert sample_tool_result.result == "测试结果"
|
||||
|
||||
|
||||
def test_config_creation(sample_config):
|
||||
"""测试配置创建"""
|
||||
assert sample_config.api_key == "test-api-key"
|
||||
assert sample_config.model == "test-model"
|
||||
assert sample_config.base_url == "https://test.api.com"
|
||||
|
||||
|
||||
def test_config_from_env():
|
||||
"""测试从环境变量加载配置"""
|
||||
import os
|
||||
os.environ["DEEPSEEK_API_KEY"] = "env-api-key"
|
||||
os.environ["MODEL_NAME"] = "env-model"
|
||||
|
||||
config = AppConfig.from_env()
|
||||
assert config.api_key == "env-api-key"
|
||||
assert config.model == "env-model"
|
||||
|
||||
|
||||
def test_log_entry_creation(sample_log_entry):
|
||||
"""测试日志条目创建"""
|
||||
assert sample_log_entry.tool_name == "memory_recall"
|
||||
assert sample_log_entry.duration == 0.5
|
||||
|
||||
|
||||
def test_log_entry_summary(sample_log_entry):
|
||||
"""测试日志条目摘要"""
|
||||
args_summary = sample_log_entry.args_summary
|
||||
result_summary = sample_log_entry.result_summary
|
||||
|
||||
assert isinstance(args_summary, str)
|
||||
assert isinstance(result_summary, str)
|
||||
assert len(args_summary) <= 53 # 50 + "..."
|
||||
assert len(result_summary) <= 103 # 100 + "..."
|
||||
Reference in New Issue
Block a user