diff --git a/src/agents/pi-embedded-subscribe.tools.extract.test.ts b/src/agents/pi-embedded-subscribe.tools.extract.test.ts index cd99ee6b674..044edc93a6d 100644 --- a/src/agents/pi-embedded-subscribe.tools.extract.test.ts +++ b/src/agents/pi-embedded-subscribe.tools.extract.test.ts @@ -1,13 +1,22 @@ import { beforeEach, describe, expect, it } from "vitest"; -import { telegramPlugin } from "../../extensions/telegram/src/channel.js"; +import { normalizeTelegramMessagingTarget } from "../../extensions/telegram/api.js"; import { setActivePluginRegistry } from "../plugins/runtime.js"; -import { createTestRegistry } from "../test-utils/channel-plugins.js"; +import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js"; import { extractMessagingToolSend } from "./pi-embedded-subscribe.tools.js"; describe("extractMessagingToolSend", () => { beforeEach(() => { setActivePluginRegistry( - createTestRegistry([{ pluginId: "telegram", plugin: telegramPlugin, source: "test" }]), + createTestRegistry([ + { + pluginId: "telegram", + plugin: { + ...createChannelTestPluginBase({ id: "telegram" }), + messaging: { normalizeTarget: normalizeTelegramMessagingTarget }, + }, + source: "test", + }, + ]), ); }); diff --git a/src/auto-reply/reply/commands-session-lifecycle.test.ts b/src/auto-reply/reply/commands-session-lifecycle.test.ts index 8d31fbf8c0d..c0988a72443 100644 --- a/src/auto-reply/reply/commands-session-lifecycle.test.ts +++ b/src/auto-reply/reply/commands-session-lifecycle.test.ts @@ -1,9 +1,6 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; -import { telegramPlugin } from "../../../extensions/telegram/src/channel.js"; import type { OpenClawConfig } from "../../config/config.js"; import type { SessionBindingRecord } from "../../infra/outbound/session-binding-service.js"; -import { setActivePluginRegistry } from "../../plugins/runtime.js"; -import { createTestRegistry } from "../../test-utils/channel-plugins.js"; const hoisted = vi.hoisted(() => { const getThreadBindingManagerMock = vi.fn(); @@ -233,9 +230,6 @@ function createFakeThreadBindingManager(binding: FakeBinding | null) { describe("/session idle and /session max-age", () => { beforeEach(() => { - setActivePluginRegistry( - createTestRegistry([{ pluginId: "telegram", source: "test", plugin: telegramPlugin }]), - ); hoisted.getThreadBindingManagerMock.mockReset(); hoisted.setThreadBindingIdleTimeoutBySessionKeyMock.mockReset(); hoisted.setThreadBindingMaxAgeBySessionKeyMock.mockReset(); diff --git a/src/commands/agents.bind.matrix.integration.test.ts b/src/commands/agents.bind.matrix.integration.test.ts index 416d9f88250..e9f82a8dc69 100644 --- a/src/commands/agents.bind.matrix.integration.test.ts +++ b/src/commands/agents.bind.matrix.integration.test.ts @@ -1,7 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import { matrixPlugin } from "../../extensions/matrix/src/channel.js"; import { setActivePluginRegistry } from "../plugins/runtime.js"; -import { createTestRegistry } from "../test-utils/channel-plugins.js"; +import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js"; import { agentsBindCommand } from "./agents.js"; import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js"; import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-helpers.js"; @@ -9,6 +8,20 @@ import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-hel const readConfigFileSnapshotMock = vi.hoisted(() => vi.fn()); const writeConfigFileMock = vi.hoisted(() => vi.fn().mockResolvedValue(undefined)); +const matrixBindingPlugin = { + ...createChannelTestPluginBase({ id: "matrix" }), + setup: { + resolveBindingAccountId: ({ accountId, agentId }: { accountId?: string; agentId?: string }) => { + const explicit = accountId?.trim(); + if (explicit) { + return explicit; + } + const agent = agentId?.trim(); + return agent || "default"; + }, + }, +}; + vi.mock("../config/config.js", async (importOriginal) => ({ ...(await importOriginal()), readConfigFileSnapshot: readConfigFileSnapshotMock, @@ -26,7 +39,7 @@ describe("agents bind matrix integration", () => { runtime.exit.mockClear(); setActivePluginRegistry( - createTestRegistry([{ pluginId: "matrix", plugin: matrixPlugin, source: "test" }]), + createTestRegistry([{ pluginId: "matrix", plugin: matrixBindingPlugin, source: "test" }]), ); }); diff --git a/src/commands/health.snapshot.test.ts b/src/commands/health.snapshot.test.ts index 03055c8eb17..24653eb187c 100644 --- a/src/commands/health.snapshot.test.ts +++ b/src/commands/health.snapshot.test.ts @@ -1,10 +1,18 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; -import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import { telegramPlugin } from "../../extensions/telegram/src/channel.js"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { + buildTokenChannelStatusSummary, + probeTelegram, + type ChannelPlugin as TelegramChannelPlugin, +} from "../../extensions/telegram/runtime-api.js"; +import { + listTelegramAccountIds, + resolveTelegramAccount, +} from "../../extensions/telegram/src/accounts.js"; import { setActivePluginRegistry } from "../plugins/runtime.js"; -import { createTestRegistry } from "../test-utils/channel-plugins.js"; +import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js"; import type { HealthSummary } from "./health.js"; import { getHealthSnapshot } from "./health.js"; @@ -109,20 +117,32 @@ async function runSuccessfulTelegramProbe( return { calls, telegram }; } -let createPluginRuntime: typeof import("../plugins/runtime/index.js").createPluginRuntime; -let setTelegramRuntime: typeof import("../../extensions/telegram/src/runtime.js").setTelegramRuntime; +const telegramHealthPlugin: Pick< + TelegramChannelPlugin, + "id" | "meta" | "capabilities" | "config" | "status" +> = { + ...createChannelTestPluginBase({ id: "telegram", label: "Telegram" }), + config: { + listAccountIds: (cfg) => listTelegramAccountIds(cfg), + resolveAccount: (cfg, accountId) => resolveTelegramAccount({ cfg, accountId }), + isConfigured: (account) => Boolean(account.token?.trim()), + }, + status: { + buildChannelSummary: ({ snapshot }) => buildTokenChannelStatusSummary(snapshot), + probeAccount: async ({ account, timeoutMs }) => + await probeTelegram(account.token, timeoutMs, { + proxyUrl: account.config.proxy, + network: account.config.network, + accountId: account.accountId, + }), + }, +}; describe("getHealthSnapshot", () => { - beforeAll(async () => { - ({ createPluginRuntime } = await import("../plugins/runtime/index.js")); - ({ setTelegramRuntime } = await import("../../extensions/telegram/src/runtime.js")); - }); - beforeEach(() => { setActivePluginRegistry( - createTestRegistry([{ pluginId: "telegram", plugin: telegramPlugin, source: "test" }]), + createTestRegistry([{ pluginId: "telegram", plugin: telegramHealthPlugin, source: "test" }]), ); - setTelegramRuntime(createPluginRuntime()); }); afterEach(() => { diff --git a/src/infra/heartbeat-runner.model-override.test.ts b/src/infra/heartbeat-runner.model-override.test.ts index 92c89e0b026..0026297c56e 100644 --- a/src/infra/heartbeat-runner.model-override.test.ts +++ b/src/infra/heartbeat-runner.model-override.test.ts @@ -1,19 +1,15 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import { telegramPlugin } from "../../extensions/telegram/src/channel.js"; -import { setTelegramRuntime } from "../../extensions/telegram/src/runtime.js"; -import { whatsappPlugin } from "../../extensions/whatsapp/src/channel.js"; -import { setWhatsAppRuntime } from "../../extensions/whatsapp/src/runtime.js"; import * as replyModule from "../auto-reply/reply.js"; import type { OpenClawConfig } from "../config/config.js"; import { resolveAgentMainSessionKey, resolveMainSessionKey } from "../config/sessions.js"; -import { setActivePluginRegistry } from "../plugins/runtime.js"; -import { createPluginRuntime } from "../plugins/runtime/index.js"; -import { createTestRegistry } from "../test-utils/channel-plugins.js"; import { runHeartbeatOnce } from "./heartbeat-runner.js"; import { seedSessionStore, withTempHeartbeatSandbox } from "./heartbeat-runner.test-utils.js"; // Avoid pulling optional runtime deps during isolated runs. vi.mock("jiti", () => ({ createJiti: () => () => ({}) })); +vi.mock("./outbound/deliver.js", () => ({ + deliverOutboundPayloads: vi.fn().mockResolvedValue(undefined), +})); type SeedSessionInput = { lastChannel: string; @@ -44,17 +40,7 @@ async function withHeartbeatFixture( ); } -beforeEach(() => { - const runtime = createPluginRuntime(); - setTelegramRuntime(runtime); - setWhatsAppRuntime(runtime); - setActivePluginRegistry( - createTestRegistry([ - { pluginId: "whatsapp", plugin: whatsappPlugin, source: "test" }, - { pluginId: "telegram", plugin: telegramPlugin, source: "test" }, - ]), - ); -}); +beforeEach(() => {}); afterEach(() => { vi.restoreAllMocks();