test: share channel directory id assertions

This commit is contained in:
Peter Steinberger
2026-04-20 23:15:40 +01:00
parent da5a6b68bd
commit 431e33b567
4 changed files with 42 additions and 122 deletions

View File

@@ -1,10 +1,7 @@
import type {
BaseProbeResult,
BaseTokenResolution,
ChannelDirectoryEntry,
} from "openclaw/plugin-sdk/channel-contract";
import type { BaseProbeResult, BaseTokenResolution } from "openclaw/plugin-sdk/channel-contract";
import type { OpenClawConfig } from "openclaw/plugin-sdk/testing";
import { describe, expect, expectTypeOf, it } from "vitest";
import { expectDirectoryIds } from "../../../test/helpers/channels/directory-ids.js";
import {
listDiscordDirectoryGroupsFromConfig,
listDiscordDirectoryPeersFromConfig,
@@ -12,43 +9,6 @@ import {
import type { DiscordProbe } from "./probe.js";
import type { DiscordTokenResolution } from "./token.js";
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 ? sortDirectoryIds(ids) : ids).toEqual(
options?.sorted ? sortDirectoryIds(expected) : expected,
);
}
function compareDirectoryIds(left: string, right: string) {
return left < right ? -1 : left > right ? 1 : 0;
}
function sortDirectoryIds(values: string[]) {
return values.toSorted(compareDirectoryIds);
}
describe("Discord directory contract", () => {
it("keeps public probe and token resolution aligned with base contracts", () => {
expectTypeOf<DiscordProbe>().toMatchTypeOf<BaseProbeResult>();

View File

@@ -1,49 +1,13 @@
import type { BaseProbeResult, ChannelDirectoryEntry } from "openclaw/plugin-sdk/channel-contract";
import type { BaseProbeResult } from "openclaw/plugin-sdk/channel-contract";
import type { OpenClawConfig } from "openclaw/plugin-sdk/testing";
import { describe, expect, expectTypeOf, it } from "vitest";
import { expectDirectoryIds } from "../../../test/helpers/channels/directory-ids.js";
import {
listSlackDirectoryGroupsFromConfig,
listSlackDirectoryPeersFromConfig,
} from "../directory-contract-api.js";
import type { SlackProbe } from "./probe.js";
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 ? sortDirectoryIds(ids) : ids).toEqual(
options?.sorted ? sortDirectoryIds(expected) : expected,
);
}
function compareDirectoryIds(left: string, right: string) {
return left < right ? -1 : left > right ? 1 : 0;
}
function sortDirectoryIds(values: string[]) {
return values.toSorted(compareDirectoryIds);
}
describe("Slack directory contract", () => {
it("keeps public probe aligned with base contract", () => {
expectTypeOf<SlackProbe>().toMatchTypeOf<BaseProbeResult>();

View File

@@ -1,10 +1,7 @@
import type {
BaseProbeResult,
BaseTokenResolution,
ChannelDirectoryEntry,
} from "openclaw/plugin-sdk/channel-contract";
import type { BaseProbeResult, BaseTokenResolution } from "openclaw/plugin-sdk/channel-contract";
import { type OpenClawConfig, withEnvAsync } from "openclaw/plugin-sdk/testing";
import { describe, expect, expectTypeOf, it } from "vitest";
import { expectDirectoryIds } from "../../../test/helpers/channels/directory-ids.js";
import {
listTelegramDirectoryGroupsFromConfig,
listTelegramDirectoryPeersFromConfig,
@@ -12,43 +9,6 @@ import {
import type { TelegramProbe } from "./probe.js";
import type { TelegramTokenResolution } from "./token.js";
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 ? sortDirectoryIds(ids) : ids).toEqual(
options?.sorted ? sortDirectoryIds(expected) : expected,
);
}
function compareDirectoryIds(left: string, right: string) {
return left < right ? -1 : left > right ? 1 : 0;
}
function sortDirectoryIds(values: string[]) {
return values.toSorted(compareDirectoryIds);
}
describe("Telegram directory contract", () => {
it("keeps public probe and token resolution aligned with base contracts", () => {
expectTypeOf<TelegramProbe>().toMatchTypeOf<BaseProbeResult>();

View File

@@ -0,0 +1,36 @@
import type { ChannelDirectoryEntry } from "openclaw/plugin-sdk/channel-contract";
import type { OpenClawConfig } from "openclaw/plugin-sdk/testing";
import { expect } from "vitest";
export type DirectoryListFn = (params: {
cfg: OpenClawConfig;
accountId?: string;
query?: string | null;
limit?: number | null;
}) => Promise<ChannelDirectoryEntry[]>;
export async function expectDirectoryIds(
listFn: DirectoryListFn,
cfg: OpenClawConfig,
expected: string[],
options?: { sorted?: boolean },
) {
const entries = await listFn({
cfg,
accountId: "default",
query: null,
limit: null,
});
const ids = entries.map((entry) => entry.id);
expect(options?.sorted ? sortDirectoryIds(ids) : ids).toEqual(
options?.sorted ? sortDirectoryIds(expected) : expected,
);
}
function compareDirectoryIds(left: string, right: string) {
return left < right ? -1 : left > right ? 1 : 0;
}
function sortDirectoryIds(values: string[]) {
return values.toSorted(compareDirectoryIds);
}