mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
refactor(config): reuse default group entry migration helper
This commit is contained in:
@@ -64,3 +64,43 @@ describe("legacy migrate audio transcription", () => {
|
||||
expect(res.config?.tools?.media?.audio).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("legacy migrate mention routing", () => {
|
||||
it("moves routing.groupChat.requireMention into channel group defaults", () => {
|
||||
const res = migrateLegacyConfig({
|
||||
routing: {
|
||||
groupChat: {
|
||||
requireMention: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.changes).toContain(
|
||||
'Moved routing.groupChat.requireMention → channels.telegram.groups."*".requireMention.',
|
||||
);
|
||||
expect(res.changes).toContain(
|
||||
'Moved routing.groupChat.requireMention → channels.imessage.groups."*".requireMention.',
|
||||
);
|
||||
expect(res.config?.channels?.telegram?.groups?.["*"]?.requireMention).toBe(true);
|
||||
expect(res.config?.channels?.imessage?.groups?.["*"]?.requireMention).toBe(true);
|
||||
expect((res.config as { routing?: unknown } | null)?.routing).toBeUndefined();
|
||||
});
|
||||
|
||||
it("moves channels.telegram.requireMention into groups.*.requireMention", () => {
|
||||
const res = migrateLegacyConfig({
|
||||
channels: {
|
||||
telegram: {
|
||||
requireMention: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.changes).toContain(
|
||||
'Moved telegram.requireMention → channels.telegram.groups."*".requireMention.',
|
||||
);
|
||||
expect(res.config?.channels?.telegram?.groups?.["*"]?.requireMention).toBe(false);
|
||||
expect(
|
||||
(res.config?.channels?.telegram as { requireMention?: unknown } | undefined)?.requireMention,
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -39,6 +39,16 @@ function migrateBindings(
|
||||
}
|
||||
}
|
||||
|
||||
function ensureDefaultGroupEntry(section: Record<string, unknown>): {
|
||||
groups: Record<string, unknown>;
|
||||
entry: Record<string, unknown>;
|
||||
} {
|
||||
const groups: Record<string, unknown> = isRecord(section.groups) ? section.groups : {};
|
||||
const defaultKey = "*";
|
||||
const entry: Record<string, unknown> = isRecord(groups[defaultKey]) ? groups[defaultKey] : {};
|
||||
return { groups, entry };
|
||||
}
|
||||
|
||||
export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
|
||||
{
|
||||
id: "bindings.match.provider->bindings.match.channel",
|
||||
@@ -268,15 +278,8 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
|
||||
channels[key] && typeof channels[key] === "object"
|
||||
? (channels[key] as Record<string, unknown>)
|
||||
: {};
|
||||
const groups =
|
||||
section.groups && typeof section.groups === "object"
|
||||
? (section.groups as Record<string, unknown>)
|
||||
: {};
|
||||
const { groups, entry } = ensureDefaultGroupEntry(section);
|
||||
const defaultKey = "*";
|
||||
const entry =
|
||||
groups[defaultKey] && typeof groups[defaultKey] === "object"
|
||||
? (groups[defaultKey] as Record<string, unknown>)
|
||||
: {};
|
||||
if (entry.requireMention === undefined) {
|
||||
entry.requireMention = requireMention;
|
||||
groups[defaultKey] = entry;
|
||||
@@ -354,16 +357,8 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
|
||||
return;
|
||||
}
|
||||
|
||||
const groups =
|
||||
(telegram as Record<string, unknown>).groups &&
|
||||
typeof (telegram as Record<string, unknown>).groups === "object"
|
||||
? ((telegram as Record<string, unknown>).groups as Record<string, unknown>)
|
||||
: {};
|
||||
const { groups, entry } = ensureDefaultGroupEntry(telegram as Record<string, unknown>);
|
||||
const defaultKey = "*";
|
||||
const entry =
|
||||
groups[defaultKey] && typeof groups[defaultKey] === "object"
|
||||
? (groups[defaultKey] as Record<string, unknown>)
|
||||
: {};
|
||||
|
||||
if (entry.requireMention === undefined) {
|
||||
entry.requireMention = requireMention;
|
||||
|
||||
Reference in New Issue
Block a user