测试基础设施
测试基础设施
相关源文件
本章引用的主要源码文件:
.github/workflows/release.yml.github/workflows/tests.ymlDockerfileDockerfile.depsapi/apps/restful_apis/user_api.pydocker/docker-compose-base.ymldocker/infinity_conf.tomldownload_deps.pyhelm/values.yamlpyproject.tomlsdk/python/pyproject.tomlsdk/python/test/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.pysdk/python/uv.locktest/benchmark/README.mdtest/benchmark/auth.pytest/benchmark/cli.pytest/playwright/README.mdtest/playwright/auth/test_register_success_optional.pytest/playwright/auth/test_register_then_login_flow.pytest/playwright/auth/test_sso_optional.pytest/playwright/conftest.pytest/playwright/e2e/test_dataset_upload_parse.pytest/playwright/e2e/test_model_providers_zhipu_ai_defaults.pytest/playwright/e2e/test_next_apps_agent.pytest/playwright/e2e/test_next_apps_chat.pytest/playwright/e2e/test_next_apps_search.pytest/playwright/helpers/_auth_helpers.pytest/playwright/helpers/_next_apps_helpers.pytest/playwright/helpers/datasets.pytest/playwright/helpers/model_providers.pytest/testcases/conftest.pytest/testcases/test_http_api/test_file_management_within_dataset/test_delete_documents.pytest/testcases/test_http_api/test_file_management_within_dataset/test_parse_documents.pytest/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.pytest/testcases/test_sdk_api/test_file_management_within_dataset/test_delete_documents.pytest/testcases/test_sdk_api/test_file_management_within_dataset/test_download_document.pytest/testcases/test_sdk_api/test_file_management_within_dataset/test_parse_documents.pytest/testcases/test_web_api/conftest.pytest/testcases/test_web_api/test_chunk_app/conftest.pytest/testcases/test_web_api/test_chunk_app/test_create_chunk.pytest/testcases/test_web_api/test_chunk_app/test_list_chunks.pytest/testcases/test_web_api/test_chunk_app/test_rm_chunks.pytest/testcases/test_web_api/test_chunk_app/test_update_chunk.pytest/testcases/test_web_api/test_document_app/test_create_document.pytest/testcases/test_web_api/test_document_app/test_list_documents.pytest/testcases/test_web_api/test_document_app/test_paser_documents.pytest/testcases/test_web_api/test_document_app/test_rm_documents.pytest/testcases/test_web_api/test_document_app/test_upload_documents.pytest/testcases/test_web_api/test_user_app/test_user_app_unit.pytest/unit_test/api/db/services/test_dialog_service_use_sql_source_columns.pyuv.lockweb/src/utils/llm-util.ts
RAGFlow 的测试基础设施提供了一套全面的验证套件,覆盖了整个技术栈,从核心数学工具到端到端的浏览器交互。该系统使用 pytest 作为主要测试运行器,并与 GitHub Actions 集成以实现持续集成和持续部署。
测试套件组织
测试套件根据其目标接口以及在请求生命周期中的位置,分为几个不同的层级。
| 类别 | 位置 | 目的 | 关键工具 |
|---|---|---|---|
| SDK 测试 | test/testcases/test_sdk_api/ | 验证 Python SDK 客户端逻辑及其与服务器的交互。 | ragflow-sdk, pytest |
| HTTP API 测试 | test/testcases/test_http_api/ | 通过 requests 直接测试 RESTful API 端点。 | requests, pytest, hypothesis |
| Web API 测试 | test/testcases/test_web_api/ | 测试 React 前端使用的内部 API。 | requests, pytest |
| SDK 单元测试 | sdk/python/test/ | 验证特定 SDK 组件和客户端逻辑。 | pytest, requests |
| Playwright 端到端测试 | test/playwright/ | 基于浏览器的应用程序端到端测试。 | pytest-playwright |
| 单元测试 | test/unit_test/ | 测试独立的业务逻辑和工具函数。 | pytest |
测试中的系统数据流
下图说明了不同类型的测试如何与 RAGFlow 生态系统交互,将自然语言测试定义桥接到代码实体。
测试接口架构
来源: sdk/python/pyproject.toml:1-4, docker/docker-compose-base.yml:72-146, docker/docker-compose-base.yml:148-174, docker/docker-compose-base.yml:225-231, pyproject.toml:170-186
测试配置与持续集成
RAGFlow 利用 pytest 的夹具(fixtures)、标记(markers)和 GitHub Actions 来管理状态并在不同环境中确定执行优先级。
Pytest 标记与优先级
测试套件使用优先级标记对测试进行分类,这些标记在 SDK 和主测试配置中定义:
@pytest.mark.p1:关键/高优先级功能测试,例如基本数据集创建或文档上传sdk/python/pyproject.toml:28-28。@pytest.mark.p2:中等优先级测试,涵盖边界条件和标准工作流sdk/python/pyproject.toml:29-29。@pytest.mark.p3:低优先级或边缘情况测试,包括长时间运行或非关键路径测试sdk/python/pyproject.toml:30-30。
持续集成(CI)
GitHub Actions 工作流 tests.yml 自动化了测试过程。它处理以下事项:
- 环境设置:使用
uv构建 Go 服务器和 Python 环境pyproject.toml:188-199。 - 容器化:构建
ragflow:nightly镜像Dockerfile:134-150。 - 执行矩阵:根据环境配置,针对不同的文档引擎(Infinity、Elasticsearch、OpenSearch)运行测试
helm/values.yaml:14-21。 - 静态分析:运行
Ruff进行代码风格检查和格式化检查.github/workflows/tests.yml:94-98。
来源: sdk/python/pyproject.toml:26-31, .github/workflows/tests.yml:132-150, pyproject.toml:188-199, helm/values.yaml:14-21
专项测试场景
SDK 和 HTTP API 测试
SDK 和 HTTP API 测试确保外部集成的稳定性。
- 文件管理:
test/testcases/test_http_api/test_file_management_within_dataset/中的测试验证了文档生命周期操作,例如parse_documents、stop_parse_documents和delete_documents。 - 基于属性的测试:使用
Hypothesis生成多样化的输入数据,以测试 API 的健壮性pyproject.toml:171-171。
Playwright 端到端测试
test/playwright/ 中的基于浏览器的测试模拟了真实的用户交互:
- 认证流程:验证注册和登录成功
test/playwright/auth/test_register_then_login_flow.py。 - 应用工作流:测试聊天会话(
test_next_apps_chat.py)、代理执行(test_next_apps_agent.py)和知识库搜索(test_next_apps_search.py)。 - 模型提供商设置:验证与智谱AI等大语言模型(LLM)提供商的集成
test/playwright/e2e/test_model_providers_zhipu_ai_defaults.py。
来源: pyproject.toml:171-171, pyproject.toml:184-184, test/playwright/e2e/test_next_apps_chat.py:1-1, test/playwright/e2e/test_next_apps_agent.py:1-1
测试基础设施组件
测试环境依赖于与生产环境相同的基础设施,并通过 Docker Compose 进行本地开发编排。
基础设施组件映射
测试依赖管理
测试依赖项在单独的组中进行管理,以保持生产镜像的精简:
- Python 库:
pytest、hypothesis、pytest-playwright和pytest-cov在test依赖组中定义pyproject.toml:170-186。 - 外部二进制文件:
Dockerfile包含安装chrome-linux64和chromedriver的逻辑,以支持 Playwright 和 Selenium 测试Dockerfile:116-123。 - 模拟数据:测试使用在构建过程中下载的
nltk_data和特定模型快照(DeepDoc)download_deps.py:74-77。
来源: pyproject.toml:170-186, Dockerfile:116-123, download_deps.py:74-77, docker/docker-compose-base.yml:1-231