mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:50:42 +00:00
test(extensions): move channel contracts out of core
This commit is contained in:
@@ -185,4 +185,15 @@ describe("non-extension test boundaries", () => {
|
||||
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps extension channel contract helpers on the public testing surface", () => {
|
||||
const files = walkCode(path.join(repoRoot, "extensions"));
|
||||
|
||||
const offenders = files.filter((file) => {
|
||||
const source = fs.readFileSync(path.join(repoRoot, file), "utf8");
|
||||
return source.includes("src/channels/plugins/contracts/test-helpers.js");
|
||||
});
|
||||
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { it } from "vitest";
|
||||
import { expectChannelInboundContextContract } from "../../../src/channels/plugins/contracts/test-helpers.js";
|
||||
import { resolveRelativeBundledPluginPublicModuleId } from "../../../src/test-utils/bundled-plugin-public-surface.js";
|
||||
|
||||
type BuildFinalizedDiscordDirectInboundContext =
|
||||
() => import("../../../src/auto-reply/templating.js").MsgContext;
|
||||
|
||||
const discordInboundContextHarnessModuleId = resolveRelativeBundledPluginPublicModuleId({
|
||||
fromModuleUrl: import.meta.url,
|
||||
pluginId: "discord",
|
||||
artifactBasename: "src/monitor/inbound-context.test-helpers.js",
|
||||
});
|
||||
|
||||
async function getBuildFinalizedDiscordDirectInboundContext(): Promise<BuildFinalizedDiscordDirectInboundContext> {
|
||||
const module = (await import(discordInboundContextHarnessModuleId)) as {
|
||||
buildFinalizedDiscordDirectInboundContext: BuildFinalizedDiscordDirectInboundContext;
|
||||
};
|
||||
return module.buildFinalizedDiscordDirectInboundContext;
|
||||
}
|
||||
|
||||
export function installDiscordInboundContractSuite() {
|
||||
it("keeps inbound context finalized", async () => {
|
||||
const buildContext = await getBuildFinalizedDiscordDirectInboundContext();
|
||||
const ctx = buildContext();
|
||||
|
||||
expectChannelInboundContextContract(ctx);
|
||||
});
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import { it } from "vitest";
|
||||
import { finalizeInboundContext } from "../../../src/auto-reply/reply/inbound-context.js";
|
||||
import { expectChannelInboundContextContract } from "../../../src/channels/plugins/contracts/test-helpers.js";
|
||||
|
||||
export function installSignalInboundContractSuite() {
|
||||
it("keeps inbound context finalized", () => {
|
||||
const ctx = finalizeInboundContext({
|
||||
Body: "Alice: hi",
|
||||
BodyForAgent: "hi",
|
||||
RawBody: "hi",
|
||||
CommandBody: "hi",
|
||||
BodyForCommands: "hi",
|
||||
From: "group:g1",
|
||||
To: "group:g1",
|
||||
SessionKey: "agent:main:signal:group:g1",
|
||||
AccountId: "default",
|
||||
ChatType: "group",
|
||||
ConversationLabel: "Alice",
|
||||
GroupSubject: "Test Group",
|
||||
SenderName: "Alice",
|
||||
SenderId: "+15550001111",
|
||||
Provider: "signal",
|
||||
Surface: "signal",
|
||||
MessageSid: "1700000000000",
|
||||
OriginatingChannel: "signal",
|
||||
OriginatingTo: "group:g1",
|
||||
CommandAuthorized: true,
|
||||
});
|
||||
|
||||
expectChannelInboundContextContract(ctx);
|
||||
});
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
import { expect, it } from "vitest";
|
||||
import type { MsgContext } from "../../../src/auto-reply/templating.js";
|
||||
import { expectChannelInboundContextContract } from "../../../src/channels/plugins/contracts/test-helpers.js";
|
||||
import type { OpenClawConfig } from "../../../src/config/config.js";
|
||||
import { resolveRelativeBundledPluginPublicModuleId } from "../../../src/test-utils/bundled-plugin-public-surface.js";
|
||||
import { withTempHome } from "../temp-home.js";
|
||||
|
||||
type ResolvedSlackAccount = {
|
||||
accountId: string;
|
||||
enabled: boolean;
|
||||
botTokenSource: string;
|
||||
appTokenSource: string;
|
||||
userTokenSource: string;
|
||||
config: {
|
||||
replyToMode?: unknown;
|
||||
replyToModeByChatType?: unknown;
|
||||
dm?: unknown;
|
||||
};
|
||||
replyToMode?: unknown;
|
||||
replyToModeByChatType?: unknown;
|
||||
dm?: unknown;
|
||||
};
|
||||
|
||||
type SlackMessageEvent = {
|
||||
channel: string;
|
||||
channel_type?: string;
|
||||
user?: string;
|
||||
text?: string;
|
||||
ts: string;
|
||||
};
|
||||
|
||||
type SlackPrepareResult = { ctxPayload: MsgContext } | null | undefined;
|
||||
|
||||
type SlackTestApi = {
|
||||
createInboundSlackTestContext: (params: { cfg: OpenClawConfig }) => {
|
||||
resolveUserName?: () => Promise<unknown>;
|
||||
};
|
||||
prepareSlackMessage: (params: {
|
||||
ctx: {
|
||||
resolveUserName?: () => Promise<unknown>;
|
||||
};
|
||||
account: ResolvedSlackAccount;
|
||||
message: SlackMessageEvent;
|
||||
opts: { source: string };
|
||||
}) => Promise<SlackPrepareResult>;
|
||||
};
|
||||
|
||||
const slackPrepareTestApiModuleId = resolveRelativeBundledPluginPublicModuleId({
|
||||
fromModuleUrl: import.meta.url,
|
||||
pluginId: "slack",
|
||||
artifactBasename: "inbound-contract-test-api.js",
|
||||
});
|
||||
|
||||
let slackTestApiPromise: Promise<SlackTestApi> | undefined;
|
||||
|
||||
async function loadSlackTestApi(): Promise<SlackTestApi> {
|
||||
slackTestApiPromise ??= import(slackPrepareTestApiModuleId) as Promise<SlackTestApi>;
|
||||
return await slackTestApiPromise;
|
||||
}
|
||||
|
||||
function createSlackAccount(config: ResolvedSlackAccount["config"] = {}): ResolvedSlackAccount {
|
||||
return {
|
||||
accountId: "default",
|
||||
enabled: true,
|
||||
botTokenSource: "config",
|
||||
appTokenSource: "config",
|
||||
userTokenSource: "none",
|
||||
config,
|
||||
replyToMode: config.replyToMode,
|
||||
replyToModeByChatType: config.replyToModeByChatType,
|
||||
dm: config.dm,
|
||||
};
|
||||
}
|
||||
|
||||
function createSlackMessage(overrides: Partial<SlackMessageEvent>): SlackMessageEvent {
|
||||
return {
|
||||
channel: "D123",
|
||||
channel_type: "im",
|
||||
user: "U1",
|
||||
text: "hi",
|
||||
ts: "1.000",
|
||||
...overrides,
|
||||
} as SlackMessageEvent;
|
||||
}
|
||||
|
||||
export function installSlackInboundContractSuite() {
|
||||
it("keeps inbound context finalized", async () => {
|
||||
await withTempHome(async () => {
|
||||
const { createInboundSlackTestContext, prepareSlackMessage } = await loadSlackTestApi();
|
||||
const ctx = createInboundSlackTestContext({
|
||||
cfg: {
|
||||
channels: { slack: { enabled: true } },
|
||||
} as OpenClawConfig,
|
||||
});
|
||||
ctx.resolveUserName = async () => ({ name: "Alice" }) as never;
|
||||
|
||||
const prepared = await prepareSlackMessage({
|
||||
ctx,
|
||||
account: createSlackAccount(),
|
||||
message: createSlackMessage({}),
|
||||
opts: { source: "message" },
|
||||
});
|
||||
|
||||
expect(prepared).toBeTruthy();
|
||||
expectChannelInboundContextContract(prepared!.ctxPayload);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
import { it } from "vitest";
|
||||
import { expectChannelInboundContextContract } from "../../../src/channels/plugins/contracts/test-helpers.js";
|
||||
import type { OpenClawConfig } from "../../../src/config/config.js";
|
||||
import { resolveRelativeBundledPluginPublicModuleId } from "../../../src/test-utils/bundled-plugin-public-surface.js";
|
||||
|
||||
const telegramHarnessModuleId = resolveRelativeBundledPluginPublicModuleId({
|
||||
fromModuleUrl: import.meta.url,
|
||||
pluginId: "telegram",
|
||||
artifactBasename: "src/bot-message-context.test-harness.js",
|
||||
});
|
||||
|
||||
async function buildTelegramMessageContextForTest(params: {
|
||||
cfg: OpenClawConfig;
|
||||
message: Record<string, unknown>;
|
||||
}) {
|
||||
const telegramHarnessModule = (await import(telegramHarnessModuleId)) as {
|
||||
buildTelegramMessageContextForTest: (params: {
|
||||
cfg: OpenClawConfig;
|
||||
message: Record<string, unknown>;
|
||||
}) => Promise<
|
||||
{ ctxPayload: import("../../../src/auto-reply/templating.js").MsgContext } | null | undefined
|
||||
>;
|
||||
};
|
||||
return await telegramHarnessModule.buildTelegramMessageContextForTest(params);
|
||||
}
|
||||
|
||||
export function installTelegramInboundContractSuite() {
|
||||
it("keeps inbound context finalized", async () => {
|
||||
const context = await buildTelegramMessageContextForTest({
|
||||
cfg: {
|
||||
agents: {
|
||||
defaults: {
|
||||
envelopeTimezone: "utc",
|
||||
},
|
||||
},
|
||||
channels: {
|
||||
telegram: {
|
||||
groupPolicy: "open",
|
||||
groups: { "*": { requireMention: false } },
|
||||
},
|
||||
},
|
||||
} satisfies OpenClawConfig,
|
||||
message: {
|
||||
chat: { id: 42, type: "group", title: "Ops" },
|
||||
text: "hello",
|
||||
date: 1736380800,
|
||||
message_id: 2,
|
||||
from: {
|
||||
id: 99,
|
||||
first_name: "Ada",
|
||||
last_name: "Lovelace",
|
||||
username: "ada",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const payload = context?.ctxPayload;
|
||||
if (!payload) {
|
||||
throw new Error("expected telegram inbound payload");
|
||||
}
|
||||
expectChannelInboundContextContract(payload);
|
||||
});
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import { it } from "vitest";
|
||||
import { finalizeInboundContext } from "../../../src/auto-reply/reply/inbound-context.js";
|
||||
import { expectChannelInboundContextContract } from "../../../src/channels/plugins/contracts/test-helpers.js";
|
||||
|
||||
export function installWhatsAppInboundContractSuite() {
|
||||
it("keeps inbound context finalized", () => {
|
||||
const ctx = finalizeInboundContext({
|
||||
Body: "Alice: hi",
|
||||
BodyForAgent: "hi",
|
||||
RawBody: "hi",
|
||||
CommandBody: "hi",
|
||||
BodyForCommands: "hi",
|
||||
From: "123@g.us",
|
||||
To: "+15550001111",
|
||||
SessionKey: "agent:main:whatsapp:group:123",
|
||||
AccountId: "default",
|
||||
ChatType: "group",
|
||||
ConversationLabel: "123@g.us",
|
||||
GroupSubject: "Test Group",
|
||||
SenderName: "Alice",
|
||||
SenderId: "alice@s.whatsapp.net",
|
||||
SenderE164: "+15550002222",
|
||||
Provider: "whatsapp",
|
||||
Surface: "whatsapp",
|
||||
MessageSid: "msg1",
|
||||
OriginatingChannel: "whatsapp",
|
||||
OriginatingTo: "123@g.us",
|
||||
CommandAuthorized: true,
|
||||
});
|
||||
|
||||
expectChannelInboundContextContract(ctx);
|
||||
});
|
||||
}
|
||||
@@ -1,452 +0,0 @@
|
||||
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||
import type {
|
||||
BaseProbeResult,
|
||||
BaseTokenResolution,
|
||||
ChannelDirectoryEntry,
|
||||
} from "../../../src/channels/plugins/types.js";
|
||||
import type { OpenClawConfig } from "../../../src/config/config.js";
|
||||
import type { LineProbeResult } from "../../../src/plugin-sdk/line.js";
|
||||
import { resolveRelativeBundledPluginPublicModuleId } from "../../../src/test-utils/bundled-plugin-public-surface.js";
|
||||
import { withEnvAsync } from "../../../src/test-utils/env.js";
|
||||
|
||||
type DiscordDirectoryContractApiSurface = {
|
||||
listDiscordDirectoryPeersFromConfig: DirectoryListFn;
|
||||
listDiscordDirectoryGroupsFromConfig: DirectoryListFn;
|
||||
};
|
||||
type DiscordProbe = BaseProbeResult;
|
||||
type DiscordTokenResolution = BaseTokenResolution;
|
||||
type IMessageProbe = BaseProbeResult;
|
||||
type SignalProbe = BaseProbeResult;
|
||||
type SlackDirectoryContractApiSurface = {
|
||||
listSlackDirectoryPeersFromConfig: DirectoryListFn;
|
||||
listSlackDirectoryGroupsFromConfig: DirectoryListFn;
|
||||
};
|
||||
type SlackProbe = BaseProbeResult;
|
||||
type TelegramDirectoryContractApiSurface = {
|
||||
listTelegramDirectoryPeersFromConfig: DirectoryListFn;
|
||||
listTelegramDirectoryGroupsFromConfig: DirectoryListFn;
|
||||
};
|
||||
type TelegramProbe = BaseProbeResult;
|
||||
type TelegramTokenResolution = BaseTokenResolution;
|
||||
type WhatsAppDirectoryContractApiSurface = {
|
||||
listWhatsAppDirectoryPeersFromConfig: DirectoryListFn;
|
||||
listWhatsAppDirectoryGroupsFromConfig: DirectoryListFn;
|
||||
};
|
||||
|
||||
let discordDirectoryContractApi: Promise<DiscordDirectoryContractApiSurface> | undefined;
|
||||
let slackDirectoryContractApi: Promise<SlackDirectoryContractApiSurface> | undefined;
|
||||
let telegramDirectoryContractApi: Promise<TelegramDirectoryContractApiSurface> | undefined;
|
||||
let whatsappDirectoryContractApi: Promise<WhatsAppDirectoryContractApiSurface> | undefined;
|
||||
|
||||
async function importDirectoryContractApi<T extends object>(pluginId: string): Promise<T> {
|
||||
const moduleId = resolveRelativeBundledPluginPublicModuleId({
|
||||
fromModuleUrl: import.meta.url,
|
||||
pluginId,
|
||||
artifactBasename: "directory-contract-api.js",
|
||||
});
|
||||
return (await import(moduleId)) as T;
|
||||
}
|
||||
|
||||
function getDiscordDirectoryContractApi(): Promise<DiscordDirectoryContractApiSurface> {
|
||||
discordDirectoryContractApi ??=
|
||||
importDirectoryContractApi<DiscordDirectoryContractApiSurface>("discord");
|
||||
return discordDirectoryContractApi;
|
||||
}
|
||||
|
||||
function getSlackDirectoryContractApi(): Promise<SlackDirectoryContractApiSurface> {
|
||||
slackDirectoryContractApi ??=
|
||||
importDirectoryContractApi<SlackDirectoryContractApiSurface>("slack");
|
||||
return slackDirectoryContractApi;
|
||||
}
|
||||
|
||||
function getTelegramDirectoryContractApi(): Promise<TelegramDirectoryContractApiSurface> {
|
||||
telegramDirectoryContractApi ??=
|
||||
importDirectoryContractApi<TelegramDirectoryContractApiSurface>("telegram");
|
||||
return telegramDirectoryContractApi;
|
||||
}
|
||||
|
||||
function getWhatsAppDirectoryContractApi(): Promise<WhatsAppDirectoryContractApiSurface> {
|
||||
whatsappDirectoryContractApi ??=
|
||||
importDirectoryContractApi<WhatsAppDirectoryContractApiSurface>("whatsapp");
|
||||
return whatsappDirectoryContractApi;
|
||||
}
|
||||
|
||||
type DirectoryListFn = (params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string;
|
||||
query?: string | null;
|
||||
limit?: number | null;
|
||||
}) => Promise<ChannelDirectoryEntry[]>;
|
||||
|
||||
async function listDirectoryEntriesWithDefaults(listFn: DirectoryListFn, cfg: OpenClawConfig) {
|
||||
return await listFn({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
});
|
||||
}
|
||||
|
||||
async function expectDirectoryIds(
|
||||
listFn: DirectoryListFn,
|
||||
cfg: OpenClawConfig,
|
||||
expected: string[],
|
||||
options?: { sorted?: boolean },
|
||||
) {
|
||||
const entries = await listDirectoryEntriesWithDefaults(listFn, cfg);
|
||||
const ids = entries.map((entry) => entry.id);
|
||||
expect(options?.sorted ? ids.toSorted() : ids).toEqual(expected);
|
||||
}
|
||||
|
||||
export function describeDiscordPluginsCoreExtensionContract() {
|
||||
describe("discord plugins-core extension contract", () => {
|
||||
it("DiscordProbe satisfies BaseProbeResult", () => {
|
||||
expectTypeOf<DiscordProbe>().toMatchTypeOf<BaseProbeResult>();
|
||||
});
|
||||
|
||||
it("Discord token resolution satisfies BaseTokenResolution", () => {
|
||||
expectTypeOf<DiscordTokenResolution>().toMatchTypeOf<BaseTokenResolution>();
|
||||
});
|
||||
|
||||
it("lists peers/groups from config (numeric ids only)", async () => {
|
||||
const { listDiscordDirectoryGroupsFromConfig, listDiscordDirectoryPeersFromConfig } =
|
||||
await getDiscordDirectoryContractApi();
|
||||
const cfg = {
|
||||
channels: {
|
||||
discord: {
|
||||
token: "discord-test",
|
||||
dm: { allowFrom: ["<@111>", "<@!333>", "nope"] },
|
||||
dms: { "222": {} },
|
||||
guilds: {
|
||||
"123": {
|
||||
users: ["<@12345>", " discord:444 ", "not-an-id"],
|
||||
channels: {
|
||||
"555": {},
|
||||
"<#777>": {},
|
||||
"channel:666": {},
|
||||
general: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
await expectDirectoryIds(
|
||||
listDiscordDirectoryPeersFromConfig,
|
||||
cfg,
|
||||
["user:111", "user:12345", "user:222", "user:333", "user:444"],
|
||||
{ sorted: true },
|
||||
);
|
||||
await expectDirectoryIds(
|
||||
listDiscordDirectoryGroupsFromConfig,
|
||||
cfg,
|
||||
["channel:555", "channel:666", "channel:777"],
|
||||
{
|
||||
sorted: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps directories readable when tokens are unresolved SecretRefs", async () => {
|
||||
const { listDiscordDirectoryGroupsFromConfig, listDiscordDirectoryPeersFromConfig } =
|
||||
await getDiscordDirectoryContractApi();
|
||||
const envSecret = {
|
||||
source: "env",
|
||||
provider: "default",
|
||||
id: "MISSING_TEST_SECRET",
|
||||
} as const;
|
||||
const cfg = {
|
||||
channels: {
|
||||
discord: {
|
||||
token: envSecret,
|
||||
dm: { allowFrom: ["<@111>"] },
|
||||
guilds: {
|
||||
"123": {
|
||||
channels: {
|
||||
"555": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
await expectDirectoryIds(listDiscordDirectoryPeersFromConfig, cfg, ["user:111"]);
|
||||
await expectDirectoryIds(listDiscordDirectoryGroupsFromConfig, cfg, ["channel:555"]);
|
||||
});
|
||||
|
||||
it("applies query and limit filtering for config-backed directories", async () => {
|
||||
const { listDiscordDirectoryGroupsFromConfig } = await getDiscordDirectoryContractApi();
|
||||
const cfg = {
|
||||
channels: {
|
||||
discord: {
|
||||
token: "discord-test",
|
||||
guilds: {
|
||||
"123": {
|
||||
channels: {
|
||||
"555": {},
|
||||
"666": {},
|
||||
"777": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
const groups = await listDiscordDirectoryGroupsFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: "666",
|
||||
limit: 5,
|
||||
});
|
||||
expect(groups.map((entry) => entry.id)).toEqual(["channel:666"]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function describeSlackPluginsCoreExtensionContract() {
|
||||
describe("slack plugins-core extension contract", () => {
|
||||
it("SlackProbe satisfies BaseProbeResult", () => {
|
||||
expectTypeOf<SlackProbe>().toMatchTypeOf<BaseProbeResult>();
|
||||
});
|
||||
|
||||
it("lists peers/groups from config", async () => {
|
||||
const { listSlackDirectoryGroupsFromConfig, listSlackDirectoryPeersFromConfig } =
|
||||
await getSlackDirectoryContractApi();
|
||||
const cfg = {
|
||||
channels: {
|
||||
slack: {
|
||||
botToken: "xoxb-test",
|
||||
appToken: "xapp-test",
|
||||
dm: { allowFrom: ["U123", "user:U999"] },
|
||||
dms: { U234: {} },
|
||||
channels: { C111: { users: ["U777"] } },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
await expectDirectoryIds(
|
||||
listSlackDirectoryPeersFromConfig,
|
||||
cfg,
|
||||
["user:u123", "user:u234", "user:u777", "user:u999"],
|
||||
{ sorted: true },
|
||||
);
|
||||
await expectDirectoryIds(listSlackDirectoryGroupsFromConfig, cfg, ["channel:c111"]);
|
||||
});
|
||||
|
||||
it("keeps directories readable when tokens are unresolved SecretRefs", async () => {
|
||||
const { listSlackDirectoryGroupsFromConfig, listSlackDirectoryPeersFromConfig } =
|
||||
await getSlackDirectoryContractApi();
|
||||
const envSecret = {
|
||||
source: "env",
|
||||
provider: "default",
|
||||
id: "MISSING_TEST_SECRET",
|
||||
} as const;
|
||||
const cfg = {
|
||||
channels: {
|
||||
slack: {
|
||||
botToken: envSecret,
|
||||
appToken: envSecret,
|
||||
dm: { allowFrom: ["U123"] },
|
||||
channels: { C111: {} },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
await expectDirectoryIds(listSlackDirectoryPeersFromConfig, cfg, ["user:u123"]);
|
||||
await expectDirectoryIds(listSlackDirectoryGroupsFromConfig, cfg, ["channel:c111"]);
|
||||
});
|
||||
|
||||
it("applies query and limit filtering for config-backed directories", async () => {
|
||||
const { listSlackDirectoryPeersFromConfig } = await getSlackDirectoryContractApi();
|
||||
const cfg = {
|
||||
channels: {
|
||||
slack: {
|
||||
botToken: "xoxb-test",
|
||||
appToken: "xapp-test",
|
||||
dm: { allowFrom: ["U100", "U200"] },
|
||||
dms: { U300: {} },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
const peers = await listSlackDirectoryPeersFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: "user:u",
|
||||
limit: 2,
|
||||
});
|
||||
expect(peers).toHaveLength(2);
|
||||
expect(peers.every((entry) => entry.id.startsWith("user:u"))).toBe(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function describeTelegramPluginsCoreExtensionContract() {
|
||||
describe("telegram plugins-core extension contract", () => {
|
||||
it("TelegramProbe satisfies BaseProbeResult", () => {
|
||||
expectTypeOf<TelegramProbe>().toMatchTypeOf<BaseProbeResult>();
|
||||
});
|
||||
|
||||
it("Telegram token resolution satisfies BaseTokenResolution", () => {
|
||||
expectTypeOf<TelegramTokenResolution>().toMatchTypeOf<BaseTokenResolution>();
|
||||
});
|
||||
|
||||
it("lists peers/groups from config", async () => {
|
||||
const { listTelegramDirectoryGroupsFromConfig, listTelegramDirectoryPeersFromConfig } =
|
||||
await getTelegramDirectoryContractApi();
|
||||
const cfg = {
|
||||
channels: {
|
||||
telegram: {
|
||||
botToken: "telegram-test",
|
||||
allowFrom: ["123", "alice", "tg:@bob"],
|
||||
dms: { "456": {} },
|
||||
groups: { "-1001": {}, "*": {} },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
await expectDirectoryIds(
|
||||
listTelegramDirectoryPeersFromConfig,
|
||||
cfg,
|
||||
["123", "456", "@alice", "@bob"],
|
||||
{
|
||||
sorted: true,
|
||||
},
|
||||
);
|
||||
await expectDirectoryIds(listTelegramDirectoryGroupsFromConfig, cfg, ["-1001"]);
|
||||
});
|
||||
|
||||
it("keeps fallback semantics when accountId is omitted", async () => {
|
||||
const { listTelegramDirectoryGroupsFromConfig, listTelegramDirectoryPeersFromConfig } =
|
||||
await getTelegramDirectoryContractApi();
|
||||
await withEnvAsync({ TELEGRAM_BOT_TOKEN: "tok-env" }, async () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
telegram: {
|
||||
allowFrom: ["alice"],
|
||||
groups: { "-1001": {} },
|
||||
accounts: {
|
||||
work: {
|
||||
botToken: "tok-work",
|
||||
allowFrom: ["bob"],
|
||||
groups: { "-2002": {} },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
await expectDirectoryIds(listTelegramDirectoryPeersFromConfig, cfg, ["@alice"]);
|
||||
await expectDirectoryIds(listTelegramDirectoryGroupsFromConfig, cfg, ["-1001"]);
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps directories readable when tokens are unresolved SecretRefs", async () => {
|
||||
const { listTelegramDirectoryGroupsFromConfig, listTelegramDirectoryPeersFromConfig } =
|
||||
await getTelegramDirectoryContractApi();
|
||||
const envSecret = {
|
||||
source: "env",
|
||||
provider: "default",
|
||||
id: "MISSING_TEST_SECRET",
|
||||
} as const;
|
||||
const cfg = {
|
||||
channels: {
|
||||
telegram: {
|
||||
botToken: envSecret,
|
||||
allowFrom: ["alice"],
|
||||
groups: { "-1001": {} },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
await expectDirectoryIds(listTelegramDirectoryPeersFromConfig, cfg, ["@alice"]);
|
||||
await expectDirectoryIds(listTelegramDirectoryGroupsFromConfig, cfg, ["-1001"]);
|
||||
});
|
||||
|
||||
it("applies query and limit filtering for config-backed directories", async () => {
|
||||
const { listTelegramDirectoryGroupsFromConfig } = await getTelegramDirectoryContractApi();
|
||||
const cfg = {
|
||||
channels: {
|
||||
telegram: {
|
||||
botToken: "telegram-test",
|
||||
groups: { "-1001": {}, "-1002": {}, "-2001": {} },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
const groups = await listTelegramDirectoryGroupsFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: "-100",
|
||||
limit: 1,
|
||||
});
|
||||
expect(groups.map((entry) => entry.id)).toEqual(["-1001"]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function describeWhatsAppPluginsCoreExtensionContract() {
|
||||
describe("whatsapp plugins-core extension contract", () => {
|
||||
it("lists peers/groups from config", async () => {
|
||||
const { listWhatsAppDirectoryGroupsFromConfig, listWhatsAppDirectoryPeersFromConfig } =
|
||||
await getWhatsAppDirectoryContractApi();
|
||||
const cfg = {
|
||||
channels: {
|
||||
whatsapp: {
|
||||
allowFrom: ["+15550000000", "*", "123@g.us"],
|
||||
groups: { "999@g.us": { requireMention: true }, "*": {} },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
await expectDirectoryIds(listWhatsAppDirectoryPeersFromConfig, cfg, ["+15550000000"]);
|
||||
await expectDirectoryIds(listWhatsAppDirectoryGroupsFromConfig, cfg, ["999@g.us"]);
|
||||
});
|
||||
|
||||
it("applies query and limit filtering for config-backed directories", async () => {
|
||||
const { listWhatsAppDirectoryGroupsFromConfig } = await getWhatsAppDirectoryContractApi();
|
||||
const cfg = {
|
||||
channels: {
|
||||
whatsapp: {
|
||||
groups: { "111@g.us": {}, "222@g.us": {}, "333@s.whatsapp.net": {} },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
const groups = await listWhatsAppDirectoryGroupsFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: "@g.us",
|
||||
limit: 1,
|
||||
});
|
||||
expect(groups.map((entry) => entry.id)).toEqual(["111@g.us"]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function describeSignalPluginsCoreExtensionContract() {
|
||||
describe("signal plugins-core extension contract", () => {
|
||||
it("SignalProbe satisfies BaseProbeResult", () => {
|
||||
expectTypeOf<SignalProbe>().toMatchTypeOf<BaseProbeResult>();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function describeIMessagePluginsCoreExtensionContract() {
|
||||
describe("imessage plugins-core extension contract", () => {
|
||||
it("IMessageProbe satisfies BaseProbeResult", () => {
|
||||
expectTypeOf<IMessageProbe>().toMatchTypeOf<BaseProbeResult>();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function describeLinePluginsCoreExtensionContract() {
|
||||
describe("line plugins-core extension contract", () => {
|
||||
it("LineProbeResult satisfies BaseProbeResult", () => {
|
||||
expectTypeOf<LineProbeResult>().toMatchTypeOf<BaseProbeResult>();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -43,11 +43,6 @@ describe("scripts/lib/channel-contract-test-plan.mjs", () => {
|
||||
runtime: "node",
|
||||
task: "contracts-channels",
|
||||
},
|
||||
{
|
||||
checkName: "checks-fast-contracts-channels-extensions",
|
||||
runtime: "node",
|
||||
task: "contracts-channels",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user