Skip to content

Commit 710d449

Browse files
committed
tests: type gateway reply mock helpers
1 parent b702be1 commit 710d449

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/gateway/server.chat.gateway-server-chat-b.e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe("gateway server chat", () => {
139139

140140
test("chat.send does not force-disable block streaming", async () => {
141141
await withGatewayChatHarness(async ({ ws, createSessionDir }) => {
142-
const spy = vi.mocked(getReplyFromConfig) as unknown as ReturnType<typeof vi.fn>;
142+
const spy = getReplyFromConfig;
143143
await connectOk(ws);
144144

145145
await createSessionDir();
@@ -288,7 +288,7 @@ describe("gateway server chat", () => {
288288

289289
test("smoke: supports abort and idempotent completion", async () => {
290290
await withGatewayChatHarness(async ({ ws, createSessionDir }) => {
291-
const spy = vi.mocked(getReplyFromConfig) as unknown as ReturnType<typeof vi.fn>;
291+
const spy = getReplyFromConfig;
292292
let aborted = false;
293293
await connectOk(ws);
294294

src/gateway/test-helpers.mocks.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import fs from "node:fs/promises";
44
import os from "node:os";
55
import path from "node:path";
66
import { Mock, vi } from "vitest";
7+
import type { MsgContext } from "../auto-reply/templating.js";
8+
import type { GetReplyOptions, ReplyPayload } from "../auto-reply/types.js";
79
import type { ChannelPlugin, ChannelOutboundAdapter } from "../channels/plugins/types.js";
10+
import type { OpenClawConfig } from "../config/config.js";
811
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
912
import type { AgentBinding } from "../config/types.agents.js";
1013
import type { HooksConfig } from "../config/types.hooks.js";
@@ -19,6 +22,12 @@ type StubChannelOptions = {
1922
summary?: Record<string, unknown>;
2023
};
2124

25+
type GetReplyFromConfigFn = (
26+
ctx: MsgContext,
27+
opts?: GetReplyOptions,
28+
configOverride?: OpenClawConfig,
29+
) => Promise<ReplyPayload | ReplyPayload[] | undefined>;
30+
2231
const createStubOutboundAdapter = (channelId: ChannelPlugin["id"]): ChannelOutboundAdapter => ({
2332
deliveryMode: "direct",
2433
sendText: async () => ({
@@ -169,7 +178,7 @@ const hoisted = vi.hoisted(() => ({
169178
waitResults: new Map<string, boolean>(),
170179
},
171180
testTailscaleWhois: { value: null as TailscaleWhoisIdentity | null },
172-
getReplyFromConfig: vi.fn().mockResolvedValue(undefined),
181+
getReplyFromConfig: vi.fn<GetReplyFromConfigFn>().mockResolvedValue(undefined),
173182
sendWhatsAppMock: vi.fn().mockResolvedValue({ messageId: "msg-1", toJid: "jid-1" }),
174183
}));
175184

@@ -202,7 +211,7 @@ export const testTailscaleWhois = hoisted.testTailscaleWhois;
202211
export const piSdkMock = hoisted.piSdkMock;
203212
export const cronIsolatedRun = hoisted.cronIsolatedRun;
204213
export const agentCommand: Mock<() => void> = hoisted.agentCommand;
205-
export const getReplyFromConfig: Mock<() => void> = hoisted.getReplyFromConfig;
214+
export const getReplyFromConfig: Mock<GetReplyFromConfigFn> = hoisted.getReplyFromConfig;
206215

207216
export const testState = {
208217
agentConfig: undefined as Record<string, unknown> | undefined,

0 commit comments

Comments
 (0)