AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Feature] 增加更多的测试以保证兼容性,并要求后面的贡献者添加更改功能加上测试

Open whatevertogo opened this issue 9 months ago • 1 comments

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

whatevertogo avatar Feb 20 '26 14:02 whatevertogo

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 响应类
  • [ ] TokenUsage Token 统计
  • [ ] 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_source OpenAI TTS
  • [ ] azure_tts_source Azure TTS
  • [ ] edge_tts_source Edge TTS
  • [ ] dashscope_tts 阿里云 TTS
  • [ ] fishaudio_tts_api_source FishAudio TTS
  • [ ] gemini_tts_source Gemini TTS
  • [ ] genie_tts Genie TTS
  • [ ] gsvi_tts_source GSVI TTS
  • [ ] minimax_tts_api_source Minimax TTS
  • [ ] volcengine_tts 火山引擎 TTS

3.13 STT Providers [P2]

  • [ ] whisper_api_source Whisper API
  • [ ] whisper_selfhosted_source 自托管 Whisper
  • [ ] sensevoice_selfhosted_source 自托管 SenseVoice

3.14 Embedding Providers [P1]

  • [ ] openai_embedding_source OpenAI Embedding
  • [ ] gemini_embedding_source Gemini Embedding

3.15 Rerank Providers [P2]

  • [ ] bailian_rerank_source 百炼 Rerank
  • [ ] vllm_rerank_source vLLM Rerank
  • [ ] xinference_rerank_source Xinference 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] LLMSummaryCompressor LLM 压缩器
  • [x] split_history() 历史分割

4.6 Token Counter [P1]

  • [x] count_tokens() Token 计数
  • [x] 多语言支持

4.7 Tool [P0]

  • [ ] FunctionTool 函数工具
  • [ ] ToolSet 工具集
  • [ ] HandoffTool 移交工具
  • [ ] MCPTool MCP 工具

4.8 Tool Executor [P0]

  • [ ] FunctionToolExecutor 工具执行器
  • [ ] 并发执行
  • [ ] 超时处理

4.9 Agent Runners - 第三方 [P2]

  • [ ] coze_agent_runner Coze Agent
  • [ ] coze_api_client Coze API
  • [ ] dashscope_agent_runner DashScope Agent
  • [ ] dify_agent_runner Dify Agent
  • [ ] dify_api_client Dify 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_tool LLM 工具注册
  • [ ] register_regex 正则注册
  • [ ] register_on_llm_request/response LLM 钩子

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_sqlite SQLite 存储
  • [ ] 向量存储
  • [ ] 元数据管理

7.3 Chunking [P1]

  • [ ] base 分块基类
  • [ ] fixed_size 固定大小分块
  • [ ] recursive 递归分块

7.4 Parsers [P1]

  • [ ] base 解析器基类
  • [ ] pdf_parser PDF 解析
  • [ ] text_parser 文本解析
  • [ ] markitdown_parser Markdown 解析
  • [ ] url_parser URL 解析
  • [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_usage Token 使用迁移
  • [ ]migra_webchat_session Webchat 会话迁移
  • [ ] shared_preferences_v3 偏好设置迁移

8.4 VecDB [P1]

  • [ ] base 向量数据库基类
  • [ ] faiss_impl FAISS 实现
    • [ ] 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_project ChatUI 项目路由
  • [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.py Dashboard 工具函数

11. CLI 模块 (astrbot/cli)

11.1 Main [P1]

  • [ ] __main__.py CLI 入口
  • [ ] 命令解析

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 帮助命令
  • [ ] llm LLM 命令
  • [ ] persona 人设命令
  • [ ] plugin 插件命令
  • [ ] provider Provider 命令
  • [ ] setunset 设置命令
  • [ ] sid SID 命令
  • [ ] t2i 文字转图片命令
  • [ ] tts TTS 命令
  • [ ] utils/rst_scene 场景重置

12.2 session_controller [P1]

  • [ ] main.py 会话控制器
  • [ ] 会话锁定
  • [ ] 会话解锁

12.3 web_searcher [P2]

  • [ ] main.py 网页搜索
  • [ ] engines/bing Bing 搜索
  • [ ] engines/sogo 搜狗搜索

12.4 astrbot [P1]

  • [ ] main.py AstrBot 内置功能
  • [ ] 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.py IO 工具
    • [ ] 文件下载
    • [ ] 图片下载
  • [ ] file_extract.py 文件提取

13.3 Network Utils [P1]

  • [ ] network_utils.py 网络工具
  • [ ] http_ssl.py SSL 工具
  • [ ] webhook_utils.py Webhook 工具

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.py OneBot 客户端
  • [ ] 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.py Pip 安装器
  • [ ] 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.py LLM 元数据

14. 其他模块

14.1 skills/ [P2]

  • [ ] skill_manager.py 技能管理器
  • [ ] 技能加载
  • [ ] 技能执行

14.2 tools/ [P1]

  • [ ] cron_tools.py Cron 工具

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_path fixture

异步测试

@pytest.mark.asyncio
async def test_async_function():
    result = await some_async_function()
    assert result == expected

注意事项

  1. 测试隔离: 每个测试应该独立运行,不依赖其他测试
  2. 数据隔离: 使用临时目录和数据库,不要污染真实数据
  3. 异步测试: 记得使用 @pytest.mark.asyncio 装饰器
  4. Mock 外部依赖: 不要依赖真实的 API 调用
  5. 测试覆盖: 关注边界条件和错误处理
  6. 测试速度: 保持测试快速执行,避免长时间等待

whatevertogo avatar Feb 21 '26 08:02 whatevertogo