fix(regression): preserve Telegram status fallback without runtime

This commit is contained in:
Tak Hoffman 2026-03-27 15:30:41 -05:00
parent ae7d93adc4
commit 77060aa9f9
No known key found for this signature in database
3 changed files with 38 additions and 5 deletions

View File

@ -8,7 +8,7 @@ import * as auditModule from "./audit.js";
import { telegramPlugin } from "./channel.js";
import * as monitorModule from "./monitor.js";
import * as probeModule from "./probe.js";
import { setTelegramRuntime } from "./runtime.js";
import { clearTelegramRuntime, setTelegramRuntime } from "./runtime.js";
const probeTelegramMock = vi.hoisted(() => vi.fn());
const collectTelegramUnmentionedGroupIdsMock = vi.hoisted(() => vi.fn());
@ -292,6 +292,29 @@ describe("telegramPlugin duplicate token guard", () => {
expect(monitorTelegramProvider).toHaveBeenCalled();
});
it("falls back to direct probe helpers when Telegram runtime is uninitialized", async () => {
try {
clearTelegramRuntime();
const cfg = createCfg();
const account = resolveAccount(cfg, "ops");
await expect(
telegramPlugin.status!.probeAccount!({
account,
timeoutMs: 1234,
cfg,
}),
).resolves.toEqual(
expect.objectContaining({
ok: expect.any(Boolean),
elapsedMs: expect.any(Number),
}),
);
} finally {
installTelegramRuntime();
}
});
it("passes account proxy and network settings into Telegram probes", async () => {
installGatewayRuntime();
probeTelegramMock.mockResolvedValue({

View File

@ -92,7 +92,14 @@ type TelegramStatusRuntimeHelpers = {
};
function getTelegramStatusRuntimeHelpers(): TelegramStatusRuntimeHelpers {
return (getTelegramRuntime().channel?.telegram ?? {}) as TelegramStatusRuntimeHelpers;
try {
return (getTelegramRuntime().channel?.telegram ?? {}) as TelegramStatusRuntimeHelpers;
} catch (error) {
if (error instanceof Error && error.message === "Telegram runtime not initialized") {
return {};
}
throw error;
}
}
function resolveTelegramProbe() {

View File

@ -1,6 +1,9 @@
import type { PluginRuntime } from "openclaw/plugin-sdk/core";
import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
const { setRuntime: setTelegramRuntime, getRuntime: getTelegramRuntime } =
createPluginRuntimeStore<PluginRuntime>("Telegram runtime not initialized");
export { getTelegramRuntime, setTelegramRuntime };
const {
setRuntime: setTelegramRuntime,
clearRuntime: clearTelegramRuntime,
getRuntime: getTelegramRuntime,
} = createPluginRuntimeStore<PluginRuntime>("Telegram runtime not initialized");
export { clearTelegramRuntime, getTelegramRuntime, setTelegramRuntime };