File size: 5,709 Bytes
eb3f11e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * 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,
            }),
          ]),
        );
      });
    }
  });
}