


























@@ -12,16 +12,6 @@ vi.mock("../plugins/setup-registry.js", () => ({
1212}),
1313}));
141415-function asLegacyConfig(value: unknown): OpenClawConfig {
16-return value as OpenClawConfig;
17-}
18-19-function getLegacyProperty(value: unknown, key: string): unknown {
20-if (!value || typeof value !== "object") {
21-return undefined;
22-}
23-return (value as Record<string, unknown>)[key];
24-}
2515describe("normalizeCompatibilityConfigValues", () => {
2616let previousOauthDir: string | undefined;
2717let tempOauthDir = "";
@@ -90,201 +80,6 @@ describe("normalizeCompatibilityConfigValues", () => {
9080});
9181});
928293-it("migrates Slack dm.policy/dm.allowFrom to dmPolicy/allowFrom aliases", () => {
94-const res = normalizeCompatibilityConfigValues({
95-channels: {
96-slack: {
97-dm: { enabled: true, policy: "open", allowFrom: ["*"] },
98-},
99-},
100-});
101-102-expect(res.config.channels?.slack?.dmPolicy).toBe("open");
103-expect(res.config.channels?.slack?.allowFrom).toEqual(["*"]);
104-expect(res.config.channels?.slack?.dm).toEqual({
105-enabled: true,
106-});
107-expect(res.changes).toEqual([
108-"Moved channels.slack.dm.policy → channels.slack.dmPolicy.",
109-"Moved channels.slack.dm.allowFrom → channels.slack.allowFrom.",
110-]);
111-});
112-113-it("migrates Discord account dm.policy/dm.allowFrom to dmPolicy/allowFrom aliases", () => {
114-const res = normalizeCompatibilityConfigValues({
115-channels: {
116-discord: {
117-accounts: {
118-work: {
119-dm: { policy: "allowlist", allowFrom: ["123"], groupEnabled: true },
120-},
121-},
122-},
123-},
124-});
125-126-expect(res.config.channels?.discord?.accounts?.work?.dmPolicy).toBe("allowlist");
127-expect(res.config.channels?.discord?.accounts?.work?.allowFrom).toEqual(["123"]);
128-expect(res.config.channels?.discord?.accounts?.work?.dm).toEqual({
129-groupEnabled: true,
130-});
131-expect(res.changes).toEqual([
132-"Moved channels.discord.accounts.work.dm.policy → channels.discord.accounts.work.dmPolicy.",
133-"Moved channels.discord.accounts.work.dm.allowFrom → channels.discord.accounts.work.allowFrom.",
134-]);
135-});
136-137-it("migrates Discord streaming boolean alias into nested streaming.mode", () => {
138-const res = normalizeCompatibilityConfigValues(
139-asLegacyConfig({
140-channels: {
141-discord: {
142-streaming: true,
143-accounts: {
144-work: {
145-streaming: false,
146-},
147-},
148-},
149-},
150-}),
151-);
152-153-expect(res.config.channels?.discord?.streaming).toEqual({ mode: "partial" });
154-expect(getLegacyProperty(res.config.channels?.discord, "streamMode")).toBeUndefined();
155-expect(res.config.channels?.discord?.accounts?.work?.streaming).toEqual({ mode: "off" });
156-expect(
157-getLegacyProperty(res.config.channels?.discord?.accounts?.work, "streamMode"),
158-).toBeUndefined();
159-expect(res.changes).toEqual([
160-"Moved channels.discord.streaming (boolean) → channels.discord.streaming.mode (partial).",
161-"Moved channels.discord.accounts.work.streaming (boolean) → channels.discord.accounts.work.streaming.mode (off).",
162-]);
163-});
164-165-it("migrates Discord legacy streamMode into nested streaming.mode", () => {
166-const res = normalizeCompatibilityConfigValues(
167-asLegacyConfig({
168-channels: {
169-discord: {
170-streaming: false,
171-streamMode: "block",
172-},
173-},
174-}),
175-);
176-177-expect(res.config.channels?.discord?.streaming).toEqual({ mode: "block" });
178-expect(getLegacyProperty(res.config.channels?.discord, "streamMode")).toBeUndefined();
179-expect(res.changes).toEqual([
180-"Moved channels.discord.streamMode → channels.discord.streaming.mode (block).",
181-]);
182-});
183-184-it("migrates Telegram streamMode into nested streaming.mode", () => {
185-const res = normalizeCompatibilityConfigValues(
186-asLegacyConfig({
187-channels: {
188-telegram: {
189-streamMode: "block",
190-},
191-},
192-}),
193-);
194-195-expect(res.config.channels?.telegram?.streaming).toEqual({ mode: "block" });
196-expect(getLegacyProperty(res.config.channels?.telegram, "streamMode")).toBeUndefined();
197-expect(res.changes).toEqual([
198-"Moved channels.telegram.streamMode → channels.telegram.streaming.mode (block).",
199-]);
200-});
201-202-it("migrates Slack legacy streaming keys into nested streaming config", () => {
203-const res = normalizeCompatibilityConfigValues(
204-asLegacyConfig({
205-channels: {
206-slack: {
207-streaming: false,
208-streamMode: "status_final",
209-},
210-},
211-}),
212-);
213-214-expect(res.config.channels?.slack?.streaming).toEqual({
215-mode: "progress",
216-nativeTransport: false,
217-});
218-expect(getLegacyProperty(res.config.channels?.slack, "streamMode")).toBeUndefined();
219-expect(res.changes).toEqual([
220-"Moved channels.slack.streamMode → channels.slack.streaming.mode (progress).",
221-"Moved channels.slack.streaming (boolean) → channels.slack.streaming.nativeTransport.",
222-]);
223-});
224-225-it("preserves top-level Telegram allowlist fallback for existing named accounts", () => {
226-const res = normalizeCompatibilityConfigValues({
227-channels: {
228-telegram: {
229-enabled: true,
230-dmPolicy: "allowlist",
231-allowFrom: ["123"],
232-groupPolicy: "allowlist",
233-accounts: {
234-bot1: {
235-enabled: true,
236-botToken: "bot-1-token",
237-},
238-bot2: {
239-enabled: true,
240-botToken: "bot-2-token",
241-},
242-},
243-},
244-},
245-});
246-247-expect(res.config.channels?.telegram?.dmPolicy).toBe("allowlist");
248-expect(res.config.channels?.telegram?.allowFrom).toEqual(["123"]);
249-expect(res.config.channels?.telegram?.groupPolicy).toBe("allowlist");
250-expect(res.config.channels?.telegram?.accounts?.bot1?.botToken).toBe("bot-1-token");
251-expect(res.config.channels?.telegram?.accounts?.bot2?.botToken).toBe("bot-2-token");
252-expect(res.changes).not.toContain(
253-"Moved channels.telegram single-account top-level values into channels.telegram.accounts.default.",
254-);
255-});
256-257-it("keeps Telegram policy fallback top-level while still seeding default auth", () => {
258-const res = normalizeCompatibilityConfigValues({
259-channels: {
260-telegram: {
261-enabled: true,
262-botToken: "legacy-token",
263-dmPolicy: "allowlist",
264-allowFrom: ["123"],
265-groupPolicy: "allowlist",
266-accounts: {
267-bot1: {
268-enabled: true,
269-botToken: "bot-1-token",
270-},
271-},
272-},
273-},
274-});
275-276-expect(res.config.channels?.telegram?.accounts?.default).toMatchObject({
277-botToken: "legacy-token",
278-});
279-expect(res.config.channels?.telegram?.botToken).toBeUndefined();
280-expect(res.config.channels?.telegram?.dmPolicy).toBe("allowlist");
281-expect(res.config.channels?.telegram?.allowFrom).toEqual(["123"]);
282-expect(res.config.channels?.telegram?.groupPolicy).toBe("allowlist");
283-expect(res.changes).toContain(
284-"Moved channels.telegram single-account top-level values into channels.telegram.accounts.default.",
285-);
286-});
287-28883it("migrates browser ssrfPolicy allowPrivateNetwork to dangerouslyAllowPrivateNetwork", () => {
28984const res = normalizeCompatibilityConfigValues({
29085browser: {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。