test(zalo): replace heavy testing helpers in monitor tests

This commit is contained in:
Vincent Koc 2026-04-03 21:16:47 +09:00
parent 5184522f2f
commit cd81e0a07b
2 changed files with 32 additions and 9 deletions

View File

@ -1,7 +1,7 @@
import type { RequestListener } from "node:http";
import { createEmptyPluginRegistry } from "openclaw/plugin-sdk/testing";
import { setActivePluginRegistry } from "openclaw/plugin-sdk/testing";
import { afterEach, describe, expect, it, vi } from "vitest";
import { createEmptyPluginRegistry } from "../../../src/plugins/registry-empty.js";
import { setActivePluginRegistry } from "../../../src/plugins/runtime.js";
import { withServer } from "../../../test/helpers/http-test-server.js";
import type { OpenClawConfig, PluginRuntime } from "../runtime-api.js";
import {

View File

@ -1,7 +1,6 @@
import { request as httpRequest } from "node:http";
import type { OpenClawConfig, PluginRuntime } from "openclaw/plugin-sdk/zalo";
import { expect, vi } from "vitest";
import { createPluginRuntimeMock } from "../../../test/helpers/plugins/plugin-runtime-mock.js";
import type { ResolvedZaloAccount } from "../src/types.js";
export function createLifecycleConfig(params: {
@ -123,8 +122,30 @@ export function createImageLifecycleCore() {
path: "/tmp/zalo-photo.jpg",
contentType: "image/jpeg",
}));
const core = createPluginRuntimeMock({
const core = {
channel: {
routing: {
resolveAgentRoute: vi.fn(() => ({
agentId: "main",
accountId: "default",
sessionKey: "agent:main:zalo:direct:chat-123",
})) as unknown as PluginRuntime["channel"]["routing"]["resolveAgentRoute"],
},
session: {
resolveStorePath: vi.fn(
() => "/tmp/zalo-sessions.json",
) as unknown as PluginRuntime["channel"]["session"]["resolveStorePath"],
readSessionUpdatedAt: vi.fn(
() => undefined,
) as unknown as PluginRuntime["channel"]["session"]["readSessionUpdatedAt"],
recordInboundSession:
recordInboundSessionMock as unknown as PluginRuntime["channel"]["session"]["recordInboundSession"],
},
text: {
resolveMarkdownTableMode: vi.fn(
() => "code",
) as unknown as PluginRuntime["channel"]["text"]["resolveMarkdownTableMode"],
},
media: {
fetchRemoteMedia:
fetchRemoteMediaMock as unknown as PluginRuntime["channel"]["media"]["fetchRemoteMedia"],
@ -134,14 +155,16 @@ export function createImageLifecycleCore() {
reply: {
finalizeInboundContext:
finalizeInboundContextMock as unknown as PluginRuntime["channel"]["reply"]["finalizeInboundContext"],
resolveEnvelopeFormatOptions: vi.fn(() => ({
template: "channel+name+time",
})) as unknown as PluginRuntime["channel"]["reply"]["resolveEnvelopeFormatOptions"],
formatAgentEnvelope: vi.fn(
(opts: { body: string }) => opts.body,
) as unknown as PluginRuntime["channel"]["reply"]["formatAgentEnvelope"],
dispatchReplyWithBufferedBlockDispatcher: vi.fn(
async () => undefined,
) as unknown as PluginRuntime["channel"]["reply"]["dispatchReplyWithBufferedBlockDispatcher"],
},
session: {
recordInboundSession:
recordInboundSessionMock as unknown as PluginRuntime["channel"]["session"]["recordInboundSession"],
},
commands: {
shouldComputeCommandAuthorized: vi.fn(
() => false,
@ -154,7 +177,7 @@ export function createImageLifecycleCore() {
) as unknown as PluginRuntime["channel"]["commands"]["isControlCommandMessage"],
},
},
});
} as PluginRuntime;
return {
core,
finalizeInboundContextMock,