mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 04:31:10 +00:00
test: speed up msteams directory tests
This commit is contained in:
@@ -4,12 +4,12 @@ import {
|
||||
expectDirectorySurface,
|
||||
} from "../../../test/helpers/plugins/directory.js";
|
||||
import type { OpenClawConfig, RuntimeEnv } from "../runtime-api.js";
|
||||
import { msteamsPlugin } from "./channel.js";
|
||||
import { msteamsDirectoryAdapter } from "./directory.js";
|
||||
import { resolveMSTeamsOutboundSessionRoute } from "./session-route.js";
|
||||
|
||||
function requireDirectorySelf(
|
||||
directory: typeof msteamsPlugin.directory | null | undefined,
|
||||
): NonNullable<NonNullable<typeof msteamsPlugin.directory>["self"]> {
|
||||
directory: typeof msteamsDirectoryAdapter | null | undefined,
|
||||
): NonNullable<(typeof msteamsDirectoryAdapter)["self"]> {
|
||||
if (!directory?.self) {
|
||||
throw new Error("expected msteams directory.self");
|
||||
}
|
||||
@@ -18,7 +18,7 @@ function requireDirectorySelf(
|
||||
|
||||
describe("msteams directory", () => {
|
||||
const runtimeEnv = createDirectoryTestRuntime() as RuntimeEnv;
|
||||
const directorySelf = requireDirectorySelf(msteamsPlugin.directory);
|
||||
const directorySelf = requireDirectorySelf(msteamsDirectoryAdapter);
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
@@ -68,7 +68,7 @@ describe("msteams directory", () => {
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
const directory = expectDirectorySurface(msteamsPlugin.directory);
|
||||
const directory = expectDirectorySurface(msteamsDirectoryAdapter);
|
||||
|
||||
await expect(
|
||||
directory.listPeers({
|
||||
@@ -111,7 +111,7 @@ describe("msteams directory", () => {
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
const directory = expectDirectorySurface(msteamsPlugin.directory);
|
||||
const directory = expectDirectorySurface(msteamsDirectoryAdapter);
|
||||
|
||||
await expect(
|
||||
directory.listPeers({
|
||||
|
||||
@@ -12,11 +12,6 @@ import {
|
||||
createAllowlistProviderGroupPolicyWarningCollector,
|
||||
projectConfigWarningCollector,
|
||||
} from "openclaw/plugin-sdk/channel-policy";
|
||||
import {
|
||||
createChannelDirectoryAdapter,
|
||||
createRuntimeDirectoryLiveAdapter,
|
||||
listDirectoryEntriesFromSources,
|
||||
} from "openclaw/plugin-sdk/directory-runtime";
|
||||
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
|
||||
import { createRuntimeOutboundDelegates } from "openclaw/plugin-sdk/outbound-runtime";
|
||||
import { createComputedAccountStatusAdapter } from "openclaw/plugin-sdk/status-helpers";
|
||||
@@ -33,6 +28,7 @@ import {
|
||||
type OpenClawConfig,
|
||||
} from "./channel-api.js";
|
||||
import { MSTeamsChannelConfigSchema } from "./config-schema.js";
|
||||
import { msteamsDirectoryAdapter } from "./directory.js";
|
||||
import { collectMSTeamsMutableAllowlistWarnings } from "./doctor.js";
|
||||
import { formatUnknownError } from "./errors.js";
|
||||
import { resolveMSTeamsGroupToolPolicy } from "./policy.js";
|
||||
@@ -416,50 +412,7 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
|
||||
hint: "<conversationId|user:ID|conversation:ID>",
|
||||
},
|
||||
},
|
||||
directory: createChannelDirectoryAdapter({
|
||||
self: async ({ cfg }) => {
|
||||
const creds = resolveMSTeamsCredentials(cfg.channels?.msteams);
|
||||
if (!creds) {
|
||||
return null;
|
||||
}
|
||||
return { kind: "user" as const, id: creds.appId, name: creds.appId };
|
||||
},
|
||||
listPeers: async ({ cfg, query, limit }) =>
|
||||
listDirectoryEntriesFromSources({
|
||||
kind: "user",
|
||||
sources: [
|
||||
cfg.channels?.msteams?.allowFrom ?? [],
|
||||
Object.keys(cfg.channels?.msteams?.dms ?? {}),
|
||||
],
|
||||
query,
|
||||
limit,
|
||||
normalizeId: (raw) => {
|
||||
const normalized = normalizeMSTeamsMessagingTarget(raw) ?? raw;
|
||||
const lowered = normalized.toLowerCase();
|
||||
if (lowered.startsWith("user:") || lowered.startsWith("conversation:")) {
|
||||
return normalized;
|
||||
}
|
||||
return `user:${normalized}`;
|
||||
},
|
||||
}),
|
||||
listGroups: async ({ cfg, query, limit }) =>
|
||||
listDirectoryEntriesFromSources({
|
||||
kind: "group",
|
||||
sources: [
|
||||
Object.values(cfg.channels?.msteams?.teams ?? {}).flatMap((team) =>
|
||||
Object.keys(team.channels ?? {}),
|
||||
),
|
||||
],
|
||||
query,
|
||||
limit,
|
||||
normalizeId: (raw) => `conversation:${raw.replace(/^conversation:/i, "").trim()}`,
|
||||
}),
|
||||
...createRuntimeDirectoryLiveAdapter({
|
||||
getRuntime: loadMSTeamsChannelRuntime,
|
||||
listPeersLive: (runtime) => runtime.listMSTeamsDirectoryPeersLive,
|
||||
listGroupsLive: (runtime) => runtime.listMSTeamsDirectoryGroupsLive,
|
||||
}),
|
||||
}),
|
||||
directory: msteamsDirectoryAdapter,
|
||||
resolver: {
|
||||
resolveTargets: async ({ cfg, inputs, kind, runtime }) => {
|
||||
const results = inputs.map((input) => ({
|
||||
|
||||
60
extensions/msteams/src/directory.ts
Normal file
60
extensions/msteams/src/directory.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
createChannelDirectoryAdapter,
|
||||
createRuntimeDirectoryLiveAdapter,
|
||||
listDirectoryEntriesFromSources,
|
||||
} from "openclaw/plugin-sdk/directory-runtime";
|
||||
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
|
||||
import type { ChannelPlugin } from "./channel-api.js";
|
||||
import { normalizeMSTeamsMessagingTarget } from "./resolve-allowlist.js";
|
||||
import { resolveMSTeamsCredentials } from "./token.js";
|
||||
|
||||
const loadMSTeamsChannelRuntime = createLazyRuntimeNamedExport(
|
||||
() => import("./channel.runtime.js"),
|
||||
"msTeamsChannelRuntime",
|
||||
);
|
||||
|
||||
export const msteamsDirectoryAdapter: NonNullable<ChannelPlugin["directory"]> =
|
||||
createChannelDirectoryAdapter({
|
||||
self: async ({ cfg }) => {
|
||||
const creds = resolveMSTeamsCredentials(cfg.channels?.msteams);
|
||||
if (!creds) {
|
||||
return null;
|
||||
}
|
||||
return { kind: "user" as const, id: creds.appId, name: creds.appId };
|
||||
},
|
||||
listPeers: async ({ cfg, query, limit }) =>
|
||||
listDirectoryEntriesFromSources({
|
||||
kind: "user",
|
||||
sources: [
|
||||
cfg.channels?.msteams?.allowFrom ?? [],
|
||||
Object.keys(cfg.channels?.msteams?.dms ?? {}),
|
||||
],
|
||||
query,
|
||||
limit,
|
||||
normalizeId: (raw) => {
|
||||
const normalized = normalizeMSTeamsMessagingTarget(raw) ?? raw;
|
||||
const lowered = normalized.toLowerCase();
|
||||
if (lowered.startsWith("user:") || lowered.startsWith("conversation:")) {
|
||||
return normalized;
|
||||
}
|
||||
return `user:${normalized}`;
|
||||
},
|
||||
}),
|
||||
listGroups: async ({ cfg, query, limit }) =>
|
||||
listDirectoryEntriesFromSources({
|
||||
kind: "group",
|
||||
sources: [
|
||||
Object.values(cfg.channels?.msteams?.teams ?? {}).flatMap((team) =>
|
||||
Object.keys(team.channels ?? {}),
|
||||
),
|
||||
],
|
||||
query,
|
||||
limit,
|
||||
normalizeId: (raw) => `conversation:${raw.replace(/^conversation:/i, "").trim()}`,
|
||||
}),
|
||||
...createRuntimeDirectoryLiveAdapter({
|
||||
getRuntime: loadMSTeamsChannelRuntime,
|
||||
listPeersLive: (runtime) => runtime.listMSTeamsDirectoryPeersLive,
|
||||
listGroupsLive: (runtime) => runtime.listMSTeamsDirectoryGroupsLive,
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user