tests: type gateway reply mock helpers

This commit is contained in:
Gustavo Madeira Santana
2026-02-18 16:22:18 -05:00
parent b702be1f78
commit 710d449080
2 changed files with 13 additions and 4 deletions

View File

@@ -139,7 +139,7 @@ describe("gateway server chat", () => {
test("chat.send does not force-disable block streaming", async () => {
await withGatewayChatHarness(async ({ ws, createSessionDir }) => {
const spy = vi.mocked(getReplyFromConfig) as unknown as ReturnType<typeof vi.fn>;
const spy = getReplyFromConfig;
await connectOk(ws);
await createSessionDir();
@@ -288,7 +288,7 @@ describe("gateway server chat", () => {
test("smoke: supports abort and idempotent completion", async () => {
await withGatewayChatHarness(async ({ ws, createSessionDir }) => {
const spy = vi.mocked(getReplyFromConfig) as unknown as ReturnType<typeof vi.fn>;
const spy = getReplyFromConfig;
let aborted = false;
await connectOk(ws);

View File

@@ -4,7 +4,10 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { Mock, vi } from "vitest";
import type { MsgContext } from "../auto-reply/templating.js";
import type { GetReplyOptions, ReplyPayload } from "../auto-reply/types.js";
import type { ChannelPlugin, ChannelOutboundAdapter } from "../channels/plugins/types.js";
import type { OpenClawConfig } from "../config/config.js";
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
import type { AgentBinding } from "../config/types.agents.js";
import type { HooksConfig } from "../config/types.hooks.js";
@@ -19,6 +22,12 @@ type StubChannelOptions = {
summary?: Record<string, unknown>;
};
type GetReplyFromConfigFn = (
ctx: MsgContext,
opts?: GetReplyOptions,
configOverride?: OpenClawConfig,
) => Promise<ReplyPayload | ReplyPayload[] | undefined>;
const createStubOutboundAdapter = (channelId: ChannelPlugin["id"]): ChannelOutboundAdapter => ({
deliveryMode: "direct",
sendText: async () => ({
@@ -169,7 +178,7 @@ const hoisted = vi.hoisted(() => ({
waitResults: new Map<string, boolean>(),
},
testTailscaleWhois: { value: null as TailscaleWhoisIdentity | null },
getReplyFromConfig: vi.fn().mockResolvedValue(undefined),
getReplyFromConfig: vi.fn<GetReplyFromConfigFn>().mockResolvedValue(undefined),
sendWhatsAppMock: vi.fn().mockResolvedValue({ messageId: "msg-1", toJid: "jid-1" }),
}));
@@ -202,7 +211,7 @@ export const testTailscaleWhois = hoisted.testTailscaleWhois;
export const piSdkMock = hoisted.piSdkMock;
export const cronIsolatedRun = hoisted.cronIsolatedRun;
export const agentCommand: Mock<() => void> = hoisted.agentCommand;
export const getReplyFromConfig: Mock<() => void> = hoisted.getReplyFromConfig;
export const getReplyFromConfig: Mock<GetReplyFromConfigFn> = hoisted.getReplyFromConfig;
export const testState = {
agentConfig: undefined as Record<string, unknown> | undefined,