[Feature] 增加更多的测试以保证兼容性,并要求后面的贡献者添加更改功能加上测试
Description / 描述
我建议咱们分阶段推进,不强求一步到位:
第一阶段:先加最关键的测试等等
- 平台适配器:Telegram 消息收发、代理配置测试
- Provider:OpenAI 格式兼容性、fallback 机制测试
- 目标:覆盖率从当前提升到 30-40%
第二阶段(持续进行):遇到 bug 先加测试再修复
- 每次修复兼容性 issue 时,写一个对应的回归测试
- 逐步积累测试用例
- 目标:避免同类问题再次出现
第三阶段(长期目标):建立测试规范
- 新功能必须有测试才能合入(重要喵)
- PR 模板增加测试检查项
- 目标:覆盖率稳步提升到 60%+"
Use Case / 使用场景
添加新功能或者修复bug的时候跑回归确保没有兼容性问题
Willing to Submit PR? / 是否愿意提交PR?
- [x] Yes, I am willing to submit a PR. / 是的,我愿意提交 PR。
Code of Conduct
- [x] I have read and agree to abide by the project's Code of Conduct. /
AstrBot 测试需求清单
本文档详细列出 AstrBot 项目所有需要添加测试的功能模块。
测试架构
目录结构
tests/
├── conftest.py # 共享 fixtures 和配置
├── (使用 pyproject.toml 中的 [tool.pytest.ini_options])
├── TEST_REQUIREMENTS.md # 测试需求清单(本文档)
├── __init__.py # 包初始化
│
├── unit/ # 单元测试
│ ├── __init__.py
│ ├── test_core_lifecycle.py
│ ├── test_conversation_mgr.py
│ └── ...
│
├── integration/ # 集成测试
│ ├── __init__.py
│ ├── conftest.py # 集成测试专用 fixtures
│ ├── test_pipeline_integration.py
│ └── ...
│
├── agent/ # Agent 相关测试
│ ├── test_context_manager.py
│ └── test_truncator.py
│
├── fixtures/ # 测试数据和 fixtures
│ ├── __init__.py
│ ├── configs/ # 测试配置文件
│ ├── messages/ # 测试消息数据
│ ├── plugins/ # 测试插件
│ └── knowledge_base/ # 测试知识库数据
│
└── test_*.py # 根级别测试文件
测试标记
| 标记 | 说明 | 示例 |
|---|---|---|
@pytest.mark.unit |
单元测试 | -m unit |
@pytest.mark.integration |
集成测试 | -m integration |
@pytest.mark.slow |
慢速测试(>1秒) | -m "not slow" |
@pytest.mark.platform |
平台适配器测试 | -m platform |
@pytest.mark.provider |
LLM Provider 测试 | -m provider |
@pytest.mark.db |
数据库相关测试 | -m db |
@pytest.mark.asyncio |
异步测试 | 自动添加 |
说明:
tests/conftest.py会根据目录自动补充标记:tests/integration/**自动标记为integration,其余测试默认标记为unit。tests/fixtures/**是测试数据目录,已在 pytest 配置中排除,不参与测试收集。
1. 核心模块 (astrbot/core)
1.1 core_lifecycle.py - 核心生命周期 [P0]
- [x]
AstrBotCoreLifecycle.__init__()初始化 - [x]
AstrBotCoreLifecycle.start()启动流程 - [x]
AstrBotCoreLifecycle.stop()停止流程 - [x] 组件初始化顺序正确性
- [x] 异常处理和恢复机制
1.2 astr_main_agent.py - 主 Agent [P0]
- [x]
build_main_agent()构建流程 - [x]
_select_provider()Provider 选择逻辑 - [x]
_get_session_conv()会话获取/创建 - [x]
_apply_kb()知识库应用 - [x]
_apply_file_extract()文件提取 - [x]
_ensure_persona_and_skills()人设和技能应用 - [x]
_decorate_llm_request()LLM 请求装饰 - [x]
_modalities_fix()模态修复 - [x]
_sanitize_context_by_modalities()按模态清理上下文 - [x]
_plugin_tool_fix()插件工具过滤 - [x]
_handle_webchat()Webchat 标题生成 - [x]
_apply_llm_safety_mode()LLM 安全模式 - [x]
_apply_sandbox_tools()沙箱工具应用 - [x]
MainAgentBuildConfig配置验证
1.3 conversation_mgr.py - 会话管理 [P0]
- [x]
ConversationManager.new_conversation()新建会话 - [x]
ConversationManager.get_conversation()获取会话 - [x]
ConversationManager.get_curr_conversation_id()获取当前会话 ID - [x]
ConversationManager.delete_conversation()删除会话 - [x]
ConversationManager.update_conversation()更新会话 - [x] 会话历史管理
- [x] 并发访问处理
1.4 persona_mgr.py - 人设管理 [P1]
- [x]
PersonaManager.load_personas()加载人设 - [x]
PersonaManager.get_persona()获取人设 - [x] 人设验证
- [x] 人设热重载
1.5 event_bus.py - 事件总线 [P1]
- [x] 事件发布
- [x] 事件订阅
- [x] 事件过滤
- [x] 异步事件处理
1.7 cron/ - 定时任务 [P2]
- [x]
CronManager.add_job()添加任务 - [x]
CronManager.remove_job()删除任务 - [x]
CronManager.list_jobs()列出任务 - [x] 任务执行
- [x] 任务持久化
1.8 config/ - 配置管理 [P0]
- [x]
AstrBotConfig配置加载 - [x] 配置验证
- [x] 配置热重载
- [x] i18n 工具函数
1.9 computer/ - 计算机使用 [P2]
- [x]
ComputerClient初始化 - [x]
Booter实现 (local, shipyard, boxlite) - [x] 文件系统操作层
- [x] Python 执行层
- [x] Shell 执行层
- [x] 安全限制
2. 平台适配器 (astrbot/core/platform)
阶段二回归结果(本地):342 passed, 0 skipped, 0 failed
执行命令:
uv run pytest tests/unit/test_import_cycles.py tests/unit/test_platform_base.py tests/unit/test_astr_message_event.py tests/unit/test_astrbot_message.py tests/unit/test_platform_metadata.py tests/unit/test_aiocqhttp_adapter.py tests/unit/test_telegram_adapter.py tests/unit/test_discord_adapter.py tests/unit/test_slack_adapter.py tests/unit/test_wecom_adapter.py tests/unit/test_lark_adapter.py tests/unit/test_dingtalk_adapter.py tests/unit/test_webchat_adapter.py tests/unit/test_platform_manager.py tests/unit/test_other_adapters.py tests/unit/test_skipped_items_runtime.py tests/unit/test_api_compat_smoke.py -q
API 兼容冒烟测试:5 passed(tests/unit/test_api_compat_smoke.py)
跳过项补测:9 passed(tests/unit/test_skipped_items_runtime.py,覆盖 PlatformManager/slack/wecom/lark/dingtalk/qqofficial_webhook/weixin_official_account/satori/line/misskey/wecom_ai_bot 关键链路)
2.1 Platform 基类 [P0]
- [x]
Platform抽象类 - [x]
AstrMessageEvent事件类 - [x]
AstrBotMessage消息类 - [x]
MessageMember成员类 - [x]
PlatformMetadata元数据
2.2 aiocqhttp (QQ) [P1]
- [x]
aiocqhttpPlatform初始化 - [x] 消息接收和解析
- [x] 消息发送
- [x] 群消息处理
- [x] 私聊消息处理
- [x] OneBot API 调用
2.3 telegram [P1]
- [x]
TelegramPlatform初始化 - [x] Webhook 设置
- [x] 消息解析
- [x] 消息发送
- [x] 内联查询
- [x] 回调查询
2.4 discord [P1]
- [x]
DiscordPlatform初始化 - [x] 消息监听
- [x] 消息发送
- [x] Slash 命令
- [x] 组件交互
2.5 slack [P1]
- [x]
SlackPlatform初始化(补测:test_skipped_items_runtime.py) - [x] Socket Mode(补测:配置与实例化链路)
- [x] 消息解析(补测:
test_skipped_items_runtime.py) - [x] 消息发送(补测:
test_skipped_items_runtime.py) - [x] 事件处理(补测:
test_skipped_items_runtime.py)
2.6 wecom (企业微信) [P1]
- [x]
WecomPlatform初始化(test_wecom_adapter.py) - [x] 回调验证(
test_wecom_adapter.py::test_wecom_server_verify_smoke) - [x] 消息加解密(补测:
test_skipped_items_runtime.py) - [x] 消息发送(补测:文本消息转换入队关键链路)
2.7 wecom_ai_bot [P1]
- [x] AI Bot 特定功能(补测:
test_skipped_items_runtime.py) - [x] 消息格式转换(补测:
test_skipped_items_runtime.py)
2.8 feishu (飞书) [P1]
- [x]
LarkPlatform初始化(补测:test_skipped_items_runtime.py) - [x] 事件订阅(补测:事件去重关键逻辑)
- [x] 消息发送(补测:
test_skipped_items_runtime.py) - [x] 卡片消息(补测:
test_skipped_items_runtime.py)
2.9 dingtalk (钉钉) [P1]
- [x]
DingTalkPlatform初始化(补测:test_skipped_items_runtime.py) - [x] 回调处理(补测:
test_skipped_items_runtime.py) - [x] 消息发送(补测:
send_with_sesison兼容别名链路)
2.10 qqofficial [P2]
- [x] QQ 官方 API 集成(补测:
test_skipped_items_runtime.py) - [x] 消息解析和发送(补测:
test_skipped_items_runtime.py)
2.11 qqofficial_webhook [P2]
- [x] Webhook 模式(补测:
test_skipped_items_runtime.py) - [x] 消息处理(补测:
test_skipped_items_runtime.py)
2.12 weixin_official_account (微信公众号) [P2]
- [x] 公众号消息处理(补测:
test_skipped_items_runtime.py) - [x] 被动回复(补测:
test_skipped_items_runtime.py) - [x] 模板消息(补测:
test_skipped_items_runtime.py)
2.13 webchat [P1]
- [x] WebSocket 连接
- [x] 消息传输
- [x] 会话管理
2.14 satori [P2]
- [x] Satori 协议适配(补测:
test_skipped_items_runtime.py) - [x] 消息格式转换(补测:
test_skipped_items_runtime.py)
2.15 line [P2]
- [x] LINE 平台适配(补测:
test_skipped_items_runtime.py) - [x] 消息处理(补测:
test_skipped_items_runtime.py)
2.16 misskey [P2]
- [x] Misskey 平台适配(补测:
test_skipped_items_runtime.py) - [x] 消息处理(补测:
test_skipped_items_runtime.py)
3. LLM Provider (astrbot/core/provider)
3.1 Provider 基类 [P0]
- [ ]
Provider抽象类 - [ ]
ProviderRequest请求类 - [ ]
LLMResponse响应类 - [ ]
TokenUsageToken 统计 - [ ]
ProviderMetaData元数据
3.2 ProviderManager [P0]
- [ ]
ProviderManager初始化 - [ ] Provider 注册
- [ ] Provider 选择
- [ ] Fallback 机制
- [ ] API Key 轮换
3.3 OpenAI Source [P0]
- [ ]
ProviderOpenAIOfficial基础功能 - [ ] 文本对话
- [ ] 流式响应
- [x] 图片处理
- [ ] 工具调用
- [x] 错误处理
- [ ] API Key 轮换
- [ ] 模态检查
- [x] 内容审核检测与处理
- [x] 长响应文本截断
3.4 Anthropic Source [P1]
- [ ]
ProviderAnthropic基础功能 - [ ] Claude API 调用
- [ ] 流式响应
- [ ] 工具调用
- [ ] 图片处理
3.5 Gemini Source [P1]
- [ ]
ProviderGemini基础功能 - [ ] Google AI API 调用
- [ ] 流式响应
- [ ] 工具调用
- [ ] 安全设置
3.6 Groq Source [P1]
- [ ]
ProviderGroq基础功能 - [ ] 快速推理
3.7 xAI Source [P1]
- [ ]
ProviderXAI基础功能 - [ ] Grok API
3.8 Zhipu Source [P1]
- [ ]
ProviderZhipu基础功能 - [ ] 智谱 API
3.9 DashScope Source [P1]
- [ ] 阿里云灵积 API
3.10 oai_aihubmix_source [P2]
- [ ] AIHubMix 适配
3.11 gsv_selfhosted_source [P2]
- [ ] 自托管模型适配
3.12 TTS Providers [P2]
- [ ]
openai_tts_api_sourceOpenAI TTS - [ ]
azure_tts_sourceAzure TTS - [ ]
edge_tts_sourceEdge TTS - [ ]
dashscope_tts阿里云 TTS - [ ]
fishaudio_tts_api_sourceFishAudio TTS - [ ]
gemini_tts_sourceGemini TTS - [ ]
genie_ttsGenie TTS - [ ]
gsvi_tts_sourceGSVI TTS - [ ]
minimax_tts_api_sourceMinimax TTS - [ ]
volcengine_tts火山引擎 TTS
3.13 STT Providers [P2]
- [ ]
whisper_api_sourceWhisper API - [ ]
whisper_selfhosted_source自托管 Whisper - [ ]
sensevoice_selfhosted_source自托管 SenseVoice
3.14 Embedding Providers [P1]
- [ ]
openai_embedding_sourceOpenAI Embedding - [ ]
gemini_embedding_sourceGemini Embedding
3.15 Rerank Providers [P2]
- [ ]
bailian_rerank_source百炼 Rerank - [ ]
vllm_rerank_sourcevLLM Rerank - [ ]
xinference_rerank_sourceXinference Rerank
4. Agent 系统 (astrbot/core/agent)
4.1 Agent 基础 [P0]
- [ ]
Agent基类 - [ ]
AgentRunner运行器基类 - [ ]
RunContext运行上下文
4.2 ToolLoopAgentRunner [P0]
- [x]
run()执行流程 - [x]
reset()重置 - [x] 工具调用循环
- [x] 流式响应处理
- [x] 错误处理
- [x] Fallback Provider 支持
- [x] 最大步数限制
4.3 Context Manager [P0]
- [x]
ContextManager.process()上下文处理 - [x] Token 计数
- [x] 上下文截断
- [x] LLM 压缩
- [x] Enforce Max Turns
- [x] 多模态内容处理
- [x] 工具调用消息处理
4.4 Truncator [P1]
- [x]
truncate_by_turns()按轮次截断 - [x]
truncate_by_halving()半截断 - [x]
truncate_by_dropping_oldest_turns()丢弃最旧轮次 - [x]
fix_messages()消息修复 - [x] 系统消息保留
- [x] 确保用户消息优先
4.5 Compressor [P1]
- [x]
TruncateByTurnsCompressor截断压缩器 - [x]
LLMSummaryCompressorLLM 压缩器 - [x]
split_history()历史分割
4.6 Token Counter [P1]
- [x]
count_tokens()Token 计数 - [x] 多语言支持
4.7 Tool [P0]
- [ ]
FunctionTool函数工具 - [ ]
ToolSet工具集 - [ ]
HandoffTool移交工具 - [ ]
MCPToolMCP 工具
4.8 Tool Executor [P0]
- [ ]
FunctionToolExecutor工具执行器 - [ ] 并发执行
- [ ] 超时处理
4.9 Agent Runners - 第三方 [P2]
- [ ]
coze_agent_runnerCoze Agent - [ ]
coze_api_clientCoze API - [ ]
dashscope_agent_runnerDashScope Agent - [ ]
dify_agent_runnerDify Agent - [ ]
dify_api_clientDify API
4.10 Agent Message [P1]
- [ ]
Message消息类 - [ ]
TextPart文本部分 - [ ]
ImagePart图片部分 - [ ]
ToolCall工具调用
4.11 Agent Hooks [P1]
- [ ]
BaseAgentRunHooks钩子基类 - [ ]
MAIN_AGENT_HOOKS主 Agent 钩子
4.12 Agent Response [P1]
- [ ]
AgentResponse响应类 - [ ] 响应类型处理
4.13 Subagent Orchestrator [P2]
- [ ]
SubagentOrchestrator子代理编排 - [ ] 任务分发
- [ ] 结果聚合
6. 插件系统 (astrbot/core/star)
6.1 StarManager [P0]
- [x]
PluginManager插件管理器 - [x] 插件加载
- [x] 插件卸载
- [x] 插件重载
- [ ] 依赖解析
- [x] 插件安装/更新
6.2 Star 基类 [P0]
- [ ]
Star插件类 - [ ] 生命周期方法
- [ ] 元数据
6.3 Star Handler [P0]
- [ ]
star_handlers_registry处理器注册表 - [ ] 处理器执行
- [ ] 异常处理
6.4 Register [P0]
- [ ]
register_star插件注册 - [ ]
register_command命令注册 - [ ]
register_llm_toolLLM 工具注册 - [ ]
register_regex正则注册 - [ ]
register_on_llm_request/responseLLM 钩子
6.5 Filters [P1]
- [ ]
command命令过滤器 - [ ]
command_group命令组过滤器 - [ ]
regex正则过滤器 - [ ]
permission权限过滤器 - [ ]
event_message_type消息类型过滤器 - [ ]
platform_adapter_type平台类型过滤器 - [ ]
custom_filter自定义过滤器
6.6 Context [P0]
- [ ]
Context插件上下文 - [ ] 服务访问
6.7 Command Management [P1]
- [ ] 命令注册
- [ ] 命令解析
- [ ] 命令路由
6.8 Config [P1]
- [ ] 插件配置
- [ ] 配置验证
6.9 Session Managers [P1]
- [ ]
session_llm_manager会话 LLM 管理 - [ ]
session_plugin_manager会话插件管理
6.10 Star Tools [P1]
- [ ]
star_tools插件工具
6.11 Updator [P1]
- [ ] 插件更新器
7. 知识库系统 (astrbot/core/knowledge_base)
7.1 KB Manager [P0]
- [ ]
KnowledgeBaseManager知识库管理器 - [ ] 知识库创建
- [ ] 知识库删除
- [ ] 知识库查询
7.2 KB Database [P1]
- [ ]
kb_db_sqliteSQLite 存储 - [ ] 向量存储
- [ ] 元数据管理
7.3 Chunking [P1]
- [ ]
base分块基类 - [ ]
fixed_size固定大小分块 - [ ]
recursive递归分块
7.4 Parsers [P1]
- [ ]
base解析器基类 - [ ]
pdf_parserPDF 解析 - [ ]
text_parser文本解析 - [ ]
markitdown_parserMarkdown 解析 - [ ]
url_parserURL 解析 - [x] 知识库导入功能
7.5 Retrieval [P0]
- [ ]
manager检索管理器 - [ ]
sparse_retriever稀疏检索 - [ ]
rank_fusion排序融合
7.6 Models [P1]
- [ ] 数据模型
- [ ] 向量模型
7.7 Prompts [P2]
- [ ] 提示词模板
8. 数据库层 (astrbot/core/db)
8.1 SQLite [P0]
- [x]
SQLiteDatabase数据库连接 - [ ] 查询执行
- [ ] 事务处理
- [ ] 连接池
8.2 PO (Persistent Objects) [P1]
- [ ]
ConversationV2会话模型 - [ ]
PlatformSession平台会话 - [ ]
Personality人设模型 - [ ] 其他数据模型
8.3 Migration [P1]
- [ ]
helper迁移助手 - [ ]
migra_3_to_4版本迁移 - [ ]
migra_45_to_46版本迁移 - [ ]
migra_token_usageToken 使用迁移 - [ ]
migra_webchat_sessionWebchat 会话迁移 - [ ]
shared_preferences_v3偏好设置迁移
8.4 VecDB [P1]
- [ ]
base向量数据库基类 - [ ]
faiss_implFAISS 实现- [ ]
vec_db向量数据库 - [ ]
document_storage文档存储 - [ ]
embedding_storage嵌入存储
- [ ]
9. API 层 (astrbot/api)
9.1 Exports [P0]
- [ ]
all.py导出正确性 - [ ] 导入路径验证
9.2 Message Components [P1]
- [ ]
message_components.py消息组件 - [ ] 组件类型
- [ ] 序列化/反序列化
9.3 Event [P1]
- [ ]
event/__init__事件定义 - [ ]
event/filter事件过滤器
9.4 Platform [P1]
- [ ]
platform/__init__平台接口
9.5 Provider [P1]
- [ ]
provider/__init__Provider 接口
9.6 Star [P1]
- [ ]
star/__init__插件接口
9.7 Util [P2]
- [ ]
util/__init__工具函数
10. Dashboard 后端 (astrbot/dashboard)
10.1 Server [P0]
- [ ]
server.py服务器初始化 - [x] 路由注册
- [ ] 中间件
- [ ] 静态文件服务
10.2 Routes [P0]
- [x]
auth认证路由 - [ ]
backup备份路由 - [ ]
chat聊天路由 - [ ]
chatui_projectChatUI 项目路由 - [x]
command命令路由 - [ ]
config配置路由 - [ ]
conversation会话路由 - [ ]
cron定时任务路由 - [ ]
file文件路由 - [ ]
knowledge_base知识库路由 - [ ]
live_chat实时聊天路由 - [ ]
log日志路由 - [ ]
persona人设路由 - [x]
platform平台路由 - [x]
plugin插件路由 - [ ]
session_management会话管理路由 - [ ]
skills技能路由 - [x]
stat统计路由 - [ ]
static_file静态文件路由 - [ ]
subagent子代理路由 - [ ]
t2i文字转图片路由 - [ ]
tools工具路由 - [x]
update更新路由 - [ ]
util工具路由
10.3 Utils [P1]
- [ ]
utils.pyDashboard 工具函数
11. CLI 模块 (astrbot/cli)
11.1 Main [P1]
- [ ]
__main__.pyCLI 入口 - [ ] 命令解析
11.2 Commands [P1]
- [ ]
cmd_conf配置命令 - [ ]
cmd_init初始化命令 - [ ]
cmd_plug插件命令 - [ ]
cmd_run运行命令
11.3 Utils [P2]
- [ ]
basic基础工具 - [ ]
plugin插件工具 - [ ]
version_comparator版本比较
12. 内置插件 (astrbot/builtin_stars)
12.1 builtin_commands [P1]
- [ ]
main.py插件入口 - [ ]
admin管理命令 - [ ]
alter_cmd备用命令 - [ ]
conversation会话命令 - [ ]
help帮助命令 - [ ]
llmLLM 命令 - [ ]
persona人设命令 - [ ]
plugin插件命令 - [ ]
providerProvider 命令 - [ ]
setunset设置命令 - [ ]
sidSID 命令 - [ ]
t2i文字转图片命令 - [ ]
ttsTTS 命令 - [ ]
utils/rst_scene场景重置
12.2 session_controller [P1]
- [ ]
main.py会话控制器 - [ ] 会话锁定
- [ ] 会话解锁
12.3 web_searcher [P2]
- [ ]
main.py网页搜索 - [ ]
engines/bingBing 搜索 - [ ]
engines/sogo搜狗搜索
12.4 astrbot [P1]
- [ ]
main.pyAstrBot 内置功能 - [ ]
long_term_memory长期记忆
13. 工具类 (astrbot/core/utils)
13.1 Path Utils [P1]
- [ ]
astrbot_path.py路径工具- [ ]
get_astrbot_root() - [ ]
get_astrbot_data_path() - [ ]
get_astrbot_config_path() - [ ]
get_astrbot_plugin_path() - [ ]
get_astrbot_temp_path()
- [ ]
- [ ]
path_util.py路径工具
13.2 IO Utils [P1]
- [ ]
io.pyIO 工具- [ ] 文件下载
- [ ] 图片下载
- [ ]
file_extract.py文件提取
13.3 Network Utils [P1]
- [ ]
network_utils.py网络工具 - [ ]
http_ssl.pySSL 工具 - [ ]
webhook_utils.pyWebhook 工具
13.4 String Utils [P2]
- [ ]
string_utils.py字符串工具 - [ ]
command_parser.py命令解析
13.5 T2I Utils [P2]
- [ ]
t2i/local_strategy.py本地策略 - [ ]
t2i/network_strategy.py网络策略 - [ ]
t2i/renderer.py渲染器 - [ ]
t2i/template_manager.py模板管理
13.6 Quoted Message Utils [P1]
- [x]
quoted_message_parser.py引用消息解析 - [x]
quoted_message/chain_parser.py链解析 - [x]
quoted_message/extractor.py提取器 - [x]
quoted_message/image_refs.py图片引用 - [x]
quoted_message/image_resolver.py图片解析 - [x]
quoted_message/onebot_client.pyOneBot 客户端 - [ ]
quoted_message/settings.py设置
13.7 Other Utils [P2]
- [ ]
active_event_registry.py活动事件注册 - [ ]
history_saver.py历史保存 - [ ]
log_pipe.py日志管道 - [ ]
media_utils.py媒体工具 - [ ]
metrics.py指标 - [ ]
migra_helper.py迁移助手 - [ ]
pip_installer.pyPip 安装器 - [ ]
plugin_kv_store.py插件 KV 存储 - [ ]
runtime_env.py运行环境 - [ ]
session_lock.py会话锁 - [ ]
session_waiter.py会话等待 - [ ]
shared_preferences.py共享偏好 - [x]
temp_dir_cleaner.py临时目录清理 - [ ]
tencent_record_helper.py腾讯记录助手 - [ ]
trace.py追踪 - [x]
version_comparator.py版本比较 - [ ]
llm_metadata.pyLLM 元数据
14. 其他模块
14.1 skills/ [P2]
- [ ]
skill_manager.py技能管理器 - [ ] 技能加载
- [ ] 技能执行
14.2 tools/ [P1]
- [ ]
cron_tools.pyCron 工具
14.3 message/ [P0]
- [ ]
components.py消息组件- [ ]
Plain纯文本 - [ ]
Image图片 - [ ]
At@ 提及 - [ ]
Reply回复 - [ ]
File文件 - [ ] 其他组件
- [ ]
- [ ]
message_event_result.py消息事件结果- [ ]
MessageEventResult - [ ]
MessageChain - [ ]
CommandResult
- [ ]
14.4 Root Files [P1]
- [x]
main.py主入口- [x] 环境检查
- [x] Dashboard 下载
- [ ] 服务启动
- [ ]
runtime_bootstrap.py运行时引导
测试编写建议
测试命名规范
# 文件命名: test_<module_name>.py
# 类命名: Test<FeatureName>
# 方法命名: test_<scenario>_<expected_result>
测试结构
import pytest
class TestFeatureName:
"""功能描述"""
@pytest.fixture
def setup(self):
"""测试前置"""
pass
def test_normal_case(self, setup):
"""测试正常情况"""
pass
def test_edge_case(self, setup):
"""测试边界情况"""
pass
def test_error_handling(self, setup):
"""测试错误处理"""
pass
Mock 使用建议
- 对外部 API 调用使用
unittest.mock - 对异步函数使用
AsyncMock - 对文件系统操作使用
tmp_pathfixture
异步测试
@pytest.mark.asyncio
async def test_async_function():
result = await some_async_function()
assert result == expected
注意事项
- 测试隔离: 每个测试应该独立运行,不依赖其他测试
- 数据隔离: 使用临时目录和数据库,不要污染真实数据
- 异步测试: 记得使用
@pytest.mark.asyncio装饰器 - Mock 外部依赖: 不要依赖真实的 API 调用
- 测试覆盖: 关注边界条件和错误处理
- 测试速度: 保持测试快速执行,避免长时间等待