Caricamento in corso...
Caricamento in corso...
Last synced: Today, 22:00
Technical reference for the OpenClaw framework. Real-time synchronization with the official documentation engine.
Use this file to discover all available pages before exploring further.
Reference for test utilities, patterns, and lint enforcement for OpenClaw plugins.
Plugin API mock import:
openclaw/plugin-sdk/plugin-test-apiAgent runtime contract import:
openclaw/plugin-sdk/agent-runtime-test-contractsChannel contract import:
openclaw/plugin-sdk/channel-contract-testingChannel test helper import:
openclaw/plugin-sdk/channel-test-helpersChannel target test import:
openclaw/plugin-sdk/channel-target-testingPlugin contract import:
openclaw/plugin-sdk/plugin-test-contractsPlugin runtime test import:
openclaw/plugin-sdk/plugin-test-runtimeProvider contract import:
openclaw/plugin-sdk/provider-test-contractsProvider HTTP mock import:
openclaw/plugin-sdk/provider-http-test-mocksEnvironment/network test import:
openclaw/plugin-sdk/test-envGeneric fixture import:
openclaw/plugin-sdk/test-fixturesNode builtin mock import:
openclaw/plugin-sdk/test-node-mocksPrefer the focused subpaths below for new plugin tests. The broad
openclaw/plugin-sdk/testingplugin-sdk/testingplugin-sdk/test-utilstypescriptimport { shouldAckReaction, removeAckReactionAfterReply, } from "openclaw/plugin-sdk/channel-feedback"; import { installCommonResolveTargetErrorCases } from "openclaw/plugin-sdk/channel-target-testing"; import { AUTH_PROFILE_RUNTIME_CONTRACT } from "openclaw/plugin-sdk/agent-runtime-test-contracts"; import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api"; import { expectChannelInboundContextContract } from "openclaw/plugin-sdk/channel-contract-testing"; import { createStartAccountContext } from "openclaw/plugin-sdk/channel-test-helpers"; import { describePluginRegistrationContract } from "openclaw/plugin-sdk/plugin-test-contracts"; import { registerSingleProviderPlugin } from "openclaw/plugin-sdk/plugin-test-runtime"; import { describeOpenAIProviderRuntimeContract } from "openclaw/plugin-sdk/provider-test-contracts"; import { getProviderHttpMocks } from "openclaw/plugin-sdk/provider-http-test-mocks"; import { withEnv, withFetchPreconnect, withServer } from "openclaw/plugin-sdk/test-env"; import { bundledPluginRoot, createCliRuntimeCapture, typedCases, } from "openclaw/plugin-sdk/test-fixtures"; import { mockNodeBuiltinModule } from "openclaw/plugin-sdk/test-node-mocks";
| Export | Purpose |
|---|---|
text createTestPluginApi | Build a minimal plugin API mock for direct registration unit tests. Import from text plugin-sdk/plugin-test-api |
text AUTH_PROFILE_RUNTIME_CONTRACT | Shared auth-profile contract fixture for native agent runtime adapters. Import from text plugin-sdk/agent-runtime-test-contracts |
text DELIVERY_NO_REPLY_RUNTIME_CONTRACT | Shared delivery suppression contract fixture for native agent runtime adapters. Import from text plugin-sdk/agent-runtime-test-contracts |
text OUTCOME_FALLBACK_RUNTIME_CONTRACT | Shared fallback-classification contract fixture for native agent runtime adapters. Import from text plugin-sdk/agent-runtime-test-contracts |
text createParameterFreeTool | Build dynamic-tool schema fixtures for native runtime contract tests. Import from text plugin-sdk/agent-runtime-test-contracts |
text expectChannelInboundContextContract | Assert channel inbound context shape. Import from text plugin-sdk/channel-contract-testing |
text installChannelOutboundPayloadContractSuite | Install channel outbound payload contract cases. Import from text plugin-sdk/channel-contract-testing |
text createStartAccountContext | Build channel account lifecycle contexts. Import from text plugin-sdk/channel-test-helpers |
text installChannelActionsContractSuite | Install generic channel message-action contract cases. Import from text plugin-sdk/channel-test-helpers |
text installChannelSetupContractSuite | Install generic channel setup contract cases. Import from text plugin-sdk/channel-test-helpers |
text installChannelStatusContractSuite | Install generic channel status contract cases. Import from text plugin-sdk/channel-test-helpers |
text expectDirectoryIds | Assert channel directory ids from a directory-list function. Import from text plugin-sdk/channel-test-helpers |
text assertBundledChannelEntries | Assert bundled channel entrypoints expose the expected public contract. Import from text plugin-sdk/channel-test-helpers |
text formatEnvelopeTimestamp | Format deterministic envelope timestamps. Import from text plugin-sdk/channel-test-helpers |
text expectPairingReplyText | Assert channel pairing reply text and extract its code. Import from text plugin-sdk/channel-test-helpers |
text describePluginRegistrationContract | Install plugin registration contract checks. Import from text plugin-sdk/plugin-test-contracts |
text registerSingleProviderPlugin | Register one provider plugin in loader smoke tests. Import from text plugin-sdk/plugin-test-runtime |
text registerProviderPlugin | Capture all provider kinds from one plugin. Import from text plugin-sdk/plugin-test-runtime |
text registerProviderPlugins | Capture provider registrations across multiple plugins. Import from text plugin-sdk/plugin-test-runtime |
text requireRegisteredProvider | Assert that a provider collection contains an id. Import from text plugin-sdk/plugin-test-runtime |
text createRuntimeEnv | Build a mocked CLI/plugin runtime environment. Import from text plugin-sdk/plugin-test-runtime |
text createPluginSetupWizardStatus | Build setup status helpers for channel plugins. Import from text plugin-sdk/plugin-test-runtime |
text describeOpenAIProviderRuntimeContract | Install provider-family runtime contract checks. Import from text plugin-sdk/provider-test-contracts |
text expectPassthroughReplayPolicy | Assert provider replay policies pass through provider-owned tools and metadata. Import from text plugin-sdk/provider-test-contracts |
text runRealtimeSttLiveTest | Run a live realtime STT provider test with shared audio fixtures. Import from text plugin-sdk/provider-test-contracts |
text normalizeTranscriptForMatch | Normalize live transcript output before fuzzy assertions. Import from text plugin-sdk/provider-test-contracts |
text expectExplicitVideoGenerationCapabilities | Assert video providers declare explicit generation mode capabilities. Import from text plugin-sdk/provider-test-contracts |
text expectExplicitMusicGenerationCapabilities | Assert music providers declare explicit generation/edit capabilities. Import from text plugin-sdk/provider-test-contracts |
text mockSuccessfulDashscopeVideoTask | Install a successful DashScope-compatible video task response. Import from text plugin-sdk/provider-test-contracts |
text getProviderHttpMocks | Access opt-in provider HTTP/auth Vitest mocks. Import from text plugin-sdk/provider-http-test-mocks |
text installProviderHttpMockCleanup | Reset provider HTTP/auth mocks after each test. Import from text plugin-sdk/provider-http-test-mocks |
text installCommonResolveTargetErrorCases | Shared test cases for target resolution error handling. Import from text plugin-sdk/channel-target-testing |
text shouldAckReaction | Check whether a channel should add an ack reaction. Import from text plugin-sdk/channel-feedback |
text removeAckReactionAfterReply | Remove ack reaction after reply delivery. Import from text plugin-sdk/channel-feedback |
text createTestRegistry | Build a channel plugin registry fixture. Import from text plugin-sdk/plugin-test-runtimetext plugin-sdk/channel-test-helpers |
text createEmptyPluginRegistry | Build an empty plugin registry fixture. Import from text plugin-sdk/plugin-test-runtimetext plugin-sdk/channel-test-helpers |
text setActivePluginRegistry | Install a registry fixture for plugin runtime tests. Import from text plugin-sdk/plugin-test-runtimetext plugin-sdk/channel-test-helpers |
text createRequestCaptureJsonFetch | Capture JSON fetch requests in media helper tests. Import from text plugin-sdk/test-env |
text withServer | Run tests against a disposable local HTTP server. Import from text plugin-sdk/test-env |
text createMockIncomingRequest | Build a minimal incoming HTTP request object. Import from text plugin-sdk/test-env |
text withFetchPreconnect | Run fetch tests with preconnect hooks installed. Import from text plugin-sdk/test-env |
text withEnvtext withEnvAsync | Temporarily patch environment variables. Import from text plugin-sdk/test-env |
text createTempHomeEnvtext withTempHometext withTempDir | Create isolated filesystem test fixtures. Import from text plugin-sdk/test-env |
text createMockServerResponse | Create a minimal HTTP server response mock. Import from text plugin-sdk/test-env |
text createCliRuntimeCapture | Capture CLI runtime output in tests. Import from text plugin-sdk/test-fixtures |
text importFreshModule | Import an ESM module with a fresh query token to bypass module cache. Import from text plugin-sdk/test-fixtures |
text bundledPluginRoottext bundledPluginFile | Resolve bundled plugin source or dist fixture paths. Import from text plugin-sdk/test-fixtures |
text mockNodeBuiltinModule | Install narrow Node builtin Vitest mocks. Import from text plugin-sdk/test-node-mocks |
text createSandboxTestContext | Build sandbox test contexts. Import from text plugin-sdk/test-fixtures |
text writeSkill | Write skill fixtures. Import from text plugin-sdk/test-fixtures |
text makeAgentAssistantMessage | Build agent transcript message fixtures. Import from text plugin-sdk/test-fixtures |
text peekSystemEventstext resetSystemEventsForTest | Inspect and reset system event fixtures. Import from text plugin-sdk/test-fixtures |
text sanitizeTerminalText | Sanitize terminal output for assertions. Import from text plugin-sdk/test-fixtures |
text countLinestext hasBalancedFences | Assert chunking output shape. Import from text plugin-sdk/test-fixtures |
text runProviderCatalog | Execute a provider catalog hook with test dependencies |
text resolveProviderWizardOptions | Resolve provider setup wizard choices in contract tests |
text resolveProviderModelPickerEntries | Resolve provider model-picker entries in contract tests |
text buildProviderPluginMethodChoice | Build provider wizard choice ids for assertions |
text setProviderWizardProvidersResolverForTest | Inject provider wizard providers for isolated tests |
text createProviderUsageFetch | Build provider usage fetch fixtures |
text useFrozenTimetext useRealTime | Freeze and restore timers for time-sensitive tests. Import from text plugin-sdk/test-env |
text createTestWizardPrompter | Build a mocked setup wizard prompter |
text createRuntimeTaskFlow | Create isolated runtime task-flow state |
text typedCases | Preserve literal types for table-driven tests. Import from text plugin-sdk/test-fixtures |
Bundled-plugin contract suites also use SDK testing subpaths for test-only registry, manifest, public-artifact, and runtime fixture helpers. Core-only suites that depend on bundled OpenClaw inventory stay under
src/plugins/contractsplugin-sdk/plugin-test-apiplugin-sdk/channel-contract-testingplugin-sdk/agent-runtime-test-contractsplugin-sdk/channel-test-helpersplugin-sdk/plugin-test-contractsplugin-sdk/plugin-test-runtimeplugin-sdk/provider-test-contractsplugin-sdk/provider-http-test-mocksplugin-sdk/test-envplugin-sdk/test-fixturesplugin-sdk/testingsrc/**test/helpers/*Focused testing subpaths also re-export types useful in test files:
typescriptimport type { ChannelAccountSnapshot, ChannelGatewayContext, } from "openclaw/plugin-sdk/channel-contract"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types"; import type { MockFn, PluginRuntime, RuntimeEnv } from "openclaw/plugin-sdk/plugin-test-runtime";
Use
installCommonResolveTargetErrorCasestypescriptimport { describe } from "vitest"; import { installCommonResolveTargetErrorCases } from "openclaw/plugin-sdk/channel-target-testing"; describe("my-channel target resolution", () => { installCommonResolveTargetErrorCases({ resolveTarget: ({ to, mode, allowFrom }) => { // Your channel's target resolution logic return myChannelResolveTarget({ to, mode, allowFrom }); }, implicitAllowFrom: ["user1", "user2"], }); // Add channel-specific test cases it("should resolve @username targets", () => { // ... }); });
Unit tests that pass a hand-written
apiregister(api)The real loader fails plugin registration when required metadata is missing or a plugin calls a capability API it does not own. For example,
api.registerHook(...)api.registerMemoryCapability(...)kind: "memory"Prefer the shared plugin runtime mock from
openclaw/plugin-sdk/channel-test-helpersruntime.config.loadConfig()runtime.config.writeConfigFile(...)typescriptimport { describe, it, expect, vi } from "vitest"; describe("my-channel plugin", () => { it("should resolve account from config", () => { const cfg = { channels: { "my-channel": { token: "test-token", allowFrom: ["user1"], }, }, }; const account = myPlugin.setup.resolveAccount(cfg, undefined); expect(account.token).toBe("test-token"); }); it("should inspect account without materializing secrets", () => { const cfg = { channels: { "my-channel": { token: "test-token" }, }, }; const inspection = myPlugin.setup.inspectAccount(cfg, undefined); expect(inspection.configured).toBe(true); expect(inspection.tokenStatus).toBe("available"); // No token value exposed expect(inspection).not.toHaveProperty("token"); }); });
typescriptimport { describe, it, expect } from "vitest"; describe("my-provider plugin", () => { it("should resolve dynamic models", () => { const model = myProvider.resolveDynamicModel({ modelId: "custom-model-v2", // ... context }); expect(model.id).toBe("custom-model-v2"); expect(model.provider).toBe("my-provider"); expect(model.api).toBe("openai-completions"); }); it("should return catalog when API key is available", async () => { const result = await myProvider.catalog.run({ resolveProviderApiKey: () => ({ apiKey: "test-key" }), // ... context }); expect(result?.provider?.models).toHaveLength(2); }); });
For code that uses
createPluginRuntimeStoretypescriptimport { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store"; import type { PluginRuntime } from "openclaw/plugin-sdk/runtime-store"; const store = createPluginRuntimeStore<PluginRuntime>({ pluginId: "test-plugin", errorMessage: "test runtime not set", }); // In test setup const mockRuntime = { agent: { resolveAgentDir: vi.fn().mockReturnValue("/tmp/agent"), // ... other mocks }, config: { current: vi.fn(() => ({}) as const), mutateConfigFile: vi.fn(), replaceConfigFile: vi.fn(), }, // ... other namespaces } as unknown as PluginRuntime; store.setRuntime(mockRuntime); // After tests store.clearRuntime();
Prefer per-instance stubs over prototype mutation:
typescript// Preferred: per-instance stub const client = new MyChannelClient(); client.sendMessage = vi.fn().mockResolvedValue({ id: "msg-1" }); // Avoid: prototype mutation // MyChannelClient.prototype.sendMessage = vi.fn();
Bundled plugins have contract tests that verify registration ownership:
bashpnpm test -- src/plugins/contracts/
These tests assert:
For a specific plugin:
bashpnpm test -- <bundled-plugin-root>/my-channel/
For contract tests only:
bashpnpm test -- src/plugins/contracts/shape.contract.test.ts pnpm test -- src/plugins/contracts/auth.contract.test.ts pnpm test -- src/plugins/contracts/runtime.contract.test.ts
Three rules are enforced by
pnpm checkopenclaw/plugin-sdksrc/../../src/plugin-sdk/<name>External plugins are not subject to these lint rules, but following the same patterns is recommended.
OpenClaw uses Vitest with V8 coverage thresholds. For plugin tests:
bash# Run all tests pnpm test # Run specific plugin tests pnpm test -- <bundled-plugin-root>/my-channel/src/channel.test.ts # Run with a specific test name filter pnpm test -- <bundled-plugin-root>/my-channel/ -t "resolves account" # Run with coverage pnpm test:coverage
If local runs cause memory pressure:
bashOPENCLAW_VITEST_MAX_WORKERS=1 pnpm test
© 2024 TaskFlow Mirror
Powered by TaskFlow Sync Engine