Community程式設計與開發github.com

openclaw-test-performance

對 OpenClaw 測試與插件套件進行基準測試、診斷與最佳化,鎖定匯入熱點、CPU/RSS、堆積成長與緩慢的涵蓋路徑。

openclaw-test-performance 是什麼?

此技能專注於以實證為基礎的 OpenClaw 測試效能改進,核心目標是在不破壞原始涵蓋率的前提下,真實縮短 `pnpm test`、插件套件及插件檢查器的執行時間並降低記憶體使用量(RSS)。 支援的開發環境包括本機命令列、以及透過 Testbox 或遠端工作流程進行的隔離測試。運作方式要求開發者先閱讀相關的 `AGENTS.md` 文件以理解模組邊界,接著為受影響的命令建立基線數據,然後透過分離牆壁時間、Vitest 持續時間、匯入分解與最大 RSS 等指標來辨識真正的瓶頸。 修復策略強調處理根本原因而非症狀:將靜態中繼資料遷移至輕量工件、使用依賴注入與純輔助函式、避免在測試循環中重設模組與啟動伺服器。技能還提供了常見的根本原因清單(如載入全捆綁執行時期以取得靜態資料、在熱路徑中引入廣泛的 barrel 匯入),以及詳細的基準命令與驗證程序,確保每次改善都有可量測的增益與完整的涵蓋保留。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/clawdbot/clawdbot/tree/main/.agents/skills/openclaw-test-performance

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

OpenClaw 測試效能

用證據說話。目標是真正改善 pnpm test、插件套件及插件檢查器的速度與 RSS,同時保持涵蓋率完整,而不是靠猜測調整執行器。

工作流程

  1. 在編輯前先閱讀相關的本機 AGENTS.md 檔案:
    • 代理程式/匯入熱點請閱讀 src/agents/AGENTS.md。
    • 插件/通道的惰性載入請閱讀 src/channels/AGENTS.md 與 src/plugins/AGENTS.md。
    • 伺服器生命週期測試請閱讀 src/gateway/AGENTS.md。
    • 共享合約輔助函式請閱讀 test/helpers/AGENTS.md 與 src/channels/plugins/contracts/test-helpers/AGENTS.md。
    • 對外/媒體/動作測試請閱讀 src/infra/outbound/AGENTS.md。
  2. 在修改程式碼前先建立基線:
    • 針對完整套件的排名,優先使用 pnpm test:perf:groups --full-suite --allow-failures --output <file>。
    • 針對捆綁插件的廣度,在跳到完整擴展掃描前,先執行最小的相關 pnpm test:extensions:batch <plugin[,plugin...]> 或插件檢查器命令。
    • 針對範圍限定的熱點,使用:/usr/bin/time -l pnpm test <file-or-files> --maxWorkers=1 --reporter=verbose
    • 若懷疑是匯入密集型問題,可加入:OPENCLAW_VITEST_IMPORT_DURATIONS=1 OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1。
  3. 將牆壁時間/執行器噪音與真實檔案成本分開:
    • 比較 Vitest 持續時間、測試主體耗時、匯入分解、牆壁時間與最大 RSS。
    • 當分組/完整套件的數字看起來過時或有噪音時,重新執行單一檔案。
    • 如果完整套件的分組執行回報某個 lane 失敗,但 JSON 顯示測試通過,則將其歸類為測試架構/噪音,並直接驗證可疑檔案。
  4. 根據回報與風險選擇下一個攻擊目標:
    • 高回報:某個檔案/測試佔據數秒或大量 RSS,且有明確的根本原因。
    • 高槓桿:某個插件或 SDK barrel 導致每個插件檢查器或擴展批次執行都載入龐大的執行時期。
    • 較低風險:靜態描述子、目標解析、路由、認證繞過、設定提示、註冊表 fixture 或測試伺服器生命週期。
    • 較高風險:真正的記憶體/執行時期行為、即時提供者、協定合約或大規模生產重構。
  5. 修復根本原因,而非症狀:
    • 將靜態中繼資料/解析移到窄輔助函式或輕量工件中,並讓完整執行時期與快速路徑共用。
    • 優先使用依賴注入、僅載入已載入插件的查詢、明確的 fixture 與純輔助函式,而不是廣泛的 mock。
    • 當新握手無關緊要時,重複使用套件層級的伺服器/用戶端。
    • 除非測試在證明排程行為,否則關閉排程器/背景循環。
    • 在插件路徑中,將靜態中繼資料移到 manifest/輕量工件中,並將執行時期的插件載入保留在明確的執行邊界之後。
  6. 保留涵蓋率形狀:
    • 除非將確切的生產組合提取成具名輔助函式並進行測試,否則不要刪除慢速的整合測試。
    • 當跨元件接線很重要時,保留一個便宜的整合冒煙測試。
    • 明確說明移除了哪些附帶涵蓋率(如果有的話)。
  7. 在變更後重新對相同命令進行基準測試,並計算秒數與百分比增益。
  8. 當被要求時,或當這個執行緒正在追蹤某個報告時,更新進行中的報告。報告應包含前後命令、工件、涵蓋率備註、驗證結果與下一個攻擊順序。
  9. 暫存意圖修改的路徑,使用標準 Git 提交,並在使用者要求提交/推送時推送。只暫存為了本次攻擊而修改的檔案。

