diff --git a/src/channels/plugins/contracts/test-helpers/surface-contract-registry.ts b/src/channels/plugins/contracts/test-helpers/surface-contract-registry.ts index 535c2a3514c..cb90c09cd3d 100644 --- a/src/channels/plugins/contracts/test-helpers/surface-contract-registry.ts +++ b/src/channels/plugins/contracts/test-helpers/surface-contract-registry.ts @@ -1,57 +1,15 @@ -import type { OpenClawConfig } from "../../../../config/config.js"; import type { ChannelId } from "../../channel-id.types.js"; -import type { ChannelPlugin } from "../../types.js"; -import { - getBundledChannelPlugin, - listBundledChannelPluginIds, - listBundledChannelPlugins, -} from "./bundled-channel-plugin-loader.js"; -import { channelPluginSurfaceKeys, type ChannelPluginSurface } from "./manifest.js"; - -type SurfaceContractEntry = { - id: string; - plugin: Pick< - ChannelPlugin, - | "id" - | "actions" - | "setup" - | "status" - | "outbound" - | "messaging" - | "threading" - | "directory" - | "gateway" - >; - surfaces: readonly ChannelPluginSurface[]; -}; - -type ThreadingContractEntry = { - id: string; - plugin: Pick; -}; +import { listBundledChannelPluginIds } from "./bundled-channel-plugin-loader.js"; type ThreadingContractRef = { id: ChannelId; }; -type DirectoryContractEntry = { - id: string; - plugin: Pick; - coverage: "lookups" | "presence"; - cfg?: OpenClawConfig; - accountId?: string; -}; - type DirectoryContractRef = { id: ChannelId; coverage: "lookups" | "presence"; }; -let surfaceContractRegistryCache: SurfaceContractEntry[] | undefined; -const surfaceContractEntryCache = new Map(); -let threadingContractRegistryCache: ThreadingContractEntry[] | undefined; -let directoryContractRegistryCache: DirectoryContractEntry[] | undefined; - const threadingContractPluginIds = new Set([ "bluebubbles", "discord", @@ -82,14 +40,6 @@ const directoryContractPluginIds = new Set([ "zalouser", ]); -function toSurfaceContractEntry(plugin: ChannelPlugin): SurfaceContractEntry { - return { - id: plugin.id, - plugin, - surfaces: channelPluginSurfaceKeys.filter((surface) => Boolean(plugin[surface])), - }; -} - function getBundledChannelPluginIdsForShard(params: { shardIndex: number; shardCount: number; @@ -99,31 +49,6 @@ function getBundledChannelPluginIdsForShard(params: { ); } -function getSurfaceContractEntry(id: ChannelId): SurfaceContractEntry | undefined { - if (surfaceContractEntryCache.has(id)) { - return surfaceContractEntryCache.get(id) ?? undefined; - } - const plugin = getBundledChannelPlugin(id); - const entry = plugin ? toSurfaceContractEntry(plugin) : null; - surfaceContractEntryCache.set(id, entry); - return entry ?? undefined; -} - -export function getSurfaceContractRegistry(): SurfaceContractEntry[] { - surfaceContractRegistryCache ??= listBundledChannelPlugins().map(toSurfaceContractEntry); - return surfaceContractRegistryCache; -} - -export function getSurfaceContractRegistryShard(params: { - shardIndex: number; - shardCount: number; -}): SurfaceContractEntry[] { - return getBundledChannelPluginIdsForShard(params).flatMap((id) => { - const entry = getSurfaceContractEntry(id); - return entry ? [entry] : []; - }); -} - export function getSurfaceContractRegistryShardIds(params: { shardIndex: number; shardCount: number; @@ -131,42 +56,6 @@ export function getSurfaceContractRegistryShardIds(params: { return getBundledChannelPluginIdsForShard(params); } -export function getThreadingContractRegistry(): ThreadingContractEntry[] { - threadingContractRegistryCache ??= listBundledChannelPluginIds() - .filter((id) => threadingContractPluginIds.has(id)) - .flatMap((id) => { - const entry = getSurfaceContractEntry(id); - return entry && entry.surfaces.includes("threading") - ? [ - { - id: entry.id, - plugin: entry.plugin, - }, - ] - : []; - }); - return threadingContractRegistryCache; -} - -export function getThreadingContractRegistryShard(params: { - shardIndex: number; - shardCount: number; -}): ThreadingContractEntry[] { - return getBundledChannelPluginIdsForShard(params) - .filter((id) => threadingContractPluginIds.has(id)) - .flatMap((id) => { - const entry = getSurfaceContractEntry(id); - return entry && entry.surfaces.includes("threading") - ? [ - { - id: entry.id, - plugin: entry.plugin, - }, - ] - : []; - }); -} - export function getThreadingContractRegistryShardRefs(params: { shardIndex: number; shardCount: number; @@ -178,44 +67,6 @@ export function getThreadingContractRegistryShardRefs(params: { const directoryPresenceOnlyIds = new Set(["whatsapp", "zalouser"]); -export function getDirectoryContractRegistry(): DirectoryContractEntry[] { - directoryContractRegistryCache ??= listBundledChannelPluginIds() - .filter((id) => directoryContractPluginIds.has(id)) - .flatMap((id) => { - const entry = getSurfaceContractEntry(id); - return entry && entry.surfaces.includes("directory") - ? [ - { - id: entry.id, - plugin: entry.plugin, - coverage: directoryPresenceOnlyIds.has(entry.id) ? "presence" : "lookups", - }, - ] - : []; - }); - return directoryContractRegistryCache; -} - -export function getDirectoryContractRegistryShard(params: { - shardIndex: number; - shardCount: number; -}): DirectoryContractEntry[] { - return getBundledChannelPluginIdsForShard(params) - .filter((id) => directoryContractPluginIds.has(id)) - .flatMap((id) => { - const entry = getSurfaceContractEntry(id); - return entry && entry.surfaces.includes("directory") - ? [ - { - id: entry.id, - plugin: entry.plugin, - coverage: directoryPresenceOnlyIds.has(entry.id) ? "presence" : "lookups", - }, - ] - : []; - }); -} - export function getDirectoryContractRegistryShardRefs(params: { shardIndex: number; shardCount: number; diff --git a/src/channels/plugins/contracts/test-helpers/surface-contract-suite.ts b/src/channels/plugins/contracts/test-helpers/surface-contract-suite.ts index 02408eb80ad..07b008842da 100644 --- a/src/channels/plugins/contracts/test-helpers/surface-contract-suite.ts +++ b/src/channels/plugins/contracts/test-helpers/surface-contract-suite.ts @@ -1,34 +1,6 @@ -import { expect, it } from "vitest"; +import { expect } from "vitest"; import type { ChannelPlugin } from "../../types.js"; -export function installChannelSurfaceContractSuite(params: { - plugin: Pick< - ChannelPlugin, - | "id" - | "actions" - | "setup" - | "status" - | "outbound" - | "messaging" - | "threading" - | "directory" - | "gateway" - >; - surface: - | "actions" - | "setup" - | "status" - | "outbound" - | "messaging" - | "threading" - | "directory" - | "gateway"; -}) { - it(`exposes the ${params.surface} surface contract`, () => { - expectChannelSurfaceContract(params); - }); -} - export function expectChannelSurfaceContract(params: { plugin: Pick< ChannelPlugin, diff --git a/src/channels/plugins/contracts/test-helpers/threading-directory-contract-suites.ts b/src/channels/plugins/contracts/test-helpers/threading-directory-contract-suites.ts index 66bcc006787..ab94129b4ee 100644 --- a/src/channels/plugins/contracts/test-helpers/threading-directory-contract-suites.ts +++ b/src/channels/plugins/contracts/test-helpers/threading-directory-contract-suites.ts @@ -1,4 +1,4 @@ -import { expect, it } from "vitest"; +import { expect } from "vitest"; import type { OpenClawConfig } from "../../../../config/config.js"; import type { RuntimeEnv } from "../../../../runtime.js"; import type { @@ -82,18 +82,6 @@ function expectFocusedBindingShape(binding: ChannelFocusedBindingContext) { expect(binding.labelNoun.trim()).not.toBe(""); } -export function installChannelThreadingContractSuite(params: { - plugin: Pick; -}) { - it("exposes the base threading contract", () => { - expectChannelThreadingBaseContract(params.plugin); - }); - - it("keeps threading return values normalized", () => { - expectChannelThreadingReturnValuesNormalized(params.plugin); - }); -} - export function expectChannelThreadingBaseContract( plugin: Pick, ) { @@ -185,17 +173,6 @@ export function expectChannelThreadingReturnValuesNormalized( } } -export function installChannelDirectoryContractSuite(params: { - plugin: Pick; - coverage?: "lookups" | "presence"; - cfg?: OpenClawConfig; - accountId?: string; -}) { - it("exposes the base directory contract", async () => { - await expectChannelDirectoryBaseContract(params); - }); -} - export async function expectChannelDirectoryBaseContract(params: { plugin: Pick; coverage?: "lookups" | "presence";