optimizetests
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOptimize 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
操作手册
- Read ,
docs/help/testing.md, and the scopeddocs/ci.mdfiles for any subtree you will edit.AGENTS.md - 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
- Full ranking:
- Attack highest-return hotspots first:
- broad barrels or in hot tests
importActual() - per-test plus fresh imports
vi.resetModules() - expensive gateway/server/client setup where reset/reuse proves same behavior
- core tests asserting extension-owned behavior
- duplicated fixture construction or contract assertions
- broad barrels or
- 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
- After each change, rerun the same benchmark and the proving test lane. Record before/after wall time, Vitest duration, and max RSS when available.
- Run ; run broader gates (
pnpm check:changed,pnpm check,pnpm test) when touched surfaces require them.pnpm build - Commit scoped changes with . Push when requested. If CI is red, inspect with
scripts/committer "<conventional message>" <paths...>, fix, push, repeat until current CI is green or a blocker is proven unrelated.gh run list/view
- 阅读、
docs/help/testing.md以及你将要编辑的任何子树对应的范围化docs/ci.md文件AGENTS.md - 在编辑前收集证据:
- 完整排名:
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
- 完整排名:
- 优先处理收益最高的热点问题:
- 热门测试中的大范围依赖或
importActual() - 每个测试中的加上全新导入
vi.resetModules() - 可重置/复用且不影响行为的高成本网关/服务器/客户端初始化
- 断言扩展专属行为的核心测试
- 重复的 fixture 构造或契约断言
- 热门测试中的大范围依赖或
- 优先采用生产级别的修复方案:
- 窄范围运行时接缝而非宽泛的模拟
- 用于静态解析/元数据的纯辅助函数
- 注入依赖而非模块重置
- 针对捆绑插件/提供者/通道行为的扩展专属测试
- 每次修改后,重新运行相同的基准测试和验证测试流程。记录修改前后的运行时长、Vitest 耗时以及可用的最大RSS值。
- 运行;当涉及的代码范围需要时,运行更全面的检查(
pnpm check:changed、pnpm check、pnpm test)。pnpm build - 使用提交范围化的修改。按要求推送代码。如果CI失败,使用
scripts/committer "<符合规范的提交信息>" <路径...>检查问题,修复后重新推送,重复此过程直到当前CI通过或确认阻塞问题与修改无关。gh run list/view
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状态,以及任何需要单独优化的剩余后续任务。