Plugin Testing
OpenClaw 外掛的測試工具、模式與 lint 強制的參考。測試工具
Import:openclaw/plugin-sdk/testing
testing subpath 為外掛作者匯出一個窄的輔助函式集:
可用匯出
| Export | 目的 |
|---|---|
installCommonResolveTargetErrorCases | Target 解析錯誤處理的共享測試案例 |
shouldAckReaction | 檢查 channel 是否應加入 ack reaction |
removeAckReactionAfterReply | 回覆遞送後移除 ack reaction |
型別
testing subpath 也重新匯出測試檔案中有用的型別:測試 target 解析
使用installCommonResolveTargetErrorCases 為 channel target 解析加入標準錯誤案例:
測試模式
單元測試 channel 外掛
單元測試 provider 外掛
Mock plugin runtime
針對使用createPluginRuntimeStore 的代碼,在測試中 mock runtime:
使用每個實例的 stubs 測試
優先使用每個實例的 stubs 而不是原型突變:合約測試(in-repo 外掛)
捆綁外掛有合約測試,驗證註冊所有權:- 哪些外掛註冊哪些 provider
- 哪些外掛註冊哪些語音 provider
- 註冊形狀正確性
- Runtime 合約相容性
執行範疇測試
針對特定外掛:Lint 強制(in-repo 外掛)
針對 in-repo 外掛,三個規則由pnpm check 強制:
- 沒有一元根 imports — 拒絕
openclaw/plugin-sdk根 barrel - 沒有直接
src/imports — 外掛無法直接 import../../src/ - 沒有自我 imports — 外掛無法 import 自己的
plugin-sdk/<name>subpath
測試配置
OpenClaw 使用 Vitest 搭配 V8 覆蓋閾值。針對外掛測試:相關
- SDK 概述 — import 慣例
- SDK Channel 外掛 — channel 外掛介面
- SDK Provider 外掛 — provider 外掛 hooks
- 建置外掛 — 入門指南