Skip to content

Commit cb11e02

Browse files
committed
refactor(config): split channel schema imports
Signed-off-by: samzong <samzong.lu@gmail.com>
1 parent 346a773 commit cb11e02

4 files changed

Lines changed: 50 additions & 9 deletions

File tree

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import type { ChannelsConfig } from "./types.channels.js";
33
import { ChannelHeartbeatVisibilitySchema } from "./zod-schema.channels.js";
44
import { ContextVisibilityModeSchema, GroupPolicySchema } from "./zod-schema.core.js";
55

6-
export * from "./zod-schema.providers-core.js";
7-
export * from "./zod-schema.providers-whatsapp.js";
8-
export { ChannelHeartbeatVisibilitySchema } from "./zod-schema.channels.js";
9-
106
const ChannelModelByChannelSchema = z
117
.record(z.string(), z.record(z.string(), z.string()))
128
.optional();

src/config/zod-schema.providers.lazy-runtime.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe("ChannelsSchema bundled runtime loading", () => {
1717
});
1818

1919
it("skips bundled channel runtime discovery when only core channel keys are present", async () => {
20-
const runtime = await importFreshModule<typeof import("./zod-schema.providers.js")>(
20+
const runtime = await importFreshModule<typeof import("./zod-schema.channels-config.js")>(
2121
import.meta.url,
22-
"./zod-schema.providers.js?scope=channels-core-only",
22+
"./zod-schema.channels-config.js?scope=channels-core-only",
2323
);
2424

2525
const parsed = runtime.ChannelsSchema.parse({
@@ -45,9 +45,9 @@ describe("ChannelsSchema bundled runtime loading", () => {
4545
});
4646

4747
it("does not discover bundled channel runtime metadata during raw schema parsing", async () => {
48-
const runtime = await importFreshModule<typeof import("./zod-schema.providers.js")>(
48+
const runtime = await importFreshModule<typeof import("./zod-schema.channels-config.js")>(
4949
import.meta.url,
50-
"./zod-schema.providers.js?scope=channels-plugin-owned",
50+
"./zod-schema.channels-config.js?scope=channels-plugin-owned",
5151
);
5252

5353
runtime.ChannelsSchema.parse({
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures";
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
3+
4+
const providersWhatsappImportMock = vi.hoisted(() => vi.fn());
5+
const providersCoreImportMock = vi.hoisted(() => vi.fn());
6+
7+
describe("OpenClawSchema startup imports", () => {
8+
beforeEach(() => {
9+
providersWhatsappImportMock.mockClear();
10+
providersCoreImportMock.mockClear();
11+
vi.doMock("./zod-schema.providers-core.js", () => {
12+
providersCoreImportMock();
13+
return {};
14+
});
15+
vi.doMock("./zod-schema.providers-whatsapp.js", () => {
16+
providersWhatsappImportMock();
17+
return {};
18+
});
19+
});
20+
21+
it("does not load provider-specific channel schemas for generic channel validation", async () => {
22+
const runtime = await importFreshModule<typeof import("./zod-schema.js")>(
23+
import.meta.url,
24+
"./zod-schema.js?scope=startup-generic-channels",
25+
);
26+
27+
const parsed = runtime.OpenClawSchema.safeParse({
28+
channels: {
29+
defaults: {
30+
groupPolicy: "open",
31+
botLoopProtection: {
32+
maxEventsPerWindow: 4,
33+
windowSeconds: 90,
34+
cooldownSeconds: 30,
35+
},
36+
},
37+
discord: {},
38+
},
39+
});
40+
41+
expect(parsed.success).toBe(true);
42+
expect(providersCoreImportMock).not.toHaveBeenCalled();
43+
expect(providersWhatsappImportMock).not.toHaveBeenCalled();
44+
});
45+
});

src/config/zod-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import {
1616
import { ToolsSchema } from "./zod-schema.agent-runtime.js";
1717
import { AgentsSchema, AudioSchema, BindingsSchema, BroadcastSchema } from "./zod-schema.agents.js";
1818
import { ApprovalsSchema } from "./zod-schema.approvals.js";
19+
import { ChannelsSchema } from "./zod-schema.channels-config.js";
1920
import {
2021
HexColorSchema,
2122
ModelsConfigSchema,
2223
SecretInputSchema,
2324
SecretsConfigSchema,
2425
} from "./zod-schema.core.js";
2526
import { HookMappingSchema, HooksGmailSchema, InternalHooksSchema } from "./zod-schema.hooks.js";
26-
import { ChannelsSchema } from "./zod-schema.providers.js";
2727
import { ProxyConfigSchema } from "./zod-schema.proxy.js";
2828
import { sensitive } from "./zod-schema.sensitive.js";
2929
import {

0 commit comments

Comments
 (0)