Download src/plugin-sdk/test-helpers/plugin-registration-contract.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 5.71 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/plugin-sdk/test-helpers/plugin-registration-contract.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/plugin-sdk/test-helpers/plugin-registration-contract.ts
-
curl -L -o plugin-registration-contract.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/plugin-sdk/test-helpers/plugin-registration-contract.ts
5.71 kB
| /** | |
| * Contract suite for bundled plugin registration ownership and manifest auth metadata. | |
| */ | |
| import { describe, expect, it } from "vitest"; | |
| import { loadPluginManifestRegistryCore } from "../../plugins/manifest-registry.js"; | |
| export type PluginRegistrationContractParams = { | |
| pluginId: string; | |
| cliBackendIds?: string[]; | |
| providerIds?: string[]; | |
| webFetchProviderIds?: string[]; | |
| webSearchProviderIds?: string[]; | |
| speechProviderIds?: string[]; | |
| realtimeTranscriptionProviderIds?: string[]; | |
| realtimeVoiceProviderIds?: string[]; | |
| mediaUnderstandingProviderIds?: string[]; | |
| transcriptSourceProviderIds?: string[]; | |
| imageGenerationProviderIds?: string[]; | |
| videoGenerationProviderIds?: string[]; | |
| musicGenerationProviderIds?: string[]; | |
| toolNames?: string[]; | |
| manifestAuthChoice?: { | |
| pluginId: string; | |
| choiceId: string; | |
| choiceLabel: string; | |
| groupId: string; | |
| groupLabel: string; | |
| groupHint: string; | |
| }; | |
| }; | |
| export type PluginRegistrationContractResolver = ( | |
| pluginId: string, | |
| ) => Omit<PluginRegistrationContractParams, "manifestAuthChoice"> | undefined; | |
| /** Installs tests that pin a bundled plugin's registered provider/tool ownership. */ | |
| export function installPluginRegistrationContract( | |
| params: PluginRegistrationContractParams, | |
| resolveRegistration: PluginRegistrationContractResolver, | |
| ) { | |
| const findRegistration = (pluginId: string) => { | |
| const entry = resolveRegistration(pluginId); | |
| if (!entry) { | |
| throw new Error(`plugin registration contract missing for ${pluginId}`); | |
| } | |
| return entry; | |
| }; | |
| describe(`${params.pluginId} plugin registration contract`, () => { | |
| if (params.cliBackendIds) { | |
| it("keeps bundled cli-backend ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).cliBackendIds).toEqual(params.cliBackendIds); | |
| }); | |
| } | |
| if (params.providerIds) { | |
| it("keeps bundled provider ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).providerIds).toEqual(params.providerIds); | |
| }); | |
| } | |
| if (params.webSearchProviderIds) { | |
| it("keeps bundled web search ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).webSearchProviderIds).toEqual( | |
| params.webSearchProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.webFetchProviderIds) { | |
| it("keeps bundled web fetch ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).webFetchProviderIds).toEqual( | |
| params.webFetchProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.speechProviderIds) { | |
| it("keeps bundled speech ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).speechProviderIds).toEqual( | |
| params.speechProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.realtimeTranscriptionProviderIds) { | |
| it("keeps bundled realtime-transcription ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).realtimeTranscriptionProviderIds).toEqual( | |
| params.realtimeTranscriptionProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.realtimeVoiceProviderIds) { | |
| it("keeps bundled realtime-voice ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).realtimeVoiceProviderIds).toEqual( | |
| params.realtimeVoiceProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.mediaUnderstandingProviderIds) { | |
| it("keeps bundled media-understanding ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).mediaUnderstandingProviderIds).toEqual( | |
| params.mediaUnderstandingProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.transcriptSourceProviderIds) { | |
| it("keeps bundled transcripts source ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).transcriptSourceProviderIds).toEqual( | |
| params.transcriptSourceProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.imageGenerationProviderIds) { | |
| it("keeps bundled image-generation ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).imageGenerationProviderIds).toEqual( | |
| params.imageGenerationProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.videoGenerationProviderIds) { | |
| it("keeps bundled video-generation ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).videoGenerationProviderIds).toEqual( | |
| params.videoGenerationProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.musicGenerationProviderIds) { | |
| it("keeps bundled music-generation ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).musicGenerationProviderIds).toEqual( | |
| params.musicGenerationProviderIds, | |
| ); | |
| }); | |
| } | |
| if (params.toolNames) { | |
| it("keeps bundled tool ownership explicit", () => { | |
| expect(findRegistration(params.pluginId).toolNames).toEqual(params.toolNames); | |
| }); | |
| } | |
| const manifestAuthChoice = params.manifestAuthChoice; | |
| if (manifestAuthChoice) { | |
| it("keeps onboarding auth grouping explicit", () => { | |
| const plugin = loadPluginManifestRegistryCore({}).plugins.find( | |
| (entry) => entry.origin === "bundled" && entry.id === manifestAuthChoice.pluginId, | |
| ); | |
| expect(plugin?.providerAuthChoices).toEqual( | |
| expect.arrayContaining([ | |
| expect.objectContaining({ | |
| choiceId: manifestAuthChoice.choiceId, | |
| choiceLabel: manifestAuthChoice.choiceLabel, | |
| groupId: manifestAuthChoice.groupId, | |
| groupLabel: manifestAuthChoice.groupLabel, | |
| groupHint: manifestAuthChoice.groupHint, | |
| }), | |
| ]), | |
| ); | |
| }); | |
| } | |
| }); | |
| } | |