Skip to content

Commit 90b6665

Browse files
committed
refactor: move plugin api test helper to sdk
1 parent f71f5bc commit 90b6665

45 files changed

Lines changed: 120 additions & 82 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Docs: https://docs.openclaw.ai
1313
- Channels/QQBot: add full group chat support (history tracking, @-mention gating, activation modes, per-group config, FIFO message queue with deliver debounce), C2C `stream_messages` streaming with a `StreamingController` lifecycle manager, unified `sendMedia` with chunked upload for large files, and refactor the engine into pipeline stages, focused outbound submodules, builtin slash-command modules, and explicit DI ports via `createEngineAdapters()`. (#70624) Thanks @cxyhhhhh.
1414
- Gateway/runtime: reuse the current plugin metadata snapshot for provider discovery so repeated model-provider discovery avoids rebuilding plugin manifest metadata. Thanks @shakkernerd.
1515
- Gateway/startup: pass the plugin metadata snapshot from config validation into plugin bootstrap so startup reuses one manifest product instead of rebuilding plugin metadata. Thanks @shakkernerd.
16+
- Plugin SDK/testing: add a focused `plugin-sdk/plugin-test-api` helper subpath and move bundled plugin registration tests off the repo-only plugin API bridge. Thanks @vincentkoc.
1617
- Plugin SDK/testing: expose provider catalog, wizard, registry, manifest, public-artifact, outbound, and TTS contract helpers through documented SDK testing seams so bundled plugin tests no longer import repo `src/**` internals. Thanks @vincentkoc.
1718
- Matrix: attach versioned structured approval metadata to pending approval messages so capable Matrix clients can render richer approval UI while body text and reaction fallback keep working. (#72432) Thanks @kakahu2015.
1819

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
7a2039df8cfdcfea0fbc82bbe425c96631ab27b2210c932c6e3f17d380aff350 plugin-sdk-api-baseline.json
2-
ea9f134bc2a1aa17e8abf8f1335daaa927b2272c972523b9d0bd05bf4ac8e149 plugin-sdk-api-baseline.jsonl
1+
0736a1666860383e3e5f8ada181c016455d8304a2852ac6966355765f799add4 plugin-sdk-api-baseline.json
2+
761cdb609547f5912513e5714d8b0ec8fff2b29905690af376cc5bdd74f2c279 plugin-sdk-api-baseline.jsonl

docs/plugins/sdk-subpaths.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ For the plugin authoring guide, see [Plugin SDK overview](/plugins/sdk-overview)
2323
| `plugin-sdk/config-schema` | `OpenClawSchema` |
2424
| `plugin-sdk/provider-entry` | `defineSingleProviderPluginEntry` |
2525
| `plugin-sdk/testing` | Public plugin test fixtures, provider registration/catalog helpers, wizard contract hooks, and bundled-plugin contract maintenance helpers |
26+
| `plugin-sdk/plugin-test-api` | Minimal `OpenClawPluginApi` mock builder for direct plugin registration unit tests |
2627
| `plugin-sdk/migration` | Migration provider item helpers such as `createMigrationItem`, reason constants, item status markers, redaction helpers, and `summarizeMigrationItems` |
2728
| `plugin-sdk/migration-runtime` | Runtime migration helpers such as `copyMigrationFileItem` and `writeMigrationReport` |
2829

@@ -260,6 +261,7 @@ For the plugin authoring guide, see [Plugin SDK overview](/plugins/sdk-overview)
260261
| `plugin-sdk/web-media` | Shared remote/local media loading helpers |
261262
| `plugin-sdk/zod` | Re-exported `zod` for plugin SDK consumers |
262263
| `plugin-sdk/testing` | Public extension test helpers including plugin registry/runtime mocks, provider registration capture, setup-wizard helpers, fetch/env/temp/time fixtures, schema/media/live-test helpers, `installCommonResolveTargetErrorCases`, `writeSkill`, `createTestRegistry`, and live generation env loading. Extension `*.test-support.ts` helpers stay on this or focused SDK subpaths, not core internals |
264+
| `plugin-sdk/plugin-test-api` | Minimal `createTestPluginApi` helper for direct plugin registration unit tests without importing repo test helper bridges |
263265
</Accordion>
264266

265267
<Accordion title="Memory subpaths">

docs/plugins/sdk-testing.md

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ plugins.
1919

2020
## Test utilities
2121

22-
**Import:** `openclaw/plugin-sdk/testing`
22+
**General import:** `openclaw/plugin-sdk/testing`
23+
24+
**Plugin API mock import:** `openclaw/plugin-sdk/plugin-test-api`
25+
26+
**Channel contract import:** `openclaw/plugin-sdk/channel-contract-testing`
2327

2428
The testing subpath exports a narrow set of helpers for plugin authors:
2529

@@ -29,44 +33,51 @@ import {
2933
shouldAckReaction,
3034
removeAckReactionAfterReply,
3135
} from "openclaw/plugin-sdk/testing";
36+
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
37+
import { expectChannelInboundContextContract } from "openclaw/plugin-sdk/channel-contract-testing";
3238
```
3339

3440
### Available exports
3541

36-
| Export | Purpose |
37-
| ------------------------------------------- | ------------------------------------------------------- |
38-
| `installCommonResolveTargetErrorCases` | Shared test cases for target resolution error handling |
39-
| `shouldAckReaction` | Check whether a channel should add an ack reaction |
40-
| `removeAckReactionAfterReply` | Remove ack reaction after reply delivery |
41-
| `createTestRegistry` | Build a channel plugin registry fixture |
42-
| `createEmptyPluginRegistry` | Build an empty plugin registry fixture |
43-
| `setActivePluginRegistry` | Install a registry fixture for plugin runtime tests |
44-
| `createRequestCaptureJsonFetch` | Capture JSON fetch requests in media helper tests |
45-
| `withFetchPreconnect` | Run fetch tests with preconnect hooks installed |
46-
| `withEnv` / `withEnvAsync` | Temporarily patch environment variables |
47-
| `createTempHomeEnv` / `withTempDir` | Create isolated filesystem test fixtures |
48-
| `createMockServerResponse` | Create a minimal HTTP server response mock |
49-
| `registerSingleProviderPlugin` | Register one provider plugin in loader smoke tests |
50-
| `registerProviderPlugin` | Capture all provider kinds from one plugin |
51-
| `registerProviderPlugins` | Capture provider registrations across multiple plugins |
52-
| `requireRegisteredProvider` | Assert that a provider collection contains an id |
53-
| `runProviderCatalog` | Execute a provider catalog hook with test dependencies |
54-
| `resolveProviderWizardOptions` | Resolve provider setup wizard choices in contract tests |
55-
| `resolveProviderModelPickerEntries` | Resolve provider model-picker entries in contract tests |
56-
| `buildProviderPluginMethodChoice` | Build provider wizard choice ids for assertions |
57-
| `setProviderWizardProvidersResolverForTest` | Inject provider wizard providers for isolated tests |
58-
| `createProviderUsageFetch` | Build provider usage fetch fixtures |
59-
| `useFrozenTime` / `useRealTime` | Freeze and restore timers for time-sensitive tests |
60-
| `createRuntimeEnv` | Build a mocked CLI/plugin runtime environment |
61-
| `createTestWizardPrompter` | Build a mocked setup wizard prompter |
62-
| `createPluginSetupWizardStatus` | Build setup status helpers for channel plugins |
63-
| `createRuntimeTaskFlow` | Create isolated runtime task-flow state |
64-
| `typedCases` | Preserve literal types for table-driven tests |
65-
66-
Bundled-plugin contract suites also use this subpath for test-only registry,
67-
manifest, public-artifact, and runtime fixture helpers. Keep new extension tests
68-
on `openclaw/plugin-sdk/testing` or a narrower documented SDK subpath rather
69-
than importing repo `src/**` files directly.
42+
| Export | Purpose |
43+
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
44+
| `createTestPluginApi` | Build a minimal plugin API mock for direct registration unit tests. Import from `plugin-sdk/plugin-test-api` |
45+
| `expectChannelInboundContextContract` | Assert channel inbound context shape. Import from `plugin-sdk/channel-contract-testing` |
46+
| `installChannelOutboundPayloadContractSuite` | Install channel outbound payload contract cases. Import from `plugin-sdk/channel-contract-testing` |
47+
| `installCommonResolveTargetErrorCases` | Shared test cases for target resolution error handling |
48+
| `shouldAckReaction` | Check whether a channel should add an ack reaction |
49+
| `removeAckReactionAfterReply` | Remove ack reaction after reply delivery |
50+
| `createTestRegistry` | Build a channel plugin registry fixture |
51+
| `createEmptyPluginRegistry` | Build an empty plugin registry fixture |
52+
| `setActivePluginRegistry` | Install a registry fixture for plugin runtime tests |
53+
| `createRequestCaptureJsonFetch` | Capture JSON fetch requests in media helper tests |
54+
| `withFetchPreconnect` | Run fetch tests with preconnect hooks installed |
55+
| `withEnv` / `withEnvAsync` | Temporarily patch environment variables |
56+
| `createTempHomeEnv` / `withTempDir` | Create isolated filesystem test fixtures |
57+
| `createMockServerResponse` | Create a minimal HTTP server response mock |
58+
| `registerSingleProviderPlugin` | Register one provider plugin in loader smoke tests |
59+
| `registerProviderPlugin` | Capture all provider kinds from one plugin |
60+
| `registerProviderPlugins` | Capture provider registrations across multiple plugins |
61+
| `requireRegisteredProvider` | Assert that a provider collection contains an id |
62+
| `runProviderCatalog` | Execute a provider catalog hook with test dependencies |
63+
| `resolveProviderWizardOptions` | Resolve provider setup wizard choices in contract tests |
64+
| `resolveProviderModelPickerEntries` | Resolve provider model-picker entries in contract tests |
65+
| `buildProviderPluginMethodChoice` | Build provider wizard choice ids for assertions |
66+
| `setProviderWizardProvidersResolverForTest` | Inject provider wizard providers for isolated tests |
67+
| `createProviderUsageFetch` | Build provider usage fetch fixtures |
68+
| `useFrozenTime` / `useRealTime` | Freeze and restore timers for time-sensitive tests |
69+
| `createRuntimeEnv` | Build a mocked CLI/plugin runtime environment |
70+
| `createTestWizardPrompter` | Build a mocked setup wizard prompter |
71+
| `createPluginSetupWizardStatus` | Build setup status helpers for channel plugins |
72+
| `createRuntimeTaskFlow` | Create isolated runtime task-flow state |
73+
| `typedCases` | Preserve literal types for table-driven tests |
74+
75+
Bundled-plugin contract suites also use SDK testing subpaths for test-only
76+
registry, manifest, public-artifact, and runtime fixture helpers. Keep new
77+
extension tests on `openclaw/plugin-sdk/testing` or a narrower documented SDK
78+
subpath such as `plugin-sdk/plugin-test-api` or
79+
`plugin-sdk/channel-contract-testing` rather than importing repo `src/**` files
80+
directly.
7081

7182
### Types
7283

extensions/acpx/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
2+
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
23
import { beforeEach, describe, expect, it, vi } from "vitest";
3-
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
44
import setupPlugin from "./setup-api.js";
55

66
const { createAcpxRuntimeServiceMock, tryDispatchAcpReplyHookMock } = vi.hoisted(() => ({

extensions/browser/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "node:fs";
22
import path from "node:path";
3+
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
34
import { describe, expect, it, vi } from "vitest";
4-
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
55
import {
66
browserPluginNodeHostCommands,
77
browserPluginReload,

extensions/codex/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from "node:fs";
2+
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
23
import { describe, expect, it, vi } from "vitest";
3-
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
44
import { createCodexAppServerAgentHarness } from "./harness.js";
55
import plugin from "./index.js";
66

extensions/comfy/comfy.live.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { resolveOpenClawAgentDir } from "openclaw/plugin-sdk/agent-runtime";
22
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
3+
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
34
import { getRuntimeConfig } from "openclaw/plugin-sdk/runtime-config-snapshot";
45
import { isLiveTestEnabled } from "openclaw/plugin-sdk/testing";
56
import { beforeAll, describe, expect, it } from "vitest";
6-
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
77
import plugin from "./index.js";
88
import { getComfyConfig, isComfyCapabilityConfigured } from "./workflow-runtime.js";
99

extensions/device-pair/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type {
55
OpenClawPluginCommandDefinition,
66
PluginCommandContext,
77
} from "openclaw/plugin-sdk/core";
8+
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
89
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
9-
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
1010
import type { OpenClawPluginApi } from "./api.js";
1111
import type { PendingPairingRequest } from "./notify.ts";
1212

extensions/device-pair/notify.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import fs from "node:fs/promises";
22
import os from "node:os";
33
import path from "node:path";
4+
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
45
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5-
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
66

77
const listDevicePairingMock = vi.hoisted(() => vi.fn(async () => ({ pending: [] })));
88

0 commit comments

Comments
 (0)