插件套件工作流程

當效能工作涉及捆綁插件、插件檢查器、SDK barrel、套件邊界測試或擴展套件時,請使用此流程。

  1. 先繪製套件形狀:
    • 原始碼測試:pnpm test extensions/<id> 或 pnpm test:extensions:batch <id>
    • 套件邊界:pnpm run test:extensions:package-boundary:canary 與 pnpm run test:extensions:package-boundary:compile
    • 所有捆綁的原始碼測試:pnpm test:extensions
    • 插件匯入記憶體:pnpm test:extensions:memory -- --json .artifacts/test-perf/extensions-memory.json
    • 插件檢查器/報告工作:將報告原語保留在 plugin-inspector 中;保持封裝輕薄,並在命令支援時收集峰值 RSS。
  2. 從窄開始,再擴大:
    • 只更改了一個插件:執行該插件的測試與插件檢查器切片。
    • SDK/公開 barrel 變更:加入代表性的提供者、通道、記憶體與功能插件。
    • 載入器/執行時期鏡像變更:加入套件邊界檢查,並根據需要提供建置/套件證明。
    • 未知的共享插件行為:在執行 pnpm test:extensions 之前,先執行 test:extensions:batch 分組。
  3. 將插件檢查器失敗視為產品訊號:
    • JSON 必須能夠解析。
    • 警告/錯誤必須分類,不能隱藏。
    • 執行時期擷取應保持安靜且配置相容。
    • 命令輸出應包含牆壁時間、結束代碼與峰值 RSS(如有)。
  4. 使用 $openclaw-testing 作為主機選擇依據。在可比較的機器/負載條件下,可信的來源基準測試可以在本機執行。當證明需要乾淨的套件、Linux/平台行為、隔離或明確的遠端請求時,請使用 $crabbox;重複使用並僅清理所擁有的租約。
  5. 如果插件效能對套件工件敏感,請切換到 release-openclaw-plugin-testing 與套件驗收,而不是信任僅限來源的計時。

指標收集

在變更前後至少收集一個穩定的指標。優先使用同一台機器與相同的命令。對於 Testbox 比較,盡可能使用相同的 tbx_... ID。

