test: narrow doctor legacy config aliases

This commit is contained in:
Peter Steinberger
2026-04-11 06:19:17 +01:00
parent 279cbfc61c
commit d86377acfd

View File

@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { normalizeLegacyStreamingAliases } from "../config/channel-compat-normalization.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 {
return value as OpenClawConfig;
@@ -12,74 +13,77 @@ function getLegacyProperty(value: unknown, key: string): unknown {
}
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", () => {
it("preserves telegram boolean streaming aliases as-is", () => {
const res = normalizeCompatibilityConfigValues(
asLegacyConfig({
channels: {
telegram: {
streaming: false,
},
},
}),
);
const res = normalizeStreaming({
entry: { streaming: false },
pathPrefix: "channels.telegram",
resolvedMode: "off",
});
expect(res.config.channels?.telegram?.streaming).toEqual({ mode: "off" });
expect(getLegacyProperty(res.config.channels?.telegram, "streamMode")).toBeUndefined();
expect(res.entry.streaming).toEqual({ mode: "off" });
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
expect(res.changes).toEqual([
"Moved channels.telegram.streaming (boolean) → channels.telegram.streaming.mode (off).",
]);
});
it("preserves discord boolean streaming aliases as-is", () => {
const res = normalizeCompatibilityConfigValues(
asLegacyConfig({
channels: {
discord: {
streaming: true,
},
},
}),
);
const res = normalizeStreaming({
entry: { streaming: true },
pathPrefix: "channels.discord",
resolvedMode: "partial",
});
expect(res.config.channels?.discord?.streaming).toEqual({ mode: "partial" });
expect(getLegacyProperty(res.config.channels?.discord, "streamMode")).toBeUndefined();
expect(res.entry.streaming).toEqual({ mode: "partial" });
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
expect(res.changes).toEqual([
"Moved channels.discord.streaming (boolean) → channels.discord.streaming.mode (partial).",
]);
});
it("preserves explicit discord streaming=false as-is", () => {
const res = normalizeCompatibilityConfigValues(
asLegacyConfig({
channels: {
discord: {
streaming: false,
},
},
}),
);
const res = normalizeStreaming({
entry: { streaming: false },
pathPrefix: "channels.discord",
resolvedMode: "off",
});
expect(res.config.channels?.discord?.streaming).toEqual({ mode: "off" });
expect(getLegacyProperty(res.config.channels?.discord, "streamMode")).toBeUndefined();
expect(res.entry.streaming).toEqual({ mode: "off" });
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
expect(res.changes).toEqual([
"Moved channels.discord.streaming (boolean) → channels.discord.streaming.mode (off).",
]);
});
it("preserves discord streamMode when legacy config resolves to off", () => {
const res = normalizeCompatibilityConfigValues(
asLegacyConfig({
channels: {
discord: {
streamMode: "off",
},
},
}),
);
const res = normalizeStreaming({
entry: { streamMode: "off" },
pathPrefix: "channels.discord",
resolvedMode: "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(getLegacyProperty(res.config.channels?.discord, "streamMode")).toBeUndefined();
expect(res.entry.streaming).toEqual({ mode: "off" });
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
expect(res.changes).toEqual([
"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.',
@@ -87,21 +91,18 @@ describe("normalizeCompatibilityConfigValues preview streaming aliases", () => {
});
it("preserves slack boolean streaming aliases as-is", () => {
const res = normalizeCompatibilityConfigValues(
asLegacyConfig({
channels: {
slack: {
streaming: false,
},
},
}),
);
const res = normalizeStreaming({
entry: { streaming: false },
pathPrefix: "channels.slack",
resolvedMode: "off",
resolvedNativeTransport: false,
});
expect(res.config.channels?.slack?.streaming).toEqual({
expect(res.entry.streaming).toEqual({
mode: "off",
nativeTransport: false,
});
expect(getLegacyProperty(res.config.channels?.slack, "streamMode")).toBeUndefined();
expect(getLegacyProperty(res.entry, "streamMode")).toBeUndefined();
expect(res.changes).toEqual([
"Moved channels.slack.streaming (boolean) → channels.slack.streaming.mode (off).",
"Moved channels.slack.streaming (boolean) → channels.slack.streaming.nativeTransport.",
@@ -111,26 +112,30 @@ describe("normalizeCompatibilityConfigValues preview streaming aliases", () => {
describe("normalizeCompatibilityConfigValues browser compatibility aliases", () => {
it("removes legacy browser relay bind host and migrates extension profiles", () => {
const res = normalizeCompatibilityConfigValues({
browser: {
relayBindHost: "127.0.0.1",
profiles: {
work: {
driver: "extension",
},
keep: {
driver: "existing-session",
const changes: string[] = [];
const config = normalizeLegacyBrowserConfig(
asLegacyConfig({
browser: {
relayBindHost: "127.0.0.1",
profiles: {
work: {
driver: "extension",
},
keep: {
driver: "existing-session",
},
},
},
},
} as never);
}),
changes,
);
expect(
(res.config.browser as { relayBindHost?: string } | undefined)?.relayBindHost,
(config.browser as { relayBindHost?: string } | undefined)?.relayBindHost,
).toBeUndefined();
expect(res.config.browser?.profiles?.work?.driver).toBe("existing-session");
expect(res.config.browser?.profiles?.keep?.driver).toBe("existing-session");
expect(res.changes).toEqual([
expect(config.browser?.profiles?.work?.driver).toBe("existing-session");
expect(config.browser?.profiles?.keep?.driver).toBe("existing-session");
expect(changes).toEqual([
"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).',
]);