mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 23:50:22 +00:00
test: narrow doctor legacy config aliases
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { normalizeLegacyStreamingAliases } from "../config/channel-compat-normalization.js";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import { normalizeCompatibilityConfigValues } from "./doctor-legacy-config.js";
|
import { normalizeLegacyBrowserConfig } from "./doctor/shared/legacy-config-core-normalizers.js";
|
||||||
|
|
||||||
function asLegacyConfig(value: unknown): OpenClawConfig {
|
function asLegacyConfig(value: unknown): OpenClawConfig {
|
||||||
return value as OpenClawConfig;
|
return value as OpenClawConfig;
|
||||||
@@ -12,74 +13,77 @@ function getLegacyProperty(value: unknown, key: string): unknown {
|
|||||||
}
|
}
|
||||||
return (value as Record<string, unknown>)[key];
|
return (value as Record<string, unknown>)[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeStreaming(params: {
|
||||||
|
entry: Record<string, unknown>;
|
||||||
|
pathPrefix: string;
|
||||||
|
resolvedMode: string;
|
||||||
|
resolvedNativeTransport?: unknown;
|
||||||
|
offModeLegacyNotice?: (pathPrefix: string) => string;
|
||||||
|
}) {
|
||||||
|
const changes: string[] = [];
|
||||||
|
const result = normalizeLegacyStreamingAliases({
|
||||||
|
...params,
|
||||||
|
changes,
|
||||||
|
includePreviewChunk: true,
|
||||||
|
});
|
||||||
|
return { entry: result.entry, changes };
|
||||||
|
}
|
||||||
|
|
||||||
describe("normalizeCompatibilityConfigValues preview streaming aliases", () => {
|
describe("normalizeCompatibilityConfigValues preview streaming aliases", () => {
|
||||||
it("preserves telegram boolean streaming aliases as-is", () => {
|
it("preserves telegram boolean streaming aliases as-is", () => {
|
||||||
const res = normalizeCompatibilityConfigValues(
|
const res = normalizeStreaming({
|
||||||
asLegacyConfig({
|
entry: { streaming: false },
|
||||||
channels: {
|
pathPrefix: "channels.telegram",
|
||||||
telegram: {
|
resolvedMode: "off",
|
||||||
streaming: false,
|
});
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(res.config.channels?.telegram?.streaming).toEqual({ mode: "off" });
|
expect(res.entry.streaming).toEqual({ mode: "off" });
|
||||||
expect(getLegacyProperty(res.config.channels?.telegram, "streamMode")).toBeUndefined();
|
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
|
||||||
expect(res.changes).toEqual([
|
expect(res.changes).toEqual([
|
||||||
"Moved channels.telegram.streaming (boolean) → channels.telegram.streaming.mode (off).",
|
"Moved channels.telegram.streaming (boolean) → channels.telegram.streaming.mode (off).",
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("preserves discord boolean streaming aliases as-is", () => {
|
it("preserves discord boolean streaming aliases as-is", () => {
|
||||||
const res = normalizeCompatibilityConfigValues(
|
const res = normalizeStreaming({
|
||||||
asLegacyConfig({
|
entry: { streaming: true },
|
||||||
channels: {
|
pathPrefix: "channels.discord",
|
||||||
discord: {
|
resolvedMode: "partial",
|
||||||
streaming: true,
|
});
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(res.config.channels?.discord?.streaming).toEqual({ mode: "partial" });
|
expect(res.entry.streaming).toEqual({ mode: "partial" });
|
||||||
expect(getLegacyProperty(res.config.channels?.discord, "streamMode")).toBeUndefined();
|
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
|
||||||
expect(res.changes).toEqual([
|
expect(res.changes).toEqual([
|
||||||
"Moved channels.discord.streaming (boolean) → channels.discord.streaming.mode (partial).",
|
"Moved channels.discord.streaming (boolean) → channels.discord.streaming.mode (partial).",
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("preserves explicit discord streaming=false as-is", () => {
|
it("preserves explicit discord streaming=false as-is", () => {
|
||||||
const res = normalizeCompatibilityConfigValues(
|
const res = normalizeStreaming({
|
||||||
asLegacyConfig({
|
entry: { streaming: false },
|
||||||
channels: {
|
pathPrefix: "channels.discord",
|
||||||
discord: {
|
resolvedMode: "off",
|
||||||
streaming: false,
|
});
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(res.config.channels?.discord?.streaming).toEqual({ mode: "off" });
|
expect(res.entry.streaming).toEqual({ mode: "off" });
|
||||||
expect(getLegacyProperty(res.config.channels?.discord, "streamMode")).toBeUndefined();
|
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
|
||||||
expect(res.changes).toEqual([
|
expect(res.changes).toEqual([
|
||||||
"Moved channels.discord.streaming (boolean) → channels.discord.streaming.mode (off).",
|
"Moved channels.discord.streaming (boolean) → channels.discord.streaming.mode (off).",
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("preserves discord streamMode when legacy config resolves to off", () => {
|
it("preserves discord streamMode when legacy config resolves to off", () => {
|
||||||
const res = normalizeCompatibilityConfigValues(
|
const res = normalizeStreaming({
|
||||||
asLegacyConfig({
|
entry: { streamMode: "off" },
|
||||||
channels: {
|
pathPrefix: "channels.discord",
|
||||||
discord: {
|
resolvedMode: "off",
|
||||||
streamMode: "off",
|
offModeLegacyNotice: (pathPrefix) =>
|
||||||
},
|
`${pathPrefix}.streaming remains off by default to avoid Discord preview-edit rate limits; set ${pathPrefix}.streaming.mode="partial" to opt in explicitly.`,
|
||||||
},
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(res.config.channels?.discord?.streaming).toEqual({ mode: "off" });
|
expect(res.entry.streaming).toEqual({ mode: "off" });
|
||||||
expect(getLegacyProperty(res.config.channels?.discord, "streamMode")).toBeUndefined();
|
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
|
||||||
expect(res.changes).toEqual([
|
expect(res.changes).toEqual([
|
||||||
"Moved channels.discord.streamMode → channels.discord.streaming.mode (off).",
|
"Moved channels.discord.streamMode → channels.discord.streaming.mode (off).",
|
||||||
'channels.discord.streaming remains off by default to avoid Discord preview-edit rate limits; set channels.discord.streaming.mode="partial" to opt in explicitly.',
|
'channels.discord.streaming remains off by default to avoid Discord preview-edit rate limits; set channels.discord.streaming.mode="partial" to opt in explicitly.',
|
||||||
@@ -87,21 +91,18 @@ describe("normalizeCompatibilityConfigValues preview streaming aliases", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("preserves slack boolean streaming aliases as-is", () => {
|
it("preserves slack boolean streaming aliases as-is", () => {
|
||||||
const res = normalizeCompatibilityConfigValues(
|
const res = normalizeStreaming({
|
||||||
asLegacyConfig({
|
entry: { streaming: false },
|
||||||
channels: {
|
pathPrefix: "channels.slack",
|
||||||
slack: {
|
resolvedMode: "off",
|
||||||
streaming: false,
|
resolvedNativeTransport: false,
|
||||||
},
|
});
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(res.config.channels?.slack?.streaming).toEqual({
|
expect(res.entry.streaming).toEqual({
|
||||||
mode: "off",
|
mode: "off",
|
||||||
nativeTransport: false,
|
nativeTransport: false,
|
||||||
});
|
});
|
||||||
expect(getLegacyProperty(res.config.channels?.slack, "streamMode")).toBeUndefined();
|
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
|
||||||
expect(res.changes).toEqual([
|
expect(res.changes).toEqual([
|
||||||
"Moved channels.slack.streaming (boolean) → channels.slack.streaming.mode (off).",
|
"Moved channels.slack.streaming (boolean) → channels.slack.streaming.mode (off).",
|
||||||
"Moved channels.slack.streaming (boolean) → channels.slack.streaming.nativeTransport.",
|
"Moved channels.slack.streaming (boolean) → channels.slack.streaming.nativeTransport.",
|
||||||
@@ -111,26 +112,30 @@ describe("normalizeCompatibilityConfigValues preview streaming aliases", () => {
|
|||||||
|
|
||||||
describe("normalizeCompatibilityConfigValues browser compatibility aliases", () => {
|
describe("normalizeCompatibilityConfigValues browser compatibility aliases", () => {
|
||||||
it("removes legacy browser relay bind host and migrates extension profiles", () => {
|
it("removes legacy browser relay bind host and migrates extension profiles", () => {
|
||||||
const res = normalizeCompatibilityConfigValues({
|
const changes: string[] = [];
|
||||||
browser: {
|
const config = normalizeLegacyBrowserConfig(
|
||||||
relayBindHost: "127.0.0.1",
|
asLegacyConfig({
|
||||||
profiles: {
|
browser: {
|
||||||
work: {
|
relayBindHost: "127.0.0.1",
|
||||||
driver: "extension",
|
profiles: {
|
||||||
},
|
work: {
|
||||||
keep: {
|
driver: "extension",
|
||||||
driver: "existing-session",
|
},
|
||||||
|
keep: {
|
||||||
|
driver: "existing-session",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}),
|
||||||
} as never);
|
changes,
|
||||||
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
(res.config.browser as { relayBindHost?: string } | undefined)?.relayBindHost,
|
(config.browser as { relayBindHost?: string } | undefined)?.relayBindHost,
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
expect(res.config.browser?.profiles?.work?.driver).toBe("existing-session");
|
expect(config.browser?.profiles?.work?.driver).toBe("existing-session");
|
||||||
expect(res.config.browser?.profiles?.keep?.driver).toBe("existing-session");
|
expect(config.browser?.profiles?.keep?.driver).toBe("existing-session");
|
||||||
expect(res.changes).toEqual([
|
expect(changes).toEqual([
|
||||||
"Removed browser.relayBindHost (legacy Chrome extension relay setting; host-local Chrome now uses Chrome MCP existing-session attach).",
|
"Removed browser.relayBindHost (legacy Chrome extension relay setting; host-local Chrome now uses Chrome MCP existing-session attach).",
|
||||||
'Moved browser.profiles.work.driver "extension" → "existing-session" (Chrome MCP attach).',
|
'Moved browser.profiles.work.driver "extension" → "existing-session" (Chrome MCP attach).',
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user