mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 12:50:20 +00:00
fix(types): annotate portable exported helper types
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { vi } from "vitest";
|
||||
import { vi, type Mock } from "vitest";
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
type AsyncUnknownMock = Mock<(...args: unknown[]) => Promise<unknown>>;
|
||||
|
||||
const hoisted = vi.hoisted((): { recordInboundSessionMock: AsyncUnknownMock } => ({
|
||||
recordInboundSessionMock: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
export const recordInboundSessionMock = hoisted.recordInboundSessionMock;
|
||||
export const recordInboundSessionMock: AsyncUnknownMock = hoisted.recordInboundSessionMock;
|
||||
|
||||
vi.mock("./bot-message-context.session.runtime.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./bot-message-context.session.runtime.js")>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
|
||||
import { expect, vi } from "vitest";
|
||||
import { expect, vi, type Mock } from "vitest";
|
||||
import type { OpenClawConfig } from "../runtime-api.js";
|
||||
import type { TelegramNativeCommandDeps } from "./bot-native-command-deps.runtime.js";
|
||||
import {
|
||||
@@ -12,6 +12,7 @@ type RegisteredCommand = {
|
||||
command: string;
|
||||
description: string;
|
||||
};
|
||||
type UnknownMock = Mock<(...args: unknown[]) => unknown>;
|
||||
|
||||
type CreateCommandBotResult = {
|
||||
bot: RegisterTelegramNativeCommandsParams["bot"];
|
||||
@@ -36,7 +37,7 @@ const deliveryMocks = vi.hoisted(() => ({
|
||||
export const listSkillCommandsForAgents = skillCommandMocks.listSkillCommandsForAgents;
|
||||
export const deliverReplies = deliveryMocks.deliverReplies;
|
||||
export const editMessageTelegram = deliveryMocks.editMessageTelegram;
|
||||
export const emitTelegramMessageSentHooks = deliveryMocks.emitTelegramMessageSentHooks;
|
||||
export const emitTelegramMessageSentHooks: UnknownMock = deliveryMocks.emitTelegramMessageSentHooks;
|
||||
|
||||
vi.mock("./bot/delivery.js", () => ({
|
||||
deliverReplies,
|
||||
|
||||
@@ -73,6 +73,7 @@ type TelegramBotRuntime = {
|
||||
sequentialize: typeof sequentialize;
|
||||
apiThrottler: typeof apiThrottler;
|
||||
};
|
||||
type TelegramBotInstance = InstanceType<TelegramBotRuntime["Bot"]>;
|
||||
|
||||
const DEFAULT_TELEGRAM_BOT_RUNTIME: TelegramBotRuntime = {
|
||||
Bot,
|
||||
@@ -134,7 +135,7 @@ function extractTelegramApiMethod(input: TelegramFetchInput): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
export function createTelegramBot(opts: TelegramBotOptions) {
|
||||
export function createTelegramBot(opts: TelegramBotOptions): TelegramBotInstance {
|
||||
const botRuntime = telegramBotRuntimeForTest ?? DEFAULT_TELEGRAM_BOT_RUNTIME;
|
||||
const runtime: RuntimeEnv = opts.runtime ?? createNonExitingRuntime();
|
||||
const telegramDeps = opts.telegramDeps ?? defaultTelegramBotDeps;
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/testing";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi, type Mock } from "vitest";
|
||||
|
||||
export const readConfigFileSnapshotForWrite = vi.fn();
|
||||
export const writeConfigFile = vi.fn();
|
||||
export const loadCronStore = vi.fn();
|
||||
export const resolveCronStorePath = vi.fn();
|
||||
export const saveCronStore = vi.fn();
|
||||
type UnknownMock = Mock<(...args: unknown[]) => unknown>;
|
||||
type AsyncUnknownMock = Mock<(...args: unknown[]) => Promise<unknown>>;
|
||||
|
||||
export const readConfigFileSnapshotForWrite: AsyncUnknownMock = vi.fn();
|
||||
export const writeConfigFile: AsyncUnknownMock = vi.fn();
|
||||
export const loadCronStore: AsyncUnknownMock = vi.fn();
|
||||
export const resolveCronStorePath: UnknownMock = vi.fn();
|
||||
export const saveCronStore: AsyncUnknownMock = vi.fn();
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/config-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/config-runtime")>();
|
||||
|
||||
Reference in New Issue
Block a user