optimizetests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Optimize Tests

测试优化

Goal: real OpenClaw test/runtime speedups with coverage intact. Do not add shards, skip assertions, weaken gates, or tune runner flags as the main fix.
目标:在保持覆盖率的前提下,实现OpenClaw测试/运行时的实际提速。不要将添加分片、跳过断言、弱化检查门槛或调整运行器标志作为主要修复手段。

Runbook

操作手册

  1. Read
    docs/help/testing.md
    ,
    docs/ci.md
    , and the scoped
    AGENTS.md
    files for any subtree you will edit.
  2. Establish evidence before edits:
    • Full ranking:
      pnpm test:perf:groups --full-suite --allow-failures --output .artifacts/test-perf/<name>.json
    • Targeted file:
      timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose
    • Import suspicion: add
      OPENCLAW_VITEST_IMPORT_DURATIONS=1 OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1
  3. Attack highest-return hotspots first:
    • broad barrels or
      importActual()
      in hot tests
    • per-test
      vi.resetModules()
      plus fresh imports
    • expensive gateway/server/client setup where reset/reuse proves same behavior
    • core tests asserting extension-owned behavior
    • duplicated fixture construction or contract assertions
  4. Prefer production-quality fixes:
    • narrow runtime seams over broad mocks
    • pure helpers for static parsing/metadata
    • injected deps over module resets
    • extension-owned tests for bundled plugin/provider/channel behavior
  5. After each change, rerun the same benchmark and the proving test lane. Record before/after wall time, Vitest duration, and max RSS when available.
  6. Run
    pnpm check:changed
    ; run broader gates (
    pnpm check
    ,
    pnpm test
    ,
    pnpm build
    ) when touched surfaces require them.
  7. Commit scoped changes with
    scripts/committer "<conventional message>" <paths...>
    . Push when requested. If CI is red, inspect with
    gh run list/view
    , fix, push, repeat until current CI is green or a blocker is proven unrelated.
  1. 阅读
    docs/help/testing.md
    docs/ci.md
    以及你将要编辑的任何子树对应的范围化
    AGENTS.md
    文件
  2. 在编辑前收集证据:
    • 完整排名:
      pnpm test:perf:groups --full-suite --allow-failures --output .artifacts/test-perf/<name>.json
    • 目标文件:
      timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose
    • 导入排查:添加
      OPENCLAW_VITEST_IMPORT_DURATIONS=1 OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1
  3. 优先处理收益最高的热点问题:
    • 热门测试中的大范围依赖或
      importActual()
    • 每个测试中的
      vi.resetModules()
      加上全新导入
    • 可重置/复用且不影响行为的高成本网关/服务器/客户端初始化
    • 断言扩展专属行为的核心测试
    • 重复的 fixture 构造或契约断言
  4. 优先采用生产级别的修复方案:
    • 窄范围运行时接缝而非宽泛的模拟
    • 用于静态解析/元数据的纯辅助函数
    • 注入依赖而非模块重置
    • 针对捆绑插件/提供者/通道行为的扩展专属测试
  5. 每次修改后,重新运行相同的基准测试和验证测试流程。记录修改前后的运行时长、Vitest 耗时以及可用的最大RSS值。
  6. 运行
    pnpm check:changed
    ;当涉及的代码范围需要时,运行更全面的检查(
    pnpm check
    pnpm test
    pnpm build
    )。
  7. 使用
    scripts/committer "<符合规范的提交信息>" <路径...>
    提交范围化的修改。按要求推送代码。如果CI失败,使用
    gh run list/view
    检查问题,修复后重新推送,重复此过程直到当前CI通过或确认阻塞问题与修改无关。

Output

输出

End with the pushed commit(s), before/after timings, gates run, current CI state, and any remaining tail lanes that need separate optimization.
最终需提交已推送的提交记录、修改前后的时间数据、运行的检查流程、当前CI状态,以及任何需要单独优化的剩余后续任务。