






















@@ -49,7 +49,7 @@ async function useTempStateDir(): Promise<string> {
49495050function installTelegramRuntime() {
5151const runtime = createPluginRuntimeMock();
52-setTelegramRuntime({
52+const telegramRuntime = {
5353 ...runtime,
5454channel: {
5555 ...runtime.channel,
@@ -59,7 +59,17 @@ function installTelegramRuntime() {
5959 sendMessageTelegram,
6060},
6161},
62-} as unknown as TelegramRuntime);
62+} as unknown as TelegramRuntime;
63+setTelegramRuntime(telegramRuntime);
64+return telegramRuntime;
65+}
66+67+function createRuntimeEnvMock() {
68+return {
69+log: vi.fn(),
70+error: vi.fn(),
71+exit: vi.fn(),
72+};
6373}
64746575function createTelegramConfig(
@@ -297,6 +307,7 @@ describe("telegramPlugin gateway startup", () => {
297307298308it("deletes cached startup botInfo when the account token changes", async () => {
299309await useTempStateDir();
310+installTelegramRuntime();
300311await writeCachedTelegramBotInfo({
301312accountId: "ops",
302313botToken: "123456:bad-token",
@@ -307,6 +318,7 @@ describe("telegramPlugin gateway startup", () => {
307318accountId: "ops",
308319prevCfg: createTelegramConfig("ops"),
309320nextCfg: createTelegramConfig("ops", { botToken: "123456:new-token" }),
321+runtime: createRuntimeEnvMock(),
310322});
311323312324await expect(
@@ -319,6 +331,7 @@ describe("telegramPlugin gateway startup", () => {
319331320332it("keeps cached startup botInfo when unrelated Telegram config changes", async () => {
321333await useTempStateDir();
334+installTelegramRuntime();
322335await writeCachedTelegramBotInfo({
323336accountId: "ops",
324337botToken: "123456:bad-token",
@@ -329,6 +342,7 @@ describe("telegramPlugin gateway startup", () => {
329342accountId: "ops",
330343prevCfg: createTelegramConfig("ops"),
331344nextCfg: createTelegramConfig("ops", { timeoutSeconds: 60 }),
345+runtime: createRuntimeEnvMock(),
332346});
333347334348await expect(
@@ -341,13 +355,18 @@ describe("telegramPlugin gateway startup", () => {
341355342356it("deletes cached startup botInfo when the account is removed", async () => {
343357await useTempStateDir();
358+installTelegramRuntime();
344359await writeCachedTelegramBotInfo({
345360accountId: "ops",
346361botToken: "123456:bad-token",
347362botInfo: startupBotInfo,
348363});
349364350-await telegramPlugin.lifecycle?.onAccountRemoved?.({ accountId: "ops" });
365+await telegramPlugin.lifecycle?.onAccountRemoved?.({
366+accountId: "ops",
367+prevCfg: createTelegramConfig("ops"),
368+runtime: createRuntimeEnvMock(),
369+});
351370352371await expect(
353372readCachedTelegramBotInfo({
@@ -360,6 +379,8 @@ describe("telegramPlugin gateway startup", () => {
360379it("deletes cached startup botInfo when logout clears the account token", async () => {
361380await useTempStateDir();
362381installTelegramRuntime();
382+const cfg = createTelegramConfig("ops");
383+const account = telegramPlugin.config.resolveAccount(cfg, "ops");
363384await writeCachedTelegramBotInfo({
364385accountId: "ops",
365386botToken: "123456:bad-token",
@@ -368,7 +389,9 @@ describe("telegramPlugin gateway startup", () => {
368389369390await telegramPlugin.gateway?.logoutAccount?.({
370391accountId: "ops",
371-cfg: createTelegramConfig("ops"),
392+ account,
393+ cfg,
394+runtime: createRuntimeEnvMock(),
372395});
373396374397await expect(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。