File size: 13,287 Bytes
4c76b0d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | // Registry contract tests cover plugin contract registry contents and lookup behavior.
import { sortUniqueStrings } from "@openclaw/normalization-core/string-normalization";
import { describe, expect, it } from "vitest";
import { loadPluginManifestRegistryCore, type PluginManifestRecord } from "../manifest-registry.js";
import { resolveManifestContractPluginIds } from "../plugin-registry.js";
import { BUNDLED_PLUGIN_CONTRACT_SNAPSHOTS } from "./inventory/bundled-capability-metadata.js";
import { pluginRegistrationContractRegistry, providerContractLoadError } from "./registry.js";
const ACTIVATION_SCOPED_WEB_SEARCH_PLUGIN_IDS = ["codex", "qa-lab"] as const;
const ACTIVATION_SCOPED_WEB_SEARCH_PLUGIN_ID_SET = new Set<string>(
ACTIVATION_SCOPED_WEB_SEARCH_PLUGIN_IDS,
);
describe("plugin contract registry", () => {
function expectUniqueIds(ids: readonly string[]) {
expect(ids).toEqual([...new Set(ids)]);
}
function expectRegistryPluginIds(params: {
actualPluginIds: readonly string[];
predicate: (plugin: PluginManifestRecord) => boolean;
}) {
expect(sortUniqueStrings(params.actualPluginIds)).toEqual(
resolveBundledManifestPluginIds(params.predicate),
);
}
function resolveBundledManifestPluginIds(predicate: (plugin: PluginManifestRecord) => boolean) {
if (process.env.VITEST) {
return BUNDLED_PLUGIN_CONTRACT_SNAPSHOTS.map(
(entry) =>
({
id: entry.pluginId,
origin: "bundled",
providers: entry.providerIds,
contracts: {
embeddingProviders: entry.embeddingProviderIds,
workerProviders: entry.workerProviderIds,
speechProviders: entry.speechProviderIds,
realtimeTranscriptionProviders: entry.realtimeTranscriptionProviderIds,
realtimeVoiceProviders: entry.realtimeVoiceProviderIds,
mediaUnderstandingProviders: entry.mediaUnderstandingProviderIds,
transcriptSourceProviders: entry.transcriptSourceProviderIds,
documentExtractors: entry.documentExtractorIds,
imageGenerationProviders: entry.imageGenerationProviderIds,
videoGenerationProviders: entry.videoGenerationProviderIds,
musicGenerationProviders: entry.musicGenerationProviderIds,
webContentExtractors: entry.webContentExtractorIds,
webFetchProviders: entry.webFetchProviderIds,
webSearchProviders: entry.webSearchProviderIds,
migrationProviders: entry.migrationProviderIds,
tools: entry.toolNames,
},
}) as PluginManifestRecord,
)
.filter(predicate)
.map((plugin) => plugin.id)
.toSorted((left, right) => left.localeCompare(right));
}
const snapshotPluginIds = new Set(
BUNDLED_PLUGIN_CONTRACT_SNAPSHOTS.map((entry) => entry.pluginId),
);
return loadPluginManifestRegistryCore({})
.plugins.filter((plugin) => snapshotPluginIds.has(plugin.id) && predicate(plugin))
.map((plugin) => plugin.id)
.toSorted((left, right) => left.localeCompare(right));
}
it("loads bundled non-provider capability registries without import-time failure", () => {
expect(providerContractLoadError).toBeUndefined();
expect(Array.from(pluginRegistrationContractRegistry)).toStrictEqual(
BUNDLED_PLUGIN_CONTRACT_SNAPSHOTS,
);
});
it.each([
{
name: "does not duplicate bundled provider ids",
ids: () => pluginRegistrationContractRegistry.flatMap((entry) => entry.providerIds),
},
{
name: "does not duplicate bundled worker provider ids",
ids: () => pluginRegistrationContractRegistry.flatMap((entry) => entry.workerProviderIds),
},
{
name: "does not duplicate bundled web fetch provider ids",
ids: () => pluginRegistrationContractRegistry.flatMap((entry) => entry.webFetchProviderIds),
},
{
name: "does not duplicate bundled web search provider ids",
ids: () => pluginRegistrationContractRegistry.flatMap((entry) => entry.webSearchProviderIds),
},
{
name: "does not duplicate bundled migration provider ids",
ids: () => pluginRegistrationContractRegistry.flatMap((entry) => entry.migrationProviderIds),
},
{
name: "does not duplicate bundled media provider ids",
ids: () =>
pluginRegistrationContractRegistry.flatMap((entry) => entry.mediaUnderstandingProviderIds),
},
{
name: "does not duplicate bundled transcripts source provider ids",
ids: () =>
pluginRegistrationContractRegistry.flatMap((entry) => entry.transcriptSourceProviderIds),
},
{
name: "does not duplicate bundled realtime transcription provider ids",
ids: () =>
pluginRegistrationContractRegistry.flatMap(
(entry) => entry.realtimeTranscriptionProviderIds,
),
},
{
name: "does not duplicate bundled realtime voice provider ids",
ids: () =>
pluginRegistrationContractRegistry.flatMap((entry) => entry.realtimeVoiceProviderIds),
},
{
name: "does not duplicate bundled image-generation provider ids",
ids: () =>
pluginRegistrationContractRegistry.flatMap((entry) => entry.imageGenerationProviderIds),
},
] as const)("$name", ({ ids }) => {
expectUniqueIds(ids());
});
it("does not duplicate bundled speech provider ids", () => {
expectUniqueIds(pluginRegistrationContractRegistry.flatMap((entry) => entry.speechProviderIds));
});
it.each([
["azure-speech", "speechProviderIds", ["azure-speech", "azure"]],
["microsoft", "speechProviderIds", ["microsoft", "edge"]],
["tts-local-cli", "speechProviderIds", ["tts-local-cli", "cli"]],
["volcengine", "speechProviderIds", ["volcengine", "bytedance", "doubao"]],
["xiaomi", "speechProviderIds", ["xiaomi", "mimo"]],
["xai", "realtimeVoiceProviderIds", ["xai", "grok-voice", "xai-realtime-voice"]],
] as const)("declares canonical-first %s %s aliases", (pluginId, contract, providerIds) => {
expect(
pluginRegistrationContractRegistry.find((entry) => entry.pluginId === pluginId)?.[contract],
).toEqual(providerIds);
});
it("covers every bundled worker provider plugin discovered from manifests", () => {
expectRegistryPluginIds({
actualPluginIds: pluginRegistrationContractRegistry
.filter((entry) => entry.workerProviderIds.length > 0)
.map((entry) => entry.pluginId),
predicate: (plugin) =>
plugin.origin === "bundled" && (plugin.contracts?.workerProviders?.length ?? 0) > 0,
});
});
it("keeps video-only provider auth choices out of text onboarding", () => {
const registry = loadPluginManifestRegistryCore({});
for (const pluginId of ["alibaba", "runway"]) {
const plugin = registry.plugins.find(
(entry) => entry.origin === "bundled" && entry.id === pluginId,
);
expect(plugin?.providerAuthChoices).toEqual([
{
provider: pluginId,
method: "api-key",
choiceId: pluginId === "alibaba" ? "alibaba-model-studio-api-key" : "runway-api-key",
choiceLabel: pluginId === "alibaba" ? "Alibaba Model Studio API key" : "Runway API key",
groupId: pluginId,
groupLabel: pluginId === "alibaba" ? "Alibaba Model Studio" : "Runway",
groupHint: pluginId === "alibaba" ? "DashScope / Model Studio API key" : "API key",
onboardingScopes: ["image-generation"],
optionKey: pluginId === "alibaba" ? "alibabaModelStudioApiKey" : "runwayApiKey",
cliFlag: pluginId === "alibaba" ? "--alibaba-model-studio-api-key" : "--runway-api-key",
cliOption:
pluginId === "alibaba"
? "--alibaba-model-studio-api-key <key>"
: "--runway-api-key <key>",
cliDescription:
pluginId === "alibaba" ? "Alibaba Model Studio API key" : "Runway API key",
},
]);
}
});
it("exposes the GitHub Copilot non-interactive onboarding token flag from manifest metadata", () => {
const registry = loadPluginManifestRegistryCore({});
const plugin = registry.plugins.find(
(entry) => entry.origin === "bundled" && entry.id === "github-copilot",
);
expect(plugin?.providerAuthChoices).toEqual([
{
provider: "github-copilot",
method: "device",
appGuidedAuth: "device-code",
credentialOnly: true,
channelLogin: {},
appGuidedSecret: true,
choiceId: "github-copilot",
choiceLabel: "GitHub Copilot",
choiceHint: "Device login with your GitHub account",
assistantPriority: 1,
groupId: "copilot",
groupLabel: "Copilot",
groupHint: "GitHub, GitHub Enterprise + Local Proxy",
optionKey: "githubCopilotToken",
cliFlag: "--github-copilot-token",
cliOption: "--github-copilot-token <token>",
cliDescription: "GitHub Copilot OAuth token",
},
{
provider: "github-copilot",
method: "device-enterprise",
appGuidedAuth: "device-code",
credentialOnly: true,
choiceId: "github-copilot-enterprise",
choiceLabel: "GitHub Copilot (Enterprise / data residency)",
choiceHint: "Device login against your GitHub Enterprise (*.ghe.com) tenant",
assistantPriority: 2,
groupId: "copilot",
groupLabel: "Copilot",
groupHint: "GitHub, GitHub Enterprise + Local Proxy",
},
]);
});
it("covers every bundled speech plugin discovered from manifests", () => {
expectRegistryPluginIds({
actualPluginIds: pluginRegistrationContractRegistry
.filter((entry) => entry.speechProviderIds.length > 0)
.map((entry) => entry.pluginId),
predicate: (plugin) =>
plugin.origin === "bundled" && (plugin.contracts?.speechProviders?.length ?? 0) > 0,
});
});
it("covers every bundled realtime voice plugin discovered from manifests", () => {
expectRegistryPluginIds({
actualPluginIds: pluginRegistrationContractRegistry
.filter((entry) => entry.realtimeVoiceProviderIds.length > 0)
.map((entry) => entry.pluginId),
predicate: (plugin) =>
plugin.origin === "bundled" && (plugin.contracts?.realtimeVoiceProviders?.length ?? 0) > 0,
});
});
it("covers every bundled realtime transcription plugin discovered from manifests", () => {
expectRegistryPluginIds({
actualPluginIds: pluginRegistrationContractRegistry
.filter((entry) => entry.realtimeTranscriptionProviderIds.length > 0)
.map((entry) => entry.pluginId),
predicate: (plugin) =>
plugin.origin === "bundled" &&
(plugin.contracts?.realtimeTranscriptionProviders?.length ?? 0) > 0,
});
});
it("covers every bundled transcripts source plugin discovered from manifests", () => {
expectRegistryPluginIds({
actualPluginIds: pluginRegistrationContractRegistry
.filter((entry) => entry.transcriptSourceProviderIds.length > 0)
.map((entry) => entry.pluginId),
predicate: (plugin) =>
plugin.origin === "bundled" &&
(plugin.contracts?.transcriptSourceProviders?.length ?? 0) > 0,
});
});
it("covers every bundled web fetch plugin from the shared resolver", () => {
const bundledWebFetchPluginIds = resolveManifestContractPluginIds({
contract: "webFetchProviders",
origin: "bundled",
});
expect(
sortUniqueStrings(
pluginRegistrationContractRegistry
.filter((entry) => entry.webFetchProviderIds.length > 0)
.map((entry) => entry.pluginId),
),
).toEqual(bundledWebFetchPluginIds);
});
it("covers every bundled web search plugin from the shared resolver", () => {
const snapshotPluginIds = new Set(
BUNDLED_PLUGIN_CONTRACT_SNAPSHOTS.map((entry) => entry.pluginId),
);
const bundledWebSearchPluginIds = resolveManifestContractPluginIds({
contract: "webSearchProviders",
origin: "bundled",
}).filter(
(pluginId) =>
snapshotPluginIds.has(pluginId) &&
!ACTIVATION_SCOPED_WEB_SEARCH_PLUGIN_ID_SET.has(pluginId),
);
const expectedPluginIds = sortUniqueStrings([
...bundledWebSearchPluginIds,
...ACTIVATION_SCOPED_WEB_SEARCH_PLUGIN_IDS,
]);
const actualPluginIds = sortUniqueStrings(
pluginRegistrationContractRegistry
.filter((entry) => entry.webSearchProviderIds.length > 0)
.map((entry) => entry.pluginId),
);
expect(actualPluginIds).toEqual(expectedPluginIds);
expect(
actualPluginIds.filter((pluginId) => !bundledWebSearchPluginIds.includes(pluginId)),
).toEqual([...ACTIVATION_SCOPED_WEB_SEARCH_PLUGIN_IDS]);
});
it("covers every bundled migration provider plugin discovered from manifests", () => {
expectRegistryPluginIds({
actualPluginIds: pluginRegistrationContractRegistry
.filter((entry) => entry.migrationProviderIds.length > 0)
.map((entry) => entry.pluginId),
predicate: (plugin) =>
plugin.origin === "bundled" && (plugin.contracts?.migrationProviders?.length ?? 0) > 0,
});
});
});
|