From 0f129c87ba4608d35bbdc3a39e7ec1d0b98ef12f Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 4 Apr 2026 00:16:33 +0900 Subject: [PATCH] test(config): cover telegram and x_search legacy doctor paths --- src/commands/doctor-config-flow.test.ts | 70 +++++++++++++++++++++++++ src/config/config-misc.test.ts | 53 +++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/src/commands/doctor-config-flow.test.ts b/src/commands/doctor-config-flow.test.ts index 0c334c4f0f9..4ddef7f273f 100644 --- a/src/commands/doctor-config-flow.test.ts +++ b/src/commands/doctor-config-flow.test.ts @@ -1360,6 +1360,76 @@ describe("doctor config flow", () => { } }); + it("warns clearly about legacy telegram groupMentionsOnly config and points to doctor --fix", async () => { + const noteSpy = vi.spyOn(noteModule, "note").mockImplementation(() => {}); + try { + await runDoctorConfigWithInput({ + config: { + channels: { + telegram: { + groupMentionsOnly: true, + }, + }, + }, + run: loadAndMaybeMigrateDoctorConfig, + }); + + expect( + noteSpy.mock.calls.some( + ([message, title]) => + title === "Legacy config keys detected" && + String(message).includes("channels.telegram.groupMentionsOnly:") && + String(message).includes("channels.telegram.groups"), + ), + ).toBe(true); + expect( + noteSpy.mock.calls.some( + ([message, title]) => + title === "Doctor" && + String(message).includes('Run "openclaw doctor --fix" to migrate legacy config keys.'), + ), + ).toBe(true); + } finally { + noteSpy.mockRestore(); + } + }); + + it("warns clearly about legacy x_search auth config and points to doctor --fix", async () => { + const noteSpy = vi.spyOn(noteModule, "note").mockImplementation(() => {}); + try { + await runDoctorConfigWithInput({ + config: { + tools: { + web: { + x_search: { + apiKey: "test-key", + }, + }, + }, + }, + run: loadAndMaybeMigrateDoctorConfig, + }); + + expect( + noteSpy.mock.calls.some( + ([message, title]) => + title === "Legacy config keys detected" && + String(message).includes("tools.web.x_search.apiKey:") && + String(message).includes("plugins.entries.xai.config.webSearch.apiKey"), + ), + ).toBe(true); + expect( + noteSpy.mock.calls.some( + ([message, title]) => + title === "Doctor" && + String(message).includes('Run "openclaw doctor --fix" to migrate legacy config keys.'), + ), + ).toBe(true); + } finally { + noteSpy.mockRestore(); + } + }); + it("warns clearly about legacy talk config and points to doctor --fix", async () => { const noteSpy = vi.spyOn(noteModule, "note").mockImplementation(() => {}); try { diff --git a/src/config/config-misc.test.ts b/src/config/config-misc.test.ts index c264ced2cff..e8629a6f27c 100644 --- a/src/config/config-misc.test.ts +++ b/src/config/config-misc.test.ts @@ -645,6 +645,33 @@ describe("config strict validation", () => { }); }); + it("accepts legacy x_search auth via auto-migration and reports legacyIssues", async () => { + await withTempHome(async (home) => { + await writeOpenClawConfig(home, { + tools: { + web: { + x_search: { + apiKey: "test-key", + }, + }, + }, + }); + + const snap = await readConfigFileSnapshot(); + + expect(snap.valid).toBe(true); + expect(snap.legacyIssues.some((issue) => issue.path === "tools.web.x_search.apiKey")).toBe( + true, + ); + expect(snap.sourceConfig.plugins?.entries?.xai?.config?.webSearch).toMatchObject({ + apiKey: "test-key", + }); + expect( + (snap.sourceConfig.tools?.web?.x_search as Record | undefined)?.apiKey, + ).toBeUndefined(); + }); + }); + it("accepts legacy channel streaming aliases via auto-migration and reports legacyIssues", async () => { await withTempHome(async (home) => { await writeOpenClawConfig(home, { @@ -694,6 +721,32 @@ describe("config strict validation", () => { }); }); + it("accepts telegram groupMentionsOnly via auto-migration and reports legacyIssues", async () => { + await withTempHome(async (home) => { + await writeOpenClawConfig(home, { + channels: { + telegram: { + groupMentionsOnly: true, + }, + }, + }); + + const snap = await readConfigFileSnapshot(); + + expect(snap.valid).toBe(true); + expect( + snap.legacyIssues.some((issue) => issue.path === "channels.telegram.groupMentionsOnly"), + ).toBe(true); + expect(snap.sourceConfig.channels?.telegram?.groups?.["*"]).toMatchObject({ + requireMention: true, + }); + expect( + (snap.sourceConfig.channels?.telegram as Record | undefined) + ?.groupMentionsOnly, + ).toBeUndefined(); + }); + }); + it("accepts legacy plugins.entries.*.config.tts provider keys via auto-migration", async () => { await withTempHome(async (home) => { await writeOpenClawConfig(home, {