chore: Fix types in tests 9/N.

This commit is contained in:
cpojer
2026-02-17 11:16:58 +09:00
parent 5dc8983954
commit 95f344e433
5 changed files with 57 additions and 25 deletions

View File

@@ -26,7 +26,7 @@ describe("browser control server", () => {
async () => {
const base = await startServerAndBase();
const select = await postJson(`${base}/act`, {
const select = await postJson<{ ok: boolean }>(`${base}/act`, {
kind: "select",
ref: "5",
values: ["a", "b"],
@@ -39,7 +39,7 @@ describe("browser control server", () => {
values: ["a", "b"],
});
const fill = await postJson(`${base}/act`, {
const fill = await postJson<{ ok: boolean }>(`${base}/act`, {
kind: "fill",
fields: [{ ref: "6", type: "textbox", value: "hello" }],
});
@@ -50,7 +50,7 @@ describe("browser control server", () => {
fields: [{ ref: "6", type: "textbox", value: "hello" }],
});
const resize = await postJson(`${base}/act`, {
const resize = await postJson<{ ok: boolean }>(`${base}/act`, {
kind: "resize",
width: 800,
height: 600,
@@ -63,7 +63,7 @@ describe("browser control server", () => {
height: 600,
});
const wait = await postJson(`${base}/act`, {
const wait = await postJson<{ ok: boolean }>(`${base}/act`, {
kind: "wait",
timeMs: 5,
});
@@ -76,7 +76,7 @@ describe("browser control server", () => {
textGone: undefined,
});
const evalRes = await postJson(`${base}/act`, {
const evalRes = await postJson<{ ok: boolean; result?: string }>(`${base}/act`, {
kind: "evaluate",
fn: "() => 1",
});
@@ -101,14 +101,14 @@ describe("browser control server", () => {
setBrowserControlServerEvaluateEnabled(false);
const base = await startServerAndBase();
const waitRes = await postJson(`${base}/act`, {
const waitRes = await postJson<{ error?: string }>(`${base}/act`, {
kind: "wait",
fn: "() => window.ready === true",
});
expect(waitRes.error).toContain("browser.evaluateEnabled=false");
expect(pwMocks.waitForViaPlaywright).not.toHaveBeenCalled();
const res = await postJson(`${base}/act`, {
const res = await postJson<{ error?: string }>(`${base}/act`, {
kind: "evaluate",
fn: "() => 1",
});
@@ -185,11 +185,11 @@ describe("browser control server", () => {
expect(consoleRes.ok).toBe(true);
expect(Array.isArray(consoleRes.messages)).toBe(true);
const pdf = await postJson(`${base}/pdf`, {});
const pdf = await postJson<{ ok: boolean; path?: string }>(`${base}/pdf`, {});
expect(pdf.ok).toBe(true);
expect(typeof pdf.path).toBe("string");
const shot = await postJson(`${base}/screenshot`, {
const shot = await postJson<{ ok: boolean; path?: string }>(`${base}/screenshot`, {
element: "body",
type: "jpeg",
});

View File

@@ -1,6 +1,6 @@
import type { DiscordActionConfig } from "../../../config/types.discord.js";
import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js";
import { createDiscordActionGate, listEnabledDiscordAccounts } from "../../../discord/accounts.js";
import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js";
import { handleDiscordMessageAction } from "./discord/handle-action.js";
export const discordMessageActions: ChannelMessageActionAdapter = {

View File

@@ -1,5 +1,3 @@
import type { TelegramActionConfig } from "../../../config/types.telegram.js";
import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js";
import {
readNumberParam,
readStringArrayParam,
@@ -7,12 +5,14 @@ import {
readStringParam,
} from "../../../agents/tools/common.js";
import { handleTelegramAction } from "../../../agents/tools/telegram-actions.js";
import type { TelegramActionConfig } from "../../../config/types.telegram.js";
import { extractToolSend } from "../../../plugin-sdk/tool-send.js";
import {
createTelegramActionGate,
listEnabledTelegramAccounts,
} from "../../../telegram/accounts.js";
import { isTelegramInlineButtonsEnabled } from "../../../telegram/inline-buttons.js";
import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js";
const providerId = "telegram";

View File

@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../../config/config.js";
vi.mock("../../../slack/send.js", () => ({
sendMessageSlack: vi.fn().mockResolvedValue({ messageId: "1234.5678", channelId: "C123" }),
@@ -12,6 +13,24 @@ import { getGlobalHookRunner } from "../../../plugins/hook-runner-global.js";
import { sendMessageSlack } from "../../../slack/send.js";
import { slackOutbound } from "./slack.js";
const sendSlackText = async (ctx: {
to: string;
text: string;
accountId: string;
replyToId: string;
identity?: {
name?: string;
avatarUrl?: string;
emoji?: string;
};
}) => {
const sendText = slackOutbound.sendText as NonNullable<typeof slackOutbound.sendText>;
return await sendText({
cfg: {} as OpenClawConfig,
...ctx,
});
};
describe("slack outbound hook wiring", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -24,7 +43,7 @@ describe("slack outbound hook wiring", () => {
it("calls send without hooks when no hooks registered", async () => {
vi.mocked(getGlobalHookRunner).mockReturnValue(null);
await slackOutbound.sendText({
await sendSlackText({
to: "C123",
text: "hello",
accountId: "default",
@@ -40,7 +59,7 @@ describe("slack outbound hook wiring", () => {
it("forwards identity opts when present", async () => {
vi.mocked(getGlobalHookRunner).mockReturnValue(null);
await slackOutbound.sendText({
await sendSlackText({
to: "C123",
text: "hello",
accountId: "default",
@@ -62,7 +81,7 @@ describe("slack outbound hook wiring", () => {
it("forwards icon_emoji only when icon_url is absent", async () => {
vi.mocked(getGlobalHookRunner).mockReturnValue(null);
await slackOutbound.sendText({
await sendSlackText({
to: "C123",
text: "hello",
accountId: "default",
@@ -85,7 +104,7 @@ describe("slack outbound hook wiring", () => {
// oxlint-disable-next-line typescript/no-explicit-any
vi.mocked(getGlobalHookRunner).mockReturnValue(mockRunner as any);
await slackOutbound.sendText({
await sendSlackText({
to: "C123",
text: "hello",
accountId: "default",
@@ -111,7 +130,7 @@ describe("slack outbound hook wiring", () => {
// oxlint-disable-next-line typescript/no-explicit-any
vi.mocked(getGlobalHookRunner).mockReturnValue(mockRunner as any);
const result = await slackOutbound.sendText({
const result = await sendSlackText({
to: "C123",
text: "hello",
accountId: "default",
@@ -130,7 +149,7 @@ describe("slack outbound hook wiring", () => {
// oxlint-disable-next-line typescript/no-explicit-any
vi.mocked(getGlobalHookRunner).mockReturnValue(mockRunner as any);
await slackOutbound.sendText({
await sendSlackText({
to: "C123",
text: "original",
accountId: "default",
@@ -151,7 +170,7 @@ describe("slack outbound hook wiring", () => {
// oxlint-disable-next-line typescript/no-explicit-any
vi.mocked(getGlobalHookRunner).mockReturnValue(mockRunner as any);
await slackOutbound.sendText({
await sendSlackText({
to: "C123",
text: "hello",
accountId: "default",

View File

@@ -1,7 +1,17 @@
import { Command } from "commander";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const callGateway = vi.fn(async (opts: { method?: string }) => {
type NodeInvokeCall = {
method?: string;
params?: {
idempotencyKey?: string;
command?: string;
params?: unknown;
timeoutMs?: number;
};
};
const callGateway = vi.fn(async (opts: NodeInvokeCall) => {
if (opts.method === "node.list") {
return {
nodes: [
@@ -62,7 +72,7 @@ const defaultRuntime = {
};
vi.mock("../gateway/call.js", () => ({
callGateway: (opts: unknown) => callGateway(opts as { method?: string }),
callGateway: (opts: unknown) => callGateway(opts as NodeInvokeCall),
randomIdempotencyKey: () => randomIdempotencyKey(),
}));
@@ -77,6 +87,9 @@ vi.mock("../config/config.js", () => ({
describe("nodes-cli coverage", () => {
let registerNodesCli: (program: Command) => void;
const getNodeInvokeCall = () =>
callGateway.mock.calls.find((call) => call[0]?.method === "node.invoke")?.[0] as NodeInvokeCall;
beforeAll(async () => {
({ registerNodesCli } = await import("./nodes-cli.js"));
});
@@ -114,7 +127,7 @@ describe("nodes-cli coverage", () => {
{ from: "user" },
);
const invoke = callGateway.mock.calls.find((call) => call[0]?.method === "node.invoke")?.[0];
const invoke = getNodeInvokeCall();
expect(invoke).toBeTruthy();
expect(invoke?.params?.idempotencyKey).toBe("rk_test");
@@ -143,7 +156,7 @@ describe("nodes-cli coverage", () => {
{ from: "user" },
);
const invoke = callGateway.mock.calls.find((call) => call[0]?.method === "node.invoke")?.[0];
const invoke = getNodeInvokeCall();
expect(invoke).toBeTruthy();
expect(invoke?.params?.idempotencyKey).toBe("rk_test");
@@ -179,7 +192,7 @@ describe("nodes-cli coverage", () => {
{ from: "user" },
);
const invoke = callGateway.mock.calls.find((call) => call[0]?.method === "node.invoke")?.[0];
const invoke = getNodeInvokeCall();
expect(invoke).toBeTruthy();
expect(invoke?.params?.command).toBe("system.notify");
@@ -216,7 +229,7 @@ describe("nodes-cli coverage", () => {
{ from: "user" },
);
const invoke = callGateway.mock.calls.find((call) => call[0]?.method === "node.invoke")?.[0];
const invoke = getNodeInvokeCall();
expect(invoke).toBeTruthy();
expect(invoke?.params?.command).toBe("location.get");