mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
chore: Fix types in tests 39/N.
This commit is contained in:
@@ -145,8 +145,8 @@ describe("acp event mapper", () => {
|
||||
it("extracts text and resource blocks into prompt text", () => {
|
||||
const text = extractTextFromPrompt([
|
||||
{ type: "text", text: "Hello" },
|
||||
{ type: "resource", resource: { text: "File contents" } },
|
||||
{ type: "resource_link", uri: "https://example.com", title: "Spec" },
|
||||
{ type: "resource", resource: { uri: "file:///tmp/spec.txt", text: "File contents" } },
|
||||
{ type: "resource_link", uri: "https://example.com", name: "Spec", title: "Spec" },
|
||||
{ type: "image", data: "abc", mimeType: "image/png" },
|
||||
]);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { MsgContext } from "../auto-reply/templating.js";
|
||||
import {
|
||||
type ChannelMatchSource,
|
||||
buildChannelKeyCandidates,
|
||||
normalizeChannelSlug,
|
||||
resolveChannelEntryMatch,
|
||||
@@ -95,10 +96,8 @@ describe("resolveChannelEntryMatchWithFallback", () => {
|
||||
|
||||
describe("applyChannelMatchMeta", () => {
|
||||
it("copies match metadata onto resolved configs", () => {
|
||||
const resolved = applyChannelMatchMeta(
|
||||
{ allowed: true },
|
||||
{ matchKey: "general", matchSource: "direct" },
|
||||
);
|
||||
const base: { matchKey?: string; matchSource?: ChannelMatchSource } = {};
|
||||
const resolved = applyChannelMatchMeta(base, { matchKey: "general", matchSource: "direct" });
|
||||
expect(resolved.matchKey).toBe("general");
|
||||
expect(resolved.matchSource).toBe("direct");
|
||||
});
|
||||
@@ -106,14 +105,20 @@ describe("applyChannelMatchMeta", () => {
|
||||
|
||||
describe("resolveChannelMatchConfig", () => {
|
||||
it("returns null when no entry is matched", () => {
|
||||
const resolved = resolveChannelMatchConfig({ matchKey: "x" }, () => ({ allowed: true }));
|
||||
const resolved = resolveChannelMatchConfig({ matchKey: "x" }, () => {
|
||||
const out: { matchKey?: string; matchSource?: ChannelMatchSource } = {};
|
||||
return out;
|
||||
});
|
||||
expect(resolved).toBeNull();
|
||||
});
|
||||
|
||||
it("resolves entry and applies match metadata", () => {
|
||||
const resolved = resolveChannelMatchConfig(
|
||||
{ entry: { allow: true }, matchKey: "*", matchSource: "wildcard" },
|
||||
() => ({ allowed: true }),
|
||||
() => {
|
||||
const out: { matchKey?: string; matchSource?: ChannelMatchSource } = {};
|
||||
return out;
|
||||
},
|
||||
);
|
||||
expect(resolved?.matchKey).toBe("*");
|
||||
expect(resolved?.matchSource).toBe("wildcard");
|
||||
|
||||
@@ -436,9 +436,13 @@ describe("telegramMessageActions", () => {
|
||||
|
||||
it("rejects non-integer messageId for edit before reaching telegram-actions", async () => {
|
||||
const cfg = { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig;
|
||||
const handleAction = telegramMessageActions.handleAction;
|
||||
if (!handleAction) {
|
||||
throw new Error("telegram handleAction unavailable");
|
||||
}
|
||||
|
||||
await expect(
|
||||
telegramMessageActions.handleAction({
|
||||
handleAction({
|
||||
channel: "telegram",
|
||||
action: "edit",
|
||||
params: {
|
||||
@@ -595,9 +599,13 @@ describe("signalMessageActions", () => {
|
||||
const cfg = {
|
||||
channels: { signal: { account: "+15550001111", actions: { reactions: false } } },
|
||||
} as OpenClawConfig;
|
||||
const handleAction = signalMessageActions.handleAction;
|
||||
if (!handleAction) {
|
||||
throw new Error("signal handleAction unavailable");
|
||||
}
|
||||
|
||||
await expect(
|
||||
signalMessageActions.handleAction({
|
||||
handleAction({
|
||||
channel: "signal",
|
||||
action: "react",
|
||||
params: { to: "+15550001111", messageId: "123", emoji: "✅" },
|
||||
@@ -661,9 +669,13 @@ describe("signalMessageActions", () => {
|
||||
const cfg = {
|
||||
channels: { signal: { account: "+15550001111" } },
|
||||
} as OpenClawConfig;
|
||||
const handleAction = signalMessageActions.handleAction;
|
||||
if (!handleAction) {
|
||||
throw new Error("signal handleAction unavailable");
|
||||
}
|
||||
|
||||
await expect(
|
||||
signalMessageActions.handleAction({
|
||||
handleAction({
|
||||
channel: "signal",
|
||||
action: "react",
|
||||
params: { to: "signal:group:group-id", messageId: "123", emoji: "✅" },
|
||||
|
||||
@@ -121,6 +121,9 @@ describe("channel plugin catalog", () => {
|
||||
const createRegistry = (channels: PluginRegistry["channels"]): PluginRegistry => ({
|
||||
plugins: [],
|
||||
tools: [],
|
||||
hooks: [],
|
||||
typedHooks: [],
|
||||
commands: [],
|
||||
channels,
|
||||
providers: [],
|
||||
gatewayHandlers: {},
|
||||
|
||||
@@ -130,6 +130,9 @@ describe("resolveChannelCapabilities", () => {
|
||||
const createRegistry = (channels: PluginRegistry["channels"]): PluginRegistry => ({
|
||||
plugins: [],
|
||||
tools: [],
|
||||
hooks: [],
|
||||
typedHooks: [],
|
||||
commands: [],
|
||||
channels,
|
||||
providers: [],
|
||||
gatewayHandlers: {},
|
||||
|
||||
@@ -187,7 +187,9 @@ describe("legacy config detection", () => {
|
||||
'Moved telegram.requireMention → channels.telegram.groups."*".requireMention.',
|
||||
);
|
||||
expect(res.config?.channels?.telegram?.groups?.["*"]?.requireMention).toBe(false);
|
||||
expect(res.config?.channels?.telegram?.requireMention).toBeUndefined();
|
||||
expect(
|
||||
(res.config?.channels?.telegram as { requireMention?: boolean } | undefined)?.requireMention,
|
||||
).toBeUndefined();
|
||||
});
|
||||
it("migrates messages.tts.enabled to messages.tts.auto", async () => {
|
||||
const res = migrateLegacyConfig({
|
||||
@@ -219,7 +221,7 @@ describe("legacy config detection", () => {
|
||||
alias: "Opus",
|
||||
});
|
||||
expect(res.config?.agents?.defaults?.models?.["openai/gpt-4.1-mini"]).toBeTruthy();
|
||||
expect(res.config?.agent).toBeUndefined();
|
||||
expect((res.config as { agent?: unknown } | undefined)?.agent).toBeUndefined();
|
||||
});
|
||||
it("flags legacy config in snapshot", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
|
||||
@@ -10,6 +10,8 @@ import { attachDiscordGatewayLogging } from "./gateway-logging.js";
|
||||
|
||||
const makeRuntime = () => ({
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn(),
|
||||
});
|
||||
|
||||
describe("attachDiscordGatewayLogging", () => {
|
||||
|
||||
@@ -46,7 +46,6 @@ const CATEGORY_GUILD_CFG = {
|
||||
},
|
||||
},
|
||||
},
|
||||
routing: { allowFrom: [] },
|
||||
} satisfies Config;
|
||||
|
||||
async function createDmHandler(opts: { cfg: Config; runtimeError?: (err: unknown) => void }) {
|
||||
|
||||
@@ -3,7 +3,13 @@ import { createBaseDiscordMessageContext } from "./message-handler.test-harness.
|
||||
|
||||
const reactMessageDiscord = vi.fn(async () => {});
|
||||
const removeReactionDiscord = vi.fn(async () => {});
|
||||
const dispatchInboundMessage = vi.fn(async () => ({
|
||||
type DispatchInboundParams = {
|
||||
replyOptions?: {
|
||||
onReasoningStream?: () => Promise<void> | void;
|
||||
onToolStart?: (payload: { name?: string }) => Promise<void> | void;
|
||||
};
|
||||
};
|
||||
const dispatchInboundMessage = vi.fn(async (_params?: DispatchInboundParams) => ({
|
||||
queuedFinal: false,
|
||||
counts: { final: 0, tool: 0, block: 0 },
|
||||
}));
|
||||
@@ -114,18 +120,11 @@ describe("processDiscordMessage ack reactions", () => {
|
||||
});
|
||||
|
||||
it("debounces intermediate phase reactions and jumps to done for short runs", async () => {
|
||||
dispatchInboundMessage.mockImplementationOnce(
|
||||
async (params: {
|
||||
replyOptions?: {
|
||||
onReasoningStream?: () => Promise<void> | void;
|
||||
onToolStart?: (payload: { name?: string }) => Promise<void> | void;
|
||||
};
|
||||
}) => {
|
||||
await params.replyOptions?.onReasoningStream?.();
|
||||
await params.replyOptions?.onToolStart?.({ name: "exec" });
|
||||
return { queuedFinal: false, counts: { final: 0, tool: 0, block: 0 } };
|
||||
},
|
||||
);
|
||||
dispatchInboundMessage.mockImplementationOnce(async (params?: DispatchInboundParams) => {
|
||||
await params?.replyOptions?.onReasoningStream?.();
|
||||
await params?.replyOptions?.onToolStart?.({ name: "exec" });
|
||||
return { queuedFinal: false, counts: { final: 0, tool: 0, block: 0 } };
|
||||
});
|
||||
|
||||
const ctx = await createBaseContext();
|
||||
|
||||
|
||||
@@ -324,7 +324,10 @@ describe("discord component interactions", () => {
|
||||
await button.run(interaction, { cid: "btn_1" } as ComponentData);
|
||||
|
||||
const { interaction: secondInteraction } = createComponentButtonInteraction({
|
||||
rawData: { channel_id: "dm-channel", id: "interaction-2" },
|
||||
rawData: {
|
||||
channel_id: "dm-channel",
|
||||
id: "interaction-2",
|
||||
} as unknown as ButtonInteraction["rawData"],
|
||||
});
|
||||
await button.run(secondInteraction, { cid: "btn_1" } as ComponentData);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ describe("maybeCreateDiscordAutoThread", () => {
|
||||
message: mockMessage,
|
||||
messageChannelId: "forum1",
|
||||
isGuildMessage: true,
|
||||
channelConfig: { autoThread: true },
|
||||
channelConfig: { allowed: true, autoThread: true },
|
||||
channelType: ChannelType.GuildForum,
|
||||
baseText: "test",
|
||||
combinedBody: "test",
|
||||
@@ -34,7 +34,7 @@ describe("maybeCreateDiscordAutoThread", () => {
|
||||
message: mockMessage,
|
||||
messageChannelId: "media1",
|
||||
isGuildMessage: true,
|
||||
channelConfig: { autoThread: true },
|
||||
channelConfig: { allowed: true, autoThread: true },
|
||||
channelType: ChannelType.GuildMedia,
|
||||
baseText: "test",
|
||||
combinedBody: "test",
|
||||
@@ -50,7 +50,7 @@ describe("maybeCreateDiscordAutoThread", () => {
|
||||
message: mockMessage,
|
||||
messageChannelId: "text1",
|
||||
isGuildMessage: true,
|
||||
channelConfig: { autoThread: true },
|
||||
channelConfig: { allowed: true, autoThread: true },
|
||||
channelType: ChannelType.GuildText,
|
||||
baseText: "test",
|
||||
combinedBody: "test",
|
||||
|
||||
Reference in New Issue
Block a user