From a3e7fc7de7b83ec7afb077bbf4b458e406931c54 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 16 May 2026 17:29:44 +0100 Subject: [PATCH] test(telegram): fix cache invalidation test contexts --- .../telegram/src/channel.gateway.test.ts | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/extensions/telegram/src/channel.gateway.test.ts b/extensions/telegram/src/channel.gateway.test.ts index e2afdaccc294..da9ad23cbc7c 100644 --- a/extensions/telegram/src/channel.gateway.test.ts +++ b/extensions/telegram/src/channel.gateway.test.ts @@ -49,7 +49,7 @@ async function useTempStateDir(): Promise { function installTelegramRuntime() { const runtime = createPluginRuntimeMock(); - setTelegramRuntime({ + const telegramRuntime = { ...runtime, channel: { ...runtime.channel, @@ -59,7 +59,17 @@ function installTelegramRuntime() { sendMessageTelegram, }, }, - } as unknown as TelegramRuntime); + } as unknown as TelegramRuntime; + setTelegramRuntime(telegramRuntime); + return telegramRuntime; +} + +function createRuntimeEnvMock() { + return { + log: vi.fn(), + error: vi.fn(), + exit: vi.fn(), + }; } function createTelegramConfig( @@ -297,6 +307,7 @@ describe("telegramPlugin gateway startup", () => { it("deletes cached startup botInfo when the account token changes", async () => { await useTempStateDir(); + installTelegramRuntime(); await writeCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:bad-token", @@ -307,6 +318,7 @@ describe("telegramPlugin gateway startup", () => { accountId: "ops", prevCfg: createTelegramConfig("ops"), nextCfg: createTelegramConfig("ops", { botToken: "123456:new-token" }), + runtime: createRuntimeEnvMock(), }); await expect( @@ -319,6 +331,7 @@ describe("telegramPlugin gateway startup", () => { it("keeps cached startup botInfo when unrelated Telegram config changes", async () => { await useTempStateDir(); + installTelegramRuntime(); await writeCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:bad-token", @@ -329,6 +342,7 @@ describe("telegramPlugin gateway startup", () => { accountId: "ops", prevCfg: createTelegramConfig("ops"), nextCfg: createTelegramConfig("ops", { timeoutSeconds: 60 }), + runtime: createRuntimeEnvMock(), }); await expect( @@ -341,13 +355,18 @@ describe("telegramPlugin gateway startup", () => { it("deletes cached startup botInfo when the account is removed", async () => { await useTempStateDir(); + installTelegramRuntime(); await writeCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:bad-token", botInfo: startupBotInfo, }); - await telegramPlugin.lifecycle?.onAccountRemoved?.({ accountId: "ops" }); + await telegramPlugin.lifecycle?.onAccountRemoved?.({ + accountId: "ops", + prevCfg: createTelegramConfig("ops"), + runtime: createRuntimeEnvMock(), + }); await expect( readCachedTelegramBotInfo({ @@ -360,6 +379,8 @@ describe("telegramPlugin gateway startup", () => { it("deletes cached startup botInfo when logout clears the account token", async () => { await useTempStateDir(); installTelegramRuntime(); + const cfg = createTelegramConfig("ops"); + const account = telegramPlugin.config.resolveAccount(cfg, "ops"); await writeCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:bad-token", @@ -368,7 +389,9 @@ describe("telegramPlugin gateway startup", () => { await telegramPlugin.gateway?.logoutAccount?.({ accountId: "ops", - cfg: createTelegramConfig("ops"), + account, + cfg, + runtime: createRuntimeEnvMock(), }); await expect(