test(plugin-sdk): use narrow config runtime mocks · openclaw/openclaw@9090457
steipete
·
2026-04-27
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -145,8 +145,10 @@ releases.
|
145 | 145 | | Secret input resolution | `openclaw/plugin-sdk/secret-input-runtime` | |
146 | 146 | | Model/session overrides | `openclaw/plugin-sdk/model-session-runtime` | |
147 | 147 | |
148 | | -Bundled production plugins are scanner-guarded against the broad barrel so |
149 | | -imports stay local to the behavior they need. |
| 148 | +Bundled plugins and their tests are scanner-guarded against the broad |
| 149 | +barrel so imports and mocks stay local to the behavior they need. The broad |
| 150 | +barrel still exists for external compatibility, but new code should not |
| 151 | +depend on it. |
150 | 152 | |
151 | 153 | </Step> |
152 | 154 | |
@@ -233,6 +235,7 @@ releases.
|
233 | 235 | |
234 | 236 | ```bash |
235 | 237 | grep -r "plugin-sdk/compat" my-plugin/ |
| 238 | +grep -r "plugin-sdk/config-runtime" my-plugin/ |
236 | 239 | grep -r "openclaw/extension-api" my-plugin/ |
237 | 240 | ``` |
238 | 241 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -41,13 +41,14 @@ Persist changes with `api.runtime.config.mutateConfigFile(...)` or `api.runtime.
|
41 | 41 | |
42 | 42 | The mutation helpers return `afterWrite` plus a typed `followUp` summary so callers can log or test whether they requested a restart. The gateway still owns when that restart actually happens. |
43 | 43 | |
44 | | -`api.runtime.config.loadConfig()` and `api.runtime.config.writeConfigFile(...)` are deprecated compatibility helpers under `runtime-config-load-write`. They warn once at runtime, and bundled plugins must not use them; the config boundary guards fail if production plugin code calls them or imports those helpers from plugin SDK subpaths. |
| 44 | +`api.runtime.config.loadConfig()` and `api.runtime.config.writeConfigFile(...)` are deprecated compatibility helpers under `runtime-config-load-write`. They warn once at runtime, and remain available for old external plugins during the migration window. Bundled plugins must not use them; the config boundary guards fail if plugin code calls them or imports those helpers from plugin SDK subpaths. |
45 | 45 | |
46 | 46 | For direct SDK imports, use the focused config subpaths instead of the broad |
47 | 47 | `openclaw/plugin-sdk/config-runtime` compatibility barrel: `config-types` for |
48 | 48 | types, `plugin-config-runtime` for already-loaded config assertions and plugin |
49 | 49 | entry lookup, `runtime-config-snapshot` for current process snapshots, and |
50 | | -`config-mutation` for writes. |
| 50 | +`config-mutation` for writes. Bundled plugin tests should mock these focused |
| 51 | +subpaths directly instead of mocking the broad compatibility barrel. |
51 | 52 | |
52 | 53 | Internal OpenClaw runtime code has the same direction: load config once at the CLI, gateway, or process boundary, then pass that value through. Successful mutation writes refresh the process runtime snapshot and advance its internal revision; long-lived caches should key off the runtime-owned cache key instead of serializing config locally. Long-lived runtime modules have a zero-tolerance scanner for ambient `loadConfig()` calls; use a passed `cfg`, a request `context.getRuntimeConfig()`, or `getRuntimeConfig()` at an explicit process boundary. |
53 | 54 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -26,9 +26,9 @@ const hoisted = vi.hoisted(() => {
|
26 | 26 | }; |
27 | 27 | }); |
28 | 28 | |
29 | | -vi.mock("openclaw/plugin-sdk/config-runtime", async () => { |
30 | | -const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/config-runtime")>( |
31 | | -"openclaw/plugin-sdk/config-runtime", |
| 29 | +vi.mock("openclaw/plugin-sdk/session-store-runtime", async () => { |
| 30 | +const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/session-store-runtime")>( |
| 31 | +"openclaw/plugin-sdk/session-store-runtime", |
32 | 32 | ); |
33 | 33 | return { |
34 | 34 | ...actual, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -136,10 +136,10 @@ const configMocks = vi.hoisted(() => ({
|
136 | 136 | } |
137 | 137 | >(() => ({ browser: {} })), |
138 | 138 | })); |
139 | | -vi.mock("openclaw/plugin-sdk/config-runtime", async () => { |
140 | | -const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/config-runtime")>( |
141 | | -"openclaw/plugin-sdk/config-runtime", |
142 | | -); |
| 139 | +vi.mock("openclaw/plugin-sdk/runtime-config-snapshot", async () => { |
| 140 | +const actual = await vi.importActual< |
| 141 | +typeof import("openclaw/plugin-sdk/runtime-config-snapshot") |
| 142 | +>("openclaw/plugin-sdk/runtime-config-snapshot"); |
143 | 143 | return { |
144 | 144 | ...actual, |
145 | 145 | getRuntimeConfig: configMocks.loadConfig, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -8,10 +8,10 @@ const { loadConfigMock, isNodeCommandAllowedMock, resolveNodeCommandAllowlistMoc
|
8 | 8 | }), |
9 | 9 | ); |
10 | 10 | |
11 | | -vi.mock("openclaw/plugin-sdk/config-runtime", async () => { |
12 | | -const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/config-runtime")>( |
13 | | -"openclaw/plugin-sdk/config-runtime", |
14 | | -); |
| 11 | +vi.mock("openclaw/plugin-sdk/runtime-config-snapshot", async () => { |
| 12 | +const actual = await vi.importActual< |
| 13 | +typeof import("openclaw/plugin-sdk/runtime-config-snapshot") |
| 14 | +>("openclaw/plugin-sdk/runtime-config-snapshot"); |
15 | 15 | return { |
16 | 16 | ...actual, |
17 | 17 | loadConfig: loadConfigMock, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,10 +3,10 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
3 | 3 | |
4 | 4 | const loadConfigMock = vi.hoisted(() => vi.fn()); |
5 | 5 | |
6 | | -vi.mock("openclaw/plugin-sdk/config-runtime", async () => { |
7 | | -const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/config-runtime")>( |
8 | | -"openclaw/plugin-sdk/config-runtime", |
9 | | -); |
| 6 | +vi.mock("openclaw/plugin-sdk/runtime-config-snapshot", async () => { |
| 7 | +const actual = await vi.importActual< |
| 8 | +typeof import("openclaw/plugin-sdk/runtime-config-snapshot") |
| 9 | +>("openclaw/plugin-sdk/runtime-config-snapshot"); |
10 | 10 | return { |
11 | 11 | ...actual, |
12 | 12 | getRuntimeConfig: () => loadConfigMock(), |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -24,7 +24,7 @@ vi.mock("@buape/carbon/voice", () => ({
|
24 | 24 | }, |
25 | 25 | })); |
26 | 26 | |
27 | | -vi.mock("openclaw/plugin-sdk/config-runtime", () => ({ |
| 27 | +vi.mock("openclaw/plugin-sdk/dangerous-name-runtime", () => ({ |
28 | 28 | isDangerousNameMatchingEnabled: () => false, |
29 | 29 | })); |
30 | 30 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,9 +6,9 @@ const hoisted = vi.hoisted(() => {
|
6 | 6 | return { updateSessionStore, resolveStorePath }; |
7 | 7 | }); |
8 | 8 | |
9 | | -vi.mock("openclaw/plugin-sdk/config-runtime", async () => { |
10 | | -const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/config-runtime")>( |
11 | | -"openclaw/plugin-sdk/config-runtime", |
| 9 | +vi.mock("openclaw/plugin-sdk/session-store-runtime", async () => { |
| 10 | +const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/session-store-runtime")>( |
| 11 | +"openclaw/plugin-sdk/session-store-runtime", |
12 | 12 | ); |
13 | 13 | return { |
14 | 14 | ...actual, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -15,9 +15,9 @@ const DISCORD_TEST_CFG = {
|
15 | 15 | session: { dmScope: "main" }, |
16 | 16 | } as const; |
17 | 17 | |
18 | | -vi.mock("openclaw/plugin-sdk/config-runtime", async () => { |
19 | | -const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/config-runtime")>( |
20 | | -"openclaw/plugin-sdk/config-runtime", |
| 18 | +vi.mock("openclaw/plugin-sdk/plugin-config-runtime", async () => { |
| 19 | +const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/plugin-config-runtime")>( |
| 20 | +"openclaw/plugin-sdk/plugin-config-runtime", |
21 | 21 | ); |
22 | 22 | return { |
23 | 23 | ...actual, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,13 +3,13 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
|
3 | 3 | const recordChannelActivityMock = vi.hoisted(() => vi.fn()); |
4 | 4 | const loadConfigMock = vi.hoisted(() => vi.fn(() => ({ channels: { discord: {} } }))); |
5 | 5 | |
6 | | -vi.mock("openclaw/plugin-sdk/config-runtime", async () => { |
7 | | -const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/config-runtime")>( |
8 | | -"openclaw/plugin-sdk/config-runtime", |
| 6 | +vi.mock("openclaw/plugin-sdk/plugin-config-runtime", async () => { |
| 7 | +const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/plugin-config-runtime")>( |
| 8 | +"openclaw/plugin-sdk/plugin-config-runtime", |
9 | 9 | ); |
10 | 10 | return { |
11 | 11 | ...actual, |
12 | | -loadConfig: () => loadConfigMock(), |
| 12 | +requireRuntimeConfig: (cfg: unknown) => cfg ?? loadConfigMock(), |
13 | 13 | }; |
14 | 14 | }); |
15 | 15 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。