test: trim more channel-heavy startup in unit tests
This commit is contained in:
parent
083f825122
commit
a7401366ef
@ -1,13 +1,22 @@
|
|||||||
import { beforeEach, describe, expect, it } from "vitest";
|
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 { 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";
|
import { extractMessagingToolSend } from "./pi-embedded-subscribe.tools.js";
|
||||||
|
|
||||||
describe("extractMessagingToolSend", () => {
|
describe("extractMessagingToolSend", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
setActivePluginRegistry(
|
setActivePluginRegistry(
|
||||||
createTestRegistry([{ pluginId: "telegram", plugin: telegramPlugin, source: "test" }]),
|
createTestRegistry([
|
||||||
|
{
|
||||||
|
pluginId: "telegram",
|
||||||
|
plugin: {
|
||||||
|
...createChannelTestPluginBase({ id: "telegram" }),
|
||||||
|
messaging: { normalizeTarget: normalizeTelegramMessagingTarget },
|
||||||
|
},
|
||||||
|
source: "test",
|
||||||
|
},
|
||||||
|
]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
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 { OpenClawConfig } from "../../config/config.js";
|
||||||
import type { SessionBindingRecord } from "../../infra/outbound/session-binding-service.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 hoisted = vi.hoisted(() => {
|
||||||
const getThreadBindingManagerMock = vi.fn();
|
const getThreadBindingManagerMock = vi.fn();
|
||||||
@ -233,9 +230,6 @@ function createFakeThreadBindingManager(binding: FakeBinding | null) {
|
|||||||
|
|
||||||
describe("/session idle and /session max-age", () => {
|
describe("/session idle and /session max-age", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
setActivePluginRegistry(
|
|
||||||
createTestRegistry([{ pluginId: "telegram", source: "test", plugin: telegramPlugin }]),
|
|
||||||
);
|
|
||||||
hoisted.getThreadBindingManagerMock.mockReset();
|
hoisted.getThreadBindingManagerMock.mockReset();
|
||||||
hoisted.setThreadBindingIdleTimeoutBySessionKeyMock.mockReset();
|
hoisted.setThreadBindingIdleTimeoutBySessionKeyMock.mockReset();
|
||||||
hoisted.setThreadBindingMaxAgeBySessionKeyMock.mockReset();
|
hoisted.setThreadBindingMaxAgeBySessionKeyMock.mockReset();
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { matrixPlugin } from "../../extensions/matrix/src/channel.js";
|
|
||||||
import { setActivePluginRegistry } from "../plugins/runtime.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 { agentsBindCommand } from "./agents.js";
|
||||||
import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js";
|
import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js";
|
||||||
import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-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 readConfigFileSnapshotMock = vi.hoisted(() => vi.fn());
|
||||||
const writeConfigFileMock = vi.hoisted(() => vi.fn().mockResolvedValue(undefined));
|
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) => ({
|
vi.mock("../config/config.js", async (importOriginal) => ({
|
||||||
...(await importOriginal<typeof import("../config/config.js")>()),
|
...(await importOriginal<typeof import("../config/config.js")>()),
|
||||||
readConfigFileSnapshot: readConfigFileSnapshotMock,
|
readConfigFileSnapshot: readConfigFileSnapshotMock,
|
||||||
@ -26,7 +39,7 @@ describe("agents bind matrix integration", () => {
|
|||||||
runtime.exit.mockClear();
|
runtime.exit.mockClear();
|
||||||
|
|
||||||
setActivePluginRegistry(
|
setActivePluginRegistry(
|
||||||
createTestRegistry([{ pluginId: "matrix", plugin: matrixPlugin, source: "test" }]),
|
createTestRegistry([{ pluginId: "matrix", plugin: matrixBindingPlugin, source: "test" }]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,18 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { telegramPlugin } from "../../extensions/telegram/src/channel.js";
|
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 { 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 type { HealthSummary } from "./health.js";
|
||||||
import { getHealthSnapshot } from "./health.js";
|
import { getHealthSnapshot } from "./health.js";
|
||||||
|
|
||||||
@ -109,20 +117,32 @@ async function runSuccessfulTelegramProbe(
|
|||||||
return { calls, telegram };
|
return { calls, telegram };
|
||||||
}
|
}
|
||||||
|
|
||||||
let createPluginRuntime: typeof import("../plugins/runtime/index.js").createPluginRuntime;
|
const telegramHealthPlugin: Pick<
|
||||||
let setTelegramRuntime: typeof import("../../extensions/telegram/src/runtime.js").setTelegramRuntime;
|
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", () => {
|
describe("getHealthSnapshot", () => {
|
||||||
beforeAll(async () => {
|
|
||||||
({ createPluginRuntime } = await import("../plugins/runtime/index.js"));
|
|
||||||
({ setTelegramRuntime } = await import("../../extensions/telegram/src/runtime.js"));
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
setActivePluginRegistry(
|
setActivePluginRegistry(
|
||||||
createTestRegistry([{ pluginId: "telegram", plugin: telegramPlugin, source: "test" }]),
|
createTestRegistry([{ pluginId: "telegram", plugin: telegramHealthPlugin, source: "test" }]),
|
||||||
);
|
);
|
||||||
setTelegramRuntime(createPluginRuntime());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@ -1,19 +1,15 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
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 * as replyModule from "../auto-reply/reply.js";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import { resolveAgentMainSessionKey, resolveMainSessionKey } from "../config/sessions.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 { runHeartbeatOnce } from "./heartbeat-runner.js";
|
||||||
import { seedSessionStore, withTempHeartbeatSandbox } from "./heartbeat-runner.test-utils.js";
|
import { seedSessionStore, withTempHeartbeatSandbox } from "./heartbeat-runner.test-utils.js";
|
||||||
|
|
||||||
// Avoid pulling optional runtime deps during isolated runs.
|
// Avoid pulling optional runtime deps during isolated runs.
|
||||||
vi.mock("jiti", () => ({ createJiti: () => () => ({}) }));
|
vi.mock("jiti", () => ({ createJiti: () => () => ({}) }));
|
||||||
|
vi.mock("./outbound/deliver.js", () => ({
|
||||||
|
deliverOutboundPayloads: vi.fn().mockResolvedValue(undefined),
|
||||||
|
}));
|
||||||
|
|
||||||
type SeedSessionInput = {
|
type SeedSessionInput = {
|
||||||
lastChannel: string;
|
lastChannel: string;
|
||||||
@ -44,17 +40,7 @@ async function withHeartbeatFixture(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {});
|
||||||
const runtime = createPluginRuntime();
|
|
||||||
setTelegramRuntime(runtime);
|
|
||||||
setWhatsAppRuntime(runtime);
|
|
||||||
setActivePluginRegistry(
|
|
||||||
createTestRegistry([
|
|
||||||
{ pluginId: "whatsapp", plugin: whatsappPlugin, source: "test" },
|
|
||||||
{ pluginId: "telegram", plugin: telegramPlugin, source: "test" },
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user