mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-26 16:41:49 +00:00
test: align outbound telegram bootstrap mocks
This commit is contained in:
@@ -4,7 +4,7 @@ const mocks = vi.hoisted(() => ({
|
||||
getChannelPlugin: vi.fn(),
|
||||
resolveOutboundTarget: vi.fn(),
|
||||
deliverOutboundPayloads: vi.fn(),
|
||||
loadOpenClawPlugins: vi.fn(),
|
||||
resolveRuntimePluginRegistry: vi.fn(),
|
||||
}));
|
||||
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
@@ -38,7 +38,7 @@ describe("sendMessage", () => {
|
||||
applyPluginAutoEnable: ({ config }: { config: unknown }) => ({ config, changes: [] }),
|
||||
}));
|
||||
vi.doMock("../../plugins/loader.js", () => ({
|
||||
loadOpenClawPlugins: mocks.loadOpenClawPlugins,
|
||||
resolveRuntimePluginRegistry: mocks.resolveRuntimePluginRegistry,
|
||||
}));
|
||||
vi.doMock("./targets.js", () => ({
|
||||
resolveOutboundTarget: mocks.resolveOutboundTarget,
|
||||
@@ -50,7 +50,7 @@ describe("sendMessage", () => {
|
||||
mocks.getChannelPlugin.mockClear();
|
||||
mocks.resolveOutboundTarget.mockClear();
|
||||
mocks.deliverOutboundPayloads.mockClear();
|
||||
mocks.loadOpenClawPlugins.mockClear();
|
||||
mocks.resolveRuntimePluginRegistry.mockClear();
|
||||
|
||||
mocks.getChannelPlugin.mockReturnValue({
|
||||
outbound: { deliveryMode: "direct" },
|
||||
@@ -124,6 +124,6 @@ describe("sendMessage", () => {
|
||||
via: "direct",
|
||||
});
|
||||
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.resolveRuntimePluginRegistry).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
getChannelPlugin: vi.fn(),
|
||||
loadOpenClawPlugins: vi.fn(),
|
||||
resolveRuntimePluginRegistry: vi.fn(),
|
||||
}));
|
||||
|
||||
const TEST_WORKSPACE_ROOT = "/tmp/openclaw-test-workspace";
|
||||
@@ -37,7 +37,7 @@ vi.mock("../../agents/agent-scope.js", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("../../plugins/loader.js", () => ({
|
||||
loadOpenClawPlugins: mocks.loadOpenClawPlugins,
|
||||
resolveRuntimePluginRegistry: mocks.resolveRuntimePluginRegistry,
|
||||
}));
|
||||
|
||||
vi.mock("../../config/plugin-auto-enable.js", () => ({
|
||||
@@ -74,7 +74,7 @@ describe("resolveOutboundTarget channel resolution", () => {
|
||||
resetOutboundChannelResolutionStateForTest();
|
||||
setActivePluginRegistry(createTestRegistry([]), `targets-test-${registrySeq}`);
|
||||
mocks.getChannelPlugin.mockReset();
|
||||
mocks.loadOpenClawPlugins.mockReset();
|
||||
mocks.resolveRuntimePluginRegistry.mockReset();
|
||||
});
|
||||
|
||||
it("recovers telegram plugin resolution so announce delivery does not fail with Unsupported channel: telegram", () => {
|
||||
@@ -84,7 +84,7 @@ describe("resolveOutboundTarget channel resolution", () => {
|
||||
const result = resolveTelegramTarget();
|
||||
|
||||
expect(result).toEqual({ ok: true, to: "123456" });
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.resolveRuntimePluginRegistry).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("retries bootstrap on subsequent resolve when the first bootstrap attempt fails", () => {
|
||||
@@ -95,7 +95,7 @@ describe("resolveOutboundTarget channel resolution", () => {
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(telegramPlugin)
|
||||
.mockReturnValue(telegramPlugin);
|
||||
mocks.loadOpenClawPlugins
|
||||
mocks.resolveRuntimePluginRegistry
|
||||
.mockImplementationOnce(() => {
|
||||
throw new Error("bootstrap failed");
|
||||
})
|
||||
@@ -106,6 +106,6 @@ describe("resolveOutboundTarget channel resolution", () => {
|
||||
|
||||
expect(first.ok).toBe(false);
|
||||
expect(second).toEqual({ ok: true, to: "123456" });
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(2);
|
||||
expect(mocks.resolveRuntimePluginRegistry).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user