mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-21 05:32:53 +00:00
Extensions: stabilize telegram registry contracts
This commit is contained in:
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import { getSessionBindingService } from "openclaw/plugin-sdk/conversation-runtime";
|
||||
import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { loadBundledPluginTestApiSync } from "../../../src/test-utils/bundled-plugin-public-surface.js";
|
||||
import { importFreshModule } from "../../../test/helpers/import-fresh.js";
|
||||
import {
|
||||
__testing,
|
||||
@@ -172,6 +173,14 @@ describe("telegram thread bindings", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("exposes the reset helper through the bundled test api", async () => {
|
||||
const { resetTelegramThreadBindingsForTests } = loadBundledPluginTestApiSync<{
|
||||
resetTelegramThreadBindingsForTests: () => Promise<void>;
|
||||
}>("telegram");
|
||||
|
||||
await expect(resetTelegramThreadBindingsForTests()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not persist lifecycle updates when manager persistence is disabled", async () => {
|
||||
stateDirOverride = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-telegram-bindings-"));
|
||||
process.env.OPENCLAW_STATE_DIR = stateDirOverride;
|
||||
|
||||
@@ -8,3 +8,4 @@ export { makeProxyFetch } from "./src/proxy.js";
|
||||
export { telegramOutbound } from "./src/outbound-adapter.js";
|
||||
export { setTelegramRuntime } from "./src/runtime.js";
|
||||
export { sendMessageTelegram, sendPollTelegram, type TelegramApiOverride } from "./src/send.js";
|
||||
export { resetTelegramThreadBindingsForTests } from "./src/thread-bindings.js";
|
||||
|
||||
@@ -176,7 +176,6 @@ function expectClearedSessionBinding(params: {
|
||||
).toBeNull();
|
||||
}
|
||||
|
||||
const telegramDescribeMessageToolMock = vi.fn();
|
||||
const discordDescribeMessageToolMock = vi.fn();
|
||||
const sendMessageMatrixMock = vi.hoisted(() =>
|
||||
vi.fn(async (to: string, _message: string, opts?: { threadId?: string }) => ({
|
||||
@@ -185,16 +184,6 @@ const sendMessageMatrixMock = vi.hoisted(() =>
|
||||
})),
|
||||
);
|
||||
|
||||
setBundledChannelRuntime("telegram", {
|
||||
channel: {
|
||||
telegram: {
|
||||
messageActions: {
|
||||
describeMessageTool: telegramDescribeMessageToolMock,
|
||||
},
|
||||
},
|
||||
},
|
||||
} as never);
|
||||
|
||||
setBundledChannelRuntime("discord", {
|
||||
channel: {
|
||||
discord: {
|
||||
@@ -394,17 +383,16 @@ export const actionContractRegistry: ActionsContractEntry[] = [
|
||||
plugin: requireBundledChannelPlugin("telegram"),
|
||||
cases: [
|
||||
{
|
||||
name: "forwards runtime-backed Telegram actions and capabilities",
|
||||
cfg: {} as OpenClawConfig,
|
||||
expectedActions: ["send", "poll", "react"],
|
||||
name: "exposes configured Telegram actions and capabilities",
|
||||
cfg: {
|
||||
channels: {
|
||||
telegram: {
|
||||
botToken: "123:telegram-test-token",
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
expectedActions: ["send", "poll", "react", "delete", "edit", "topic-create", "topic-edit"],
|
||||
expectedCapabilities: ["interactive", "buttons"],
|
||||
beforeTest: () => {
|
||||
telegramDescribeMessageToolMock.mockReset();
|
||||
telegramDescribeMessageToolMock.mockReturnValue({
|
||||
actions: ["send", "poll", "react"],
|
||||
capabilities: ["interactive", "buttons"],
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -19,9 +19,11 @@ import {
|
||||
installChannelThreadingContractSuite,
|
||||
installSessionBindingContractSuite,
|
||||
} from "../../../src/channels/plugins/contracts/suites.js";
|
||||
import { setDefaultChannelPluginRegistryForTests } from "../../../src/commands/channel-test-helpers.js";
|
||||
import { __testing as sessionBindingTesting } from "../../../src/infra/outbound/session-binding-service.js";
|
||||
import { feishuThreadBindingTesting } from "../../../src/plugin-sdk/feishu-conversation.js";
|
||||
import { resetMatrixThreadBindingsForTests } from "../../../src/plugin-sdk/matrix.js";
|
||||
import { resetPluginRuntimeStateForTest } from "../../../src/plugins/runtime.js";
|
||||
import { loadBundledPluginTestApiSync } from "../../../src/test-utils/bundled-plugin-public-surface.js";
|
||||
|
||||
const { discordThreadBindingTesting } = loadBundledPluginTestApiSync<{
|
||||
@@ -122,6 +124,8 @@ export function describeSessionBindingRegistryBackedContract(id: string) {
|
||||
|
||||
describe(`${entry.id} session binding contract`, () => {
|
||||
beforeEach(async () => {
|
||||
resetPluginRuntimeStateForTest();
|
||||
setDefaultChannelPluginRegistryForTests();
|
||||
sessionBindingTesting.resetSessionBindingAdaptersForTests();
|
||||
discordThreadBindingTesting.resetThreadBindingsForTests();
|
||||
feishuThreadBindingTesting.resetFeishuThreadBindingsForTests();
|
||||
|
||||
Reference in New Issue
Block a user