Tools
Plugin Testkit
End-to-end test kit for OpenClaw plugins: install your plugin into a throwaway OpenClaw, run a real gateway, and answer with a stub model.
Install
npm install --save-dev
Configuration Example
import assert from "node:assert/strict";
import { test } from "node:test";
import { createSandbox, startStubModel } from "openclaw-plugin-testkit";
test("my plugin works in a real OpenClaw", { timeout: 600_000 }, async (t) => {
const sandbox = await createSandbox();
const stub = await startStubModel({
reply: (request) => (request.userText.includes("weather") ? "It is sunny." : "Hello."),
});
t.after(async () => {
await stub.close();
await sandbox.cleanup();
});
const { id } = await sandbox.installPlugin(".");
await sandbox.assertPluginLoaded(id);
await sandbox.useStubModel(stub);
await sandbox.setConfig("channels.my-channel", { token: "test-token" });
const turn = await sandbox.agentTurn("What's the weather?");
assert.equal(turn.text, "It is sunny.");
const gateway = await sandbox.startGateway();
await gateway.waitForLog("my-channel connected");
});
README
# openclaw-plugin-testkit
[](https://github.com/rickysinghmba/openclaw-plugin-testkit/actions/workflows/ci.yml)
[](LICENSE)
End-to-end tests for [OpenClaw](https://openclaw.ai) plugins. The kit installs your plugin into a
throwaway OpenClaw, runs a real gateway, and answers with a stub model, so you can check that the
package you are about to publish works in a real OpenClaw.
- **Your own OpenClaw is never touched.** Each sandbox has its own state directory, config and
gateway token, and is deleted afterwards.
- **No real model is called.** A stub model on `127.0.0.1` answers every request, so tests are
free, fast and repeatable.
- **It tests what you ship.** Your plugin is packed with `npm pack` and installed from the
tarball, so a missing file or a broken `prepack` fails the test, not your users.
OpenClaw's own test helpers (`openclaw/plugin-sdk/*-test-*`) cover unit tests, and
`@openclaw/plugin-inspector` checks a package without running it. This kit covers the step after
those: does the packed plugin install, load and work in a running OpenClaw?
> **Status: 0.1, early.** Tested with OpenClaw 2026.11.9 on macOS and, in CI, on Linux. On macOS
> it has also been run on a provider plugin and a channel plugin. Please report
> what you find.
## Requirements
- Node.js 22 or later (OpenClaw itself needs Node 24)
- An OpenClaw to test against: the `openclaw` package in your project's `devDependencies`, an
`openclaw` on your `PATH`, or a path in `OPENCLAW_BIN`
## Install
Until the first npm release, install from GitHub:
```bash
npm install --save-dev github:rickysinghmba/openclaw-plugin-testkit
```
## Quick check from the command line
Run this in your plugin's folder:
```bash
npx openclaw-plugin-testkit smoke
```
It packs the plugin, installs it into a fresh sandbox and checks that OpenClaw loads it. Add
`--gateway` to also start a gateway, and `--agent-turn` to run one agent turn on the stub model:
```text
• OpenClaw 2026.11.9 in /tmp/openclaw-testkit-lnfiQB
• installed plugin "my-plugin"
• plugin loaded (version 0.1.0)
• agent turn reached the stub model and replied: "testkit stub reply"
• gateway ready on port 63381
• plugin still loaded with the gateway running
PASS
```
The command exits with code 1 on failure, so it works as a CI step.
## Use in your tests
The kit has no test framework of its own. This example uses `node:test`:
```js
import assert from "node:assert/strict";
import { test } from "node:test";
import { createSandbox, startStubModel } from "openclaw-plugin-testkit";
test("my plugin works in a real OpenClaw", { timeout: 600_000 }, async (t) => {
const sandbox = await createSandbox();
const stub = await startStubModel({
reply: (request) => (request.userText.includes("weather") ? "It is sunny." : "Hello."),
});
t.after(async () => {
await stub.close();
await sandbox.cleanup();
});
const { id } = await sandbox.installPlugin(".");
await sandbox.assertPluginLoaded(id);
await sandbox.useStubModel(stub);
await sandbox.setConfig("channels.my-channel", { token: "test-token" });
const turn = await sandbox.agentTurn("What's the weather?");
assert.equal(turn.text, "It is sunny.");
const gateway = await sandbox.startGateway();
await gateway.waitForLog("my-channel connected");
});
```
For a channel plugin, start the gateway, send a message through your platform's test server, and
wait for the stub model's reply to come back. `stub.waitForRequest()` tells you the message
reached the model.
## API
### `createSandbox(options?)`
Creates an isolated OpenClaw. Options: `openclawBin`, `cwd`, `env`, `keep` (don't delete the
sandbox on cleanup).
| Method | What it does |
| --- | --- |
| `installPlugin(dirOrTgz)` | Packs a plugin folder with `npm pack` (or takes a `.tgz`) and installs it. Returns `{ id, tarball, output }`. |
| `assertPluginLoaded(id)` | Throws, with OpenClaw's diagnostics, unless the plugin's status is `loaded`. |
| `inspectPlugin(id)` | The plugin's entry from `openclaw plugins inspect --runtime --json`. |
| `setConfig(path, value)` | Sets a config value. Objects are sent as JSON. |
| `useStubModel(stub)` | Makes the stub the default agent model. |
| `agentTurn(message)` | Runs one agent turn in-process and returns `{ text, raw }`. |
| `startGateway(options?)` | Starts a gateway on loopback and waits until it is ready. Returns `{ port, logs(), waitForLog(), stop() }`. |
| `cli(args)` / `cliJson(args)` | Runs any `openclaw` command in the sandbox. Throws on a non-zero exit unless `allowFailure` is set. |
| `version()` | The OpenClaw version under test. |
| `cleanup()` | Stops gateways and deletes the sandbox. |
### `startStubModel(options?)`
Starts an OpenAI-compatible chat model on `127.0.0.1`. Options: `reply` (a string, or a function
of the request), `port`, `modelId`, `providerId`.
| Member | What it is |
| --- | --- |
| `requests` | Every chat request received. Each has `userText`, `userTexts`, `lastUserText`, `systemText`, `toolNames`, `toolResults`, `stream` and `body`. |
| `waitForRequest(match?, timeoutMs?)` | Resolves with the first request, past or future, that matches. |
| `setReply(reply)` | Changes the reply for later requests. |
| `url`, `port`, `modelRef` | Where it listens, and the `provider/model` reference for config. |
| `close()` | Stops the server. |
### Testing a plugin's tool
A reply can be tool calls instead of text: return `{ toolCalls: [{ name, arguments }] }`.
OpenClaw doesn't hand plugin tools to the model directly. By default the model gets
`tool_search` and `dispatch_action`, finds your tool by searching, and calls it through
`dispatch_action`. A stub that calls a plugin tool by its own name gets "unknown tool". Follow the
same flow:
```js
const stub = await startStubModel({
reply: (request) => {
if (request.toolResults.length === 0) {
return { toolCalls: [{ name: "tool_search", arguments: { query: "what my tool does" } }] };
}
if (request.toolResults.length === 1) {
return { toolCalls: [{ name: "dispatch_action", arguments: { id: "my_tool", args: { city: "Paris" } } }] };
}
return "Done.";
},
});
```
`request.toolResults[0]` is then the search result, which shows whether a plain-English query
finds your tool. `request.toolNames` lists the tools OpenClaw offered the model directly. See
[openclaw-ntfy's end-to-end test](https://github.com/rickysinghmba/openclaw-ntfy/blob/main/test/e2e.test.js)
for a complete example.
## Things worth knowing
- **Match on `userText`, not `lastUserText`.** OpenClaw wraps what the person wrote in an
envelope and adds its own context messages after it, so their words are rarely the whole last
message. Use `request.userText.includes("…")`.
- **Uninstalling a channel plugin removes its `channels.<id>` config.** Set the channel config
again after reinstalling.
- **Starts are slow.** Each `openclaw` command takes several seconds and a gateway takes 20 to
60 seconds to become ready, so give end-to-end tests a timeout of several minutes and keep them
few.
- **The stub only speaks chat completions**, with text or tool-call replies. It doesn't do
embeddings, images or audio yet.
## Use in CI
```yaml
- uses: actions/setup-node@v4
with:
node-version: 24
- run: npm ci
- run: npx openclaw-plugin-testkit smoke --gateway
```
If `openclaw` is a peer dependency that `npm ci` doesn't install, install it somewhere else and
point the kit at it:
```yaml
- run: npm install --prefix "$RUNNER_TEMP/openclaw" --ignore-scripts openclaw@2026.11.9
- run: npx openclaw-plugin-testkit smoke --gateway
env:
OPENCLAW_BIN: ${{ runner.temp }}/openclaw/node_modules/openclaw/openclaw.mjs
```
## Development
```bash
npm install
npm test
```
`npm test` builds the kit and runs the unit tests. The end-to-end tests run when `OPENCLAW_BIN`
points at an OpenClaw, and are skipped otherwise.
This project is not affiliated with OpenClaw. See the [roadmap](ROADMAP.md) for what is planned.
## License
MIT
tools
Comments
Sign in to leave a comment