测试指南

更新:2026-03-13 · 负责人:QA Guild

本文总结 Python + React 技术栈的测试矩阵。

:::tip 相关附录

  • docs/testing/docker-integration-tests.md
  • docs/testing/lighteval-interoperability-fixtures.md
  • docs/testing/docs-smoke-checklist.md
  • docs/testing/core-alpha-signoff.md
  • docs/testing/browser-harness-signoff.md
  • docs/testing/active-runs-hardening-signoff.md :::

覆盖率与门禁

LayerToolingRequired CoverageCI Gate
Backenduv run pytest --cov100% branch-aware coverageci.yml backend job
Frontendpnpm test --coverage核心旅程 >=80% linesci.yml frontend job
Integration(Docker)scripts/tests/run_docker_integration.sh --full-run --with-beat以回归为重点nightly + local
Playwright E2Epnpm test:e2e + pnpm test:e2e-smoke场景驱动frontend + smoke jobs

常用命令

cd backend
uv run pytest --cov --cov-report=term-missing
uv run pytest -m lighteval
uv run pytest -m integration
uv run mutmut run

cd frontend
pnpm lint
pnpm typecheck
pnpm test
pnpm test:e2e
pnpm test:e2e-smoke

后端测试细节

  1. 单元测试位于 backend/tests
  2. pytest -m lighteval 用于验证 LightEval config 生成,以及 CLI/Python 互操作
  3. pytest -m integration 用于运行 Docker-backed stack 的集成测试
  4. 后端覆盖率门禁仍由 backend/pyproject.toml 以 branch-aware 方式强制执行

Test doubles

  • 本地单元测试仍可以使用 mocks 与 fakes
  • Docker 集成测试和 LightEval 契约测试使用本地 OpenAI-compatible test gateway
  • 生产代码始终遵循标准 LiteLLM client path

Docker 驱动的集成流程

在仓库根目录运行:

scripts/tests/run_docker_integration.sh --full-run --fresh [--with-beat]

它会执行:

  1. 启动 postgresredis、本地 OpenAI-compatible gateway、celery-worker 和可选的 celery-beat
  2. 应用迁移,并用 eval_752.scripts.seed_integration 注入可复现数据
  3. 在 backend 容器中执行 uv run pytest -m integration
  4. 将 coverage 与日志收集到 .artifacts/docker-integration/

前端测试细节

  • Vitest + React Testing Library 覆盖单元与组件行为
  • Playwright 覆盖浏览器旅程与 Docker smoke
  • Active runs UI 证据由 frontend/tests/manual/active-runs-ui-audit.mjs 采集

文档 Smoke

在发布工作流变更前,请执行 docs/testing/docs-smoke-checklist.md 中的文档 smoke checklist。 这条护栏用于避免 getting-started、provider、results、i18n 和 active-runs 文档与实际产品能力漂移。