feat: enhance Milkdown editor and file system functionality
- Normalize line endings in Markdown export for DOCX files. - Improve selection serialization to Markdown with better handling of empty documents. - Add a new `updateFile` function to the file system for updating file properties. - Introduce video transcoding capabilities using FFmpeg, supporting various video formats. - Update AGENTS.md for clearer plugin structure and responsibilities. - Add scoped styles for TreeNodeItem component to improve UI consistency. - Implement cross-origin isolation headers in Vite configuration for enhanced security. - Remove obsolete test_cross.py file.
This commit is contained in:
+52
-35
@@ -1,45 +1,62 @@
|
||||
OVERVIEW: pytest 测试套件,覆盖率要求 90%
|
||||
STRUCTURE:
|
||||
- test_*.py - 各模块测试
|
||||
- run_tests.py - 测试执行脚本(unit/integration/all)
|
||||
- simulate_macos.py - macOS 环境模拟
|
||||
- TESTING_GUIDE.md - 测试指南文档
|
||||
# Backend Tests 测试指引
|
||||
|
||||
WHERE TO LOOK
|
||||
表格
|
||||
本文件适用于 backend/tests/ 下的测试和测试脚本。
|
||||
|
||||
| Area | Path |
|
||||
|---|---|
|
||||
| 单元测试 | backend/tests/ |
|
||||
| 集成测试 | backend/tests/ |
|
||||
| 测试执行脚本 | backend/tests/run_tests.py |
|
||||
| macOS 模拟 | backend/tests/simulate_macos.py |
|
||||
| 测试指南 | backend/tests/TESTING_GUIDE.md |
|
||||
## 测试入口
|
||||
|
||||
运行命令:
|
||||
- pytest - 运行所有测试
|
||||
- python backend/tests/run_tests.py unit - 单元测试
|
||||
- python backend/tests/run_tests.py integration - 集成测试
|
||||
- pytest.ini 指定默认测试目录为 backend/tests,并设置后端覆盖率门槛为 90%。
|
||||
- run_tests.py 提供 unit、integration、simulate、all 几种快捷入口。
|
||||
- 默认优先使用 pytest 跑窄测试;只有在需要脚本封装参数时再用 run_tests.py。
|
||||
|
||||
测试命名约定:test_*.py、Test* 类、test_* 函数
|
||||
## 测试分布
|
||||
|
||||
ANTI-PATTERNS:删除测试以通过覆盖率
|
||||
- test_main_endpoints.py:主 API 路由行为
|
||||
- test_main_cancel.py:补全取消和任务生命周期
|
||||
- test_prompt.py、test_prompt_extended.py:Prompt 上下文与规则
|
||||
- test_llm.py、test_llm_extended.py:LLM 包装层
|
||||
- test_geoip.py:GeoIP 逻辑
|
||||
- test_tts_asr_*.py:TTS 相关与历史 TTS/ASR 面
|
||||
- simulate_macos.py:历史模拟脚本
|
||||
- quick_verify.py、verify_cross.py、play_audio.py:人工验证或辅助脚本
|
||||
|
||||
验证
|
||||
- 保证测试覆盖率≥90% 时,报告合格
|
||||
- 使用 CI 运行 pytest,确保通过率
|
||||
## 常用命令
|
||||
|
||||
注意事项
|
||||
- 不要重复父目录内容
|
||||
- 不要超过 60 行
|
||||
- pytest
|
||||
- pytest backend/tests/test_main_endpoints.py -v
|
||||
- pytest backend/tests/test_main_cancel.py -v
|
||||
- pytest backend/tests/test_prompt.py -v
|
||||
- pytest backend/tests/test_llm.py -v
|
||||
- python backend/tests/run_tests.py unit
|
||||
- python backend/tests/run_tests.py integration --url http://localhost:8001 --key your-secret-key-here
|
||||
|
||||
测试应尽量独立,不要依赖全局状态
|
||||
- 运行单元测试时应使用 unit 标签
|
||||
- 运行集成测试时应使用 integration 标签
|
||||
## 测试原则
|
||||
|
||||
区分环境
|
||||
- unit 测试应尽量快速、稳定
|
||||
- integration 测试应覆盖接口和数据库交互
|
||||
- 优先跑与改动直接对应的窄测试,不要动不动全量跑。
|
||||
- 单元测试尽量 mock 掉外部依赖,不要直连真实 Ollama。
|
||||
- 涉及 main.py 时,优先用 monkeypatch 或 fake 对象替代:
|
||||
- call_ollama
|
||||
- call_vlm_ocr
|
||||
- MarkItDown
|
||||
- GeoIP 查询
|
||||
- TTS 模型加载
|
||||
- 测试要保持确定性,不依赖全局状态、环境顺序或人工输入。
|
||||
|
||||
维护
|
||||
- 如扩展新模块,优先增加 test_*.py 文件并在其中添加对应的测试类和方法
|
||||
## 容易误判的点
|
||||
|
||||
- 覆盖率门槛是针对多个 backend 模块一起算的,改核心文件时,即使单测通过也可能因为覆盖率不够失败。
|
||||
- htmlcov、.pytest_cache、api_performance_report.md 属于生成产物,不是需要维护的源码。
|
||||
- 这一目录里有一批 TTS/ASR 测试和说明明显继承自旧实现;当它们与当前 backend/tts_asr.py 冲突时,不要默认代码错了,先确认目标产品面。
|
||||
- integration 脚本通常假设本地服务在 http://localhost:8001,且默认 API Key 还是占位值。
|
||||
|
||||
## 改动定位建议
|
||||
|
||||
- 路由返回值不对:先看 test_main_endpoints.py 和 test_main_cancel.py
|
||||
- Prompt 规则不对:先看 test_prompt.py 和 test_prompt_extended.py
|
||||
- Ollama 调用包装不对:先看 test_llm.py 和 test_llm_extended.py
|
||||
- TTS 面变化:先确认当前 backend/tts_asr.py 是不是仍然以旧文档描述为目标,再决定修测试还是修实现
|
||||
|
||||
## 维护原则
|
||||
|
||||
- 新增后端行为时,优先给对应模块补测试,不要只依赖全量回归。
|
||||
- 如果变更的是历史 TTS/ASR 面,先把“当前规范是什么”确定下来,再批量修测试。
|
||||
- 如果覆盖率策略变化,记得同步这个文件,而不是只改 pytest.ini。
|
||||
|
||||
Reference in New Issue
Block a user