agentic_huge_data_base / wiki
页面 RAGFlow · 11.3 测试基础设施·DeepWiki 中文全文译文

11.3 · 测试基础设施(Testing Infrastructure)

复杂文档理解与引用检索 · 聚焦本章的模块关系、源码依据与实现要点。

项目RAGFlow 章节11.3 状态全文译文 模块测试、发布与运维、安装与启动、界面与交互、模型调用与提供方适配
源码线索
  • .github/workflows/release.yml
  • .github/workflows/tests.yml
  • Dockerfile
  • Dockerfile.deps
  • api/apps/restful_apis/user_api.py
  • docker/docker-compose-base.yml
  • docker/infinity_conf.toml
  • download_deps.py
  • helm/values.yaml
  • pyproject.toml
模块标签
  • 测试、发布与运维
  • 安装与启动
  • 界面与交互
  • 模型调用与提供方适配
  • 系统架构

章节正文

测试基础设施

测试基础设施

相关源文件

本章引用的主要源码文件:

  • .github/workflows/release.yml
  • .github/workflows/tests.yml
  • Dockerfile
  • Dockerfile.deps
  • api/apps/restful_apis/user_api.py
  • docker/docker-compose-base.yml
  • docker/infinity_conf.toml
  • download_deps.py
  • helm/values.yaml
  • pyproject.toml
  • sdk/python/pyproject.toml
  • sdk/python/test/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.py
  • sdk/python/uv.lock
  • test/benchmark/README.md
  • test/benchmark/auth.py
  • test/benchmark/cli.py
  • test/playwright/README.md
  • test/playwright/auth/test_register_success_optional.py
  • test/playwright/auth/test_register_then_login_flow.py
  • test/playwright/auth/test_sso_optional.py
  • test/playwright/conftest.py
  • test/playwright/e2e/test_dataset_upload_parse.py
  • test/playwright/e2e/test_model_providers_zhipu_ai_defaults.py
  • test/playwright/e2e/test_next_apps_agent.py
  • test/playwright/e2e/test_next_apps_chat.py
  • test/playwright/e2e/test_next_apps_search.py
  • test/playwright/helpers/_auth_helpers.py
  • test/playwright/helpers/_next_apps_helpers.py
  • test/playwright/helpers/datasets.py
  • test/playwright/helpers/model_providers.py
  • test/testcases/conftest.py
  • test/testcases/test_http_api/test_file_management_within_dataset/test_delete_documents.py
  • test/testcases/test_http_api/test_file_management_within_dataset/test_parse_documents.py
  • test/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.py
  • test/testcases/test_sdk_api/test_file_management_within_dataset/test_delete_documents.py
  • test/testcases/test_sdk_api/test_file_management_within_dataset/test_download_document.py
  • test/testcases/test_sdk_api/test_file_management_within_dataset/test_parse_documents.py
  • test/testcases/test_web_api/conftest.py
  • test/testcases/test_web_api/test_chunk_app/conftest.py
  • test/testcases/test_web_api/test_chunk_app/test_create_chunk.py
  • test/testcases/test_web_api/test_chunk_app/test_list_chunks.py
  • test/testcases/test_web_api/test_chunk_app/test_rm_chunks.py
  • test/testcases/test_web_api/test_chunk_app/test_update_chunk.py
  • test/testcases/test_web_api/test_document_app/test_create_document.py
  • test/testcases/test_web_api/test_document_app/test_list_documents.py
  • test/testcases/test_web_api/test_document_app/test_paser_documents.py
  • test/testcases/test_web_api/test_document_app/test_rm_documents.py
  • test/testcases/test_web_api/test_document_app/test_upload_documents.py
  • test/testcases/test_web_api/test_user_app/test_user_app_unit.py
  • test/unit_test/api/db/services/test_dialog_service_use_sql_source_columns.py
  • uv.lock
  • web/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 生态系统交互,将自然语言测试定义桥接到代码实体。

测试接口架构

RAGFlow · 测试中的系统数据流 · 图 1
RAGFlow · 测试中的系统数据流 · 图 1

来源: 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 自动化了测试过程。它处理以下事项:

  1. 环境设置:使用 uv 构建 Go 服务器和 Python 环境 pyproject.toml:188-199
  2. 容器化:构建 ragflow:nightly 镜像 Dockerfile:134-150
  3. 执行矩阵:根据环境配置,针对不同的文档引擎(Infinity、Elasticsearch、OpenSearch)运行测试 helm/values.yaml:14-21
  4. 静态分析:运行 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_documentsstop_parse_documentsdelete_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 进行本地开发编排。

基础设施组件映射

RAGFlow · 测试基础设施组件 · 图 2
RAGFlow · 测试基础设施组件 · 图 2
测试依赖管理

测试依赖项在单独的组中进行管理,以保持生产镜像的精简:

  • Python 库pytesthypothesispytest-playwrightpytest-covtest 依赖组中定义 pyproject.toml:170-186
  • 外部二进制文件Dockerfile 包含安装 chrome-linux64chromedriver 的逻辑,以支持 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