指標用途偏好來源
牆壁時間使用者可見的套件成本/usr/bin/time -l、測試封裝持續時間、Testbox 執行時間
Vitest 持續時間測試主體/匯入成本每個檔案/分片的 Vitest 輸出
匯入持續時間廣泛的 barrel/執行時期載入OPENCLAW_VITEST_IMPORT_DURATIONS=1
max RSS記憶體壓力與 OOM 風險/usr/bin/time -l、pnpm test:extensions:memory、封裝記憶體摘要
CPU/user/sysCPU 密集與等待密集的區分本機使用 /usr/bin/time -l,當本機 CPU 有噪音時使用 Testbox 工作計時
堆積證據真實洩漏與保留模組圖的區分openclaw-test-heap-leaks 工作流程

本機範圍限定命令(含 CPU/RSS):

timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose

插件匯入記憶體設定檔:

pnpm build
pnpm test:extensions:memory -- --top 20 --json .artifacts/test-perf/extensions-memory.json

目標插件匯入記憶體:

pnpm test:extensions:memory -- --extension discord --extension telegram --skip-combined

堆積/RSS 升級:

pnpm test:perf:groups \
  --config test/vitest/vitest.unit-fast.config.ts \
  --allow-failures \
  --output .artifacts/test-perf/unit-fast-memory.json
pnpm test:perf:profile:runner -- \
  --output-dir .artifacts/test-perf/vitest-runner-profile -- <file>

當 RSS 在間隔之間持續增長、工作者 OOM,或可疑命令有應用程式物件保留時,請使用 openclaw-test-heap-leaks。在快照或保留者支持之前,不要將 RSS 增長稱為洩漏。

常見根本原因

  • 為了取得靜態資料而載入完整的捆綁通道/插件執行時期。
  • 在已有載入的 fixture 或純解析器足夠時,使用了 getChannelPlugin() 回退。
  • 將廣泛的 api.ts、runtime-api.ts、test-api.ts 或插件-sdk barrel 引入熱測試。
  • SDK 根別名或套件 barrel 將聚焦的子路徑拉回廣泛的插件圖中。
  • 插件檢查器為了渲染中繼資料、報告或 CI 政策分數而載入執行時期程式碼。
  • 捆綁的插件擷取使用了真實的設定/家目錄狀態,而不是合成、編輯、隔離的狀態。
  • 部分真實的 mock 圍繞廣泛模組使用 importActual()。
  • 在每個測試的循環中使用 vi.resetModules() 加上重新匯入。
  • 測試插件註冊表在 beforeAll 中播種,而執行時期狀態在 afterEach 中重設。
  • 每次測試都重新啟動閘道器/伺服器/用戶端,而狀態重設就已足夠。
  • 空閒快照或 fixture 支付了執行時期/預設模型/認證選擇的成本。
  • 在檢查引數是否包含插件所屬欄位之前,就觸發了插件擁有的媒體/動作發現。
  • 平行 Vitest 執行共用了 node_modules/.experimental-vitest-cache,但沒有不同的 OPENCLAW_VITEST_FS_MODULE_CACHE_PATH 值。

基準命令

範圍限定檔案:

timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose

範圍限定檔案含匯入分解:

timeout 240 /usr/bin/time -l env \
  OPENCLAW_VITEST_IMPORT_DURATIONS=1 \
  OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1 \
  pnpm test <file> --maxWorkers=1 --reporter=verbose

分組套件:

pnpm test:perf:groups --full-suite --allow-failures \
  --output .artifacts/test-perf/<name>.json

擴展批次:

pnpm test:extensions:batch <plugin[,plugin...]> -- --reporter=verbose

所有擴展測試:

pnpm test:extensions

套件邊界插件檢查:

pnpm run test:extensions:package-boundary:canary
pnpm run test:extensions:package-boundary:compile

重複使用現有的 Vitest JSON 報告:

pnpm test:perf:groups --report <vitest-json> \
  --output .artifacts/test-perf/<name>.json

驗證

  • 始終執行目標測試範圍來證明變更。
  • 針對聚焦測試、必要建置、證明路由與發布時機,請遵循 OpenClaw 測試。
  • 對於僅測試的變更,透過該擁有者支援的命令執行被編輯的確切測試。
  • 對於插件 SDK/barrel/執行時期變更,當公開 API 表面可能偏移時,使用 pnpm plugin-sdk:api:diff -- --base <base-sha> --head <head-sha> 來比較確切提交。對於 PR 本機證明,使用分支合併基礎作為 <base-sha>,並使用經過測試的確切頭部提交作為 <head-sha>。
  • 對於插件套件的效能修復,驗證至少一個代表性插件批次加上變更的關卡;如果錯誤僅存在於打包的工件中,請使用套件驗收。
  • 對於遺失或過時的依賴,請遵循來源依賴與當前工作目錄的擁有者指示。使用合格的證明路由。
  • 使用報告格式:
| 指標       | 之前  | 之後  |        增益 |
| ---------- | ----: | ----: | ----------: |
| 檔案牆壁時間 |  `Xs` |  `Ys` |  `-Zs` (`P%`) |
| Max RSS    |  `XMB` |  `YMB` | `-ZMB` (`P%`) |
| CPU user/sys | `X/Ys` | `A/Bs` |       說明   |

交接

保持最終摘要簡潔:

  • 根本原因。
  • 套件/插件範圍。
  • 修改的檔案。
  • 前後的牆壁時間、Vitest/匯入、CPU 與 RSS 數字(如有)。
  • 如果涉及記憶體,洩漏分類:真實洩漏、保留模組圖或無法判定。
  • 保留的涵蓋率。
  • 驗證命令。
  • 遠端證明的 Testbox ID 或工作流程 URL。
  • 提交雜湊與推送狀態。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

1password

Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.

acp-router

Route plain-language requests for Claude Code, Cursor, Copilot, OpenClaw ACP, OpenCode, Gemini CLI, Grok Build, Qwen, Kiro, Kimi, iFlow, Factory Droid, Kilocode, or explicit ACP harness work into either OpenClaw ACP runtime sessions or direct acpx-driven sessions ("telephone game" flow). For coding-agent thread requests, read this skill first, then use only `sessions_spawn` for thread creation. Codex chat binding defaults to the native Codex app-server plugin unless ACP is explicit or background spawn needs ACP.

add-model-provider

Add and live-prove a model provider with non-interactive config one-liners, without exposing credentials.

agent-transcript

Requested GitHub PR/issue agent transcripts: redact, trim, preview, and insert safely.

apple-notes

Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.

apple-reminders

List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.

auto-qa

Run OpenClaw-wide autonomous QA and live/stress campaigns across independent subsystem lanes, with verified fixes and a resumable evidence report.

autoreview

Structured code review through the shared OpenClaw agent-skills installation.

bear-notes

Create, search, and manage Bear notes via grizzly CLI.

blacksmith-testbox

Run Blacksmith Testbox for CI-parity checks, secrets, hosted services, migrations, or builds local cannot reproduce.

block-kit

Use proactively for structured or interactive Slack replies, and when asked to author or validate native Slack Block Kit JSON.

blogwatcher

Monitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.

blucli

BluOS CLI (blu) for discovery, playback, grouping, and volume.

bluebubbles

Send and manage iMessages via BlueBubbles, including attachments, tapbacks, edits, replies, and groups.

browser-automation

Use when controlling web pages with the OpenClaw browser tool, especially multi-step flows, login checks, tab management, or recovery from stale refs/timeouts.

camsnap

Capture frames or clips from RTSP/ONVIF cameras and local webcams, including USB pan/tilt/zoom control.

canvas

Present HTML on connected OpenClaw node canvases, navigate/eval/snapshot, and debug canvas host URLs.

channel-message-flows

Use when running QA Lab channel message flow evidence.

clawdtributor

Clawtributor PRs here, last week or another window: discover conversation refs, recheck GitHub, rank by impact.

clawhub

Search ClawHub for plugins by default, or skills and agent Templates when requested; add Templates; install, verify, update, uninstall, publish, or sync skills.

相關技能