mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
Tests: isolate channel tool-result session stores
This commit is contained in:
@@ -9,26 +9,10 @@ export const readAllowFromStoreMock: MockFn = vi.fn();
|
||||
export const upsertPairingRequestMock: MockFn = vi.fn();
|
||||
export const loadConfigMock: MockFn = vi.fn();
|
||||
|
||||
export const TOOL_RESULT_SESSION_STORE_PATH = `/tmp/openclaw-sessions-${process.pid}.json`;
|
||||
|
||||
const sendModule = await import("./send.js");
|
||||
vi.spyOn(sendModule, "sendMessageDiscord").mockImplementation(
|
||||
(...args) => sendMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(sendModule, "reactMessageDiscord").mockImplementation(async (...args) => {
|
||||
reactMock(...args);
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
const replyRuntimeModule = await import("openclaw/plugin-sdk/reply-runtime");
|
||||
vi.spyOn(replyRuntimeModule, "dispatchInboundMessage").mockImplementation(
|
||||
(...args) => dispatchMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(replyRuntimeModule, "dispatchInboundMessageWithDispatcher").mockImplementation(
|
||||
(...args) => dispatchMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(replyRuntimeModule, "dispatchInboundMessageWithBufferedDispatcher").mockImplementation(
|
||||
(...args) => dispatchMock(...args) as never,
|
||||
);
|
||||
|
||||
const conversationRuntimeModule = await import("openclaw/plugin-sdk/conversation-runtime");
|
||||
type ReadChannelAllowFromStore = typeof conversationRuntimeModule.readChannelAllowFromStore;
|
||||
type UpsertChannelPairingRequest = typeof conversationRuntimeModule.upsertChannelPairingRequest;
|
||||
@@ -49,22 +33,42 @@ function createPairingStoreMocks() {
|
||||
}
|
||||
|
||||
const pairingStoreMocks = createPairingStoreMocks();
|
||||
vi.spyOn(conversationRuntimeModule, "readChannelAllowFromStore").mockImplementation((...args) =>
|
||||
pairingStoreMocks.readChannelAllowFromStore(...args),
|
||||
);
|
||||
vi.spyOn(conversationRuntimeModule, "upsertChannelPairingRequest").mockImplementation((...args) =>
|
||||
pairingStoreMocks.upsertChannelPairingRequest(...args),
|
||||
);
|
||||
|
||||
const configRuntimeModule = await import("openclaw/plugin-sdk/config-runtime");
|
||||
vi.spyOn(configRuntimeModule, "loadConfig").mockImplementation(
|
||||
(...args) => loadConfigMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(configRuntimeModule, "readSessionUpdatedAt").mockImplementation(() => undefined);
|
||||
vi.spyOn(configRuntimeModule, "resolveStorePath").mockImplementation(
|
||||
() => "/tmp/openclaw-sessions.json",
|
||||
);
|
||||
vi.spyOn(configRuntimeModule, "updateLastRoute").mockImplementation(
|
||||
(...args) => updateLastRouteMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(configRuntimeModule, "resolveSessionKey").mockImplementation(vi.fn() as never);
|
||||
|
||||
export function installDiscordToolResultHarnessSpies() {
|
||||
vi.spyOn(sendModule, "sendMessageDiscord").mockImplementation(
|
||||
(...args) => sendMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(sendModule, "reactMessageDiscord").mockImplementation(async (...args) => {
|
||||
reactMock(...args);
|
||||
return { ok: true };
|
||||
});
|
||||
vi.spyOn(replyRuntimeModule, "dispatchInboundMessage").mockImplementation(
|
||||
(...args) => dispatchMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(replyRuntimeModule, "dispatchInboundMessageWithDispatcher").mockImplementation(
|
||||
(...args) => dispatchMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(replyRuntimeModule, "dispatchInboundMessageWithBufferedDispatcher").mockImplementation(
|
||||
(...args) => dispatchMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(conversationRuntimeModule, "readChannelAllowFromStore").mockImplementation((...args) =>
|
||||
pairingStoreMocks.readChannelAllowFromStore(...args),
|
||||
);
|
||||
vi.spyOn(conversationRuntimeModule, "upsertChannelPairingRequest").mockImplementation((...args) =>
|
||||
pairingStoreMocks.upsertChannelPairingRequest(...args),
|
||||
);
|
||||
vi.spyOn(configRuntimeModule, "loadConfig").mockImplementation(
|
||||
(...args) => loadConfigMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(configRuntimeModule, "readSessionUpdatedAt").mockImplementation(() => undefined);
|
||||
vi.spyOn(configRuntimeModule, "resolveStorePath").mockImplementation(
|
||||
() => TOOL_RESULT_SESSION_STORE_PATH,
|
||||
);
|
||||
vi.spyOn(configRuntimeModule, "updateLastRoute").mockImplementation(
|
||||
(...args) => updateLastRouteMock(...args) as never,
|
||||
);
|
||||
vi.spyOn(configRuntimeModule, "resolveSessionKey").mockImplementation(vi.fn() as never);
|
||||
}
|
||||
|
||||
installDiscordToolResultHarnessSpies();
|
||||
|
||||
@@ -4,9 +4,11 @@ import type { loadConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { vi } from "vitest";
|
||||
import {
|
||||
dispatchMock,
|
||||
installDiscordToolResultHarnessSpies,
|
||||
loadConfigMock,
|
||||
readAllowFromStoreMock,
|
||||
sendMock,
|
||||
TOOL_RESULT_SESSION_STORE_PATH,
|
||||
updateLastRouteMock,
|
||||
upsertPairingRequestMock,
|
||||
} from "./monitor.tool-result.test-harness.js";
|
||||
@@ -26,7 +28,7 @@ export const BASE_CFG: Config = {
|
||||
messages: {
|
||||
inbound: { debounceMs: 0 },
|
||||
},
|
||||
session: { store: "/tmp/openclaw-sessions.json" },
|
||||
session: { store: TOOL_RESULT_SESSION_STORE_PATH },
|
||||
};
|
||||
|
||||
export const CATEGORY_GUILD_CFG = {
|
||||
@@ -45,6 +47,7 @@ export const CATEGORY_GUILD_CFG = {
|
||||
} satisfies Config;
|
||||
|
||||
export function resetDiscordToolResultHarness() {
|
||||
installDiscordToolResultHarnessSpies();
|
||||
__resetDiscordChannelInfoCacheForTest();
|
||||
sendMock.mockClear().mockResolvedValue(undefined);
|
||||
updateLastRouteMock.mockClear();
|
||||
|
||||
@@ -27,6 +27,9 @@ const streamMock = vi.hoisted(() => vi.fn()) as unknown as MockFn;
|
||||
const signalCheckMock = vi.hoisted(() => vi.fn()) as unknown as MockFn;
|
||||
const signalRpcRequestMock = vi.hoisted(() => vi.fn()) as unknown as MockFn;
|
||||
const spawnSignalDaemonMock = vi.hoisted(() => vi.fn()) as unknown as MockFn;
|
||||
const signalToolResultSessionStorePath = vi.hoisted(
|
||||
() => `/tmp/openclaw-signal-tool-result-sessions-${process.pid}.json`,
|
||||
);
|
||||
|
||||
export function getSignalToolResultTestMocks(): SignalToolResultTestMocks {
|
||||
return {
|
||||
@@ -102,7 +105,7 @@ vi.mock("openclaw/plugin-sdk/config-runtime", async () => {
|
||||
return {
|
||||
...actual,
|
||||
loadConfig: () => config,
|
||||
resolveStorePath: vi.fn(() => "/tmp/openclaw-sessions.json"),
|
||||
resolveStorePath: vi.fn(() => signalToolResultSessionStorePath),
|
||||
updateLastRoute: (...args: unknown[]) => updateLastRouteMock(...args),
|
||||
readSessionUpdatedAt: vi.fn(() => undefined),
|
||||
recordSessionMetaFromInbound: vi.fn().mockResolvedValue(undefined),
|
||||
@@ -207,6 +210,7 @@ export function installSignalToolResultTestHooks() {
|
||||
resetInboundDedupe();
|
||||
config = {
|
||||
messages: { responsePrefix: "PFX" },
|
||||
session: { store: signalToolResultSessionStorePath },
|
||||
channels: {
|
||||
signal: { autoStart: false, dmPolicy: "open", allowFrom: ["*"] },
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user