





















@@ -6,6 +6,10 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
66import { afterEach, describe, expect, it, vi } from "vitest";
77import { telegramPlugin } from "./channel.js";
88import type { TelegramMonitorFn } from "./monitor.types.js";
9+import {
10+acquireTelegramPollingLease,
11+resetTelegramPollingLeasesForTests,
12+} from "./polling-lease.js";
913import { clearTelegramRuntime, setTelegramRuntime } from "./runtime.js";
1014import type { TelegramProbeFn } from "./runtime.types.js";
1115import type { TelegramRuntime } from "./runtime.types.js";
@@ -115,6 +119,7 @@ async function waitForCondition(check: () => boolean, message: string, attempts
115119116120afterEach(() => {
117121clearTelegramRuntime();
122+resetTelegramPollingLeasesForTests();
118123resetTelegramStartupProbeLimiterForTests();
119124probeTelegram.mockReset();
120125monitorTelegramProvider.mockReset();
@@ -333,6 +338,44 @@ describe("telegramPlugin gateway startup", () => {
333338expect(probeTelegram).toHaveBeenCalledTimes(2);
334339expect(monitorTelegramProvider).toHaveBeenCalledTimes(2);
335340});
341+342+it("releases a stopped stale polling lease for the account token", async () => {
343+vi.useFakeTimers();
344+try {
345+const cfg = createTelegramConfig();
346+const account = telegramPlugin.config.resolveAccount(cfg, "default");
347+const stopAccount = telegramPlugin.gateway?.stopAccount;
348+if (!stopAccount) {
349+throw new Error("expected Telegram stopAccount gateway handler");
350+}
351+352+const abort = new AbortController();
353+await acquireTelegramPollingLease({
354+token: "123456:bad-token",
355+accountId: "default",
356+abortSignal: abort.signal,
357+});
358+abort.abort();
359+360+const stop = stopAccount(
361+createStartAccountContext({
362+ account,
363+abortSignal: abort.signal,
364+ cfg,
365+}),
366+);
367+await vi.advanceTimersByTimeAsync(5_000);
368+await stop;
369+370+const next = await acquireTelegramPollingLease({
371+token: "123456:bad-token",
372+accountId: "default",
373+});
374+next.release();
375+} finally {
376+vi.useRealTimers();
377+}
378+});
336379});
337380338381describe("telegramPlugin outbound attachments", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。