























@@ -230,6 +230,177 @@ describe("provider auth choice manifest helpers", () => {
230230]);
231231});
232232233+it("derives generic auth choices from descriptor-safe setup provider auth methods", () => {
234+setManifestPlugins([
235+{
236+id: "demo-provider",
237+name: "Demo Provider",
238+origin: "global",
239+setup: {
240+providers: [
241+{
242+id: "demo-provider",
243+authMethods: ["api-key", "oauth"],
244+},
245+],
246+requiresRuntime: false,
247+},
248+},
249+]);
250+251+expect(resolveManifestProviderAuthChoices()).toEqual([
252+{
253+pluginId: "demo-provider",
254+providerId: "demo-provider",
255+methodId: "api-key",
256+choiceId: "demo-provider-api-key",
257+choiceLabel: "Demo Provider API key",
258+groupId: "demo-provider",
259+groupLabel: "Demo Provider",
260+},
261+{
262+pluginId: "demo-provider",
263+providerId: "demo-provider",
264+methodId: "oauth",
265+choiceId: "demo-provider-oauth",
266+choiceLabel: "Demo Provider OAuth",
267+groupId: "demo-provider",
268+groupLabel: "Demo Provider",
269+},
270+]);
271+});
272+273+it("sanitizes setup provider auth descriptors before deriving prompt labels", () => {
274+setManifestPlugins([
275+{
276+id: "evil-provider",
277+origin: "workspace",
278+setup: {
279+providers: [
280+{
281+id: "evil\u001b[31m-provider",
282+authMethods: ["jwt\u001b[2K", "oidc"],
283+},
284+],
285+requiresRuntime: false,
286+},
287+},
288+]);
289+290+expect(resolveManifestProviderAuthChoices()).toEqual([
291+{
292+pluginId: "evil-provider",
293+providerId: "evil-provider",
294+methodId: "jwt",
295+choiceId: "evil-provider-jwt",
296+choiceLabel: "Evil Provider JWT",
297+groupId: "evil-provider",
298+groupLabel: "Evil Provider",
299+},
300+{
301+pluginId: "evil-provider",
302+providerId: "evil-provider",
303+methodId: "oidc",
304+choiceId: "evil-provider-oidc",
305+choiceLabel: "Evil Provider OIDC",
306+groupId: "evil-provider",
307+groupLabel: "Evil Provider",
308+},
309+]);
310+});
311+312+it("uses setup provider auth methods when no setup entry exists", () => {
313+setManifestPlugins([
314+{
315+id: "no-runtime-provider",
316+origin: "global",
317+setup: {
318+providers: [
319+{
320+id: "no-runtime-provider",
321+authMethods: ["api-key"],
322+},
323+],
324+},
325+},
326+]);
327+328+expect(resolveManifestProviderAuthChoice("no-runtime-provider-api-key")).toEqual({
329+pluginId: "no-runtime-provider",
330+providerId: "no-runtime-provider",
331+methodId: "api-key",
332+choiceId: "no-runtime-provider-api-key",
333+choiceLabel: "No Runtime Provider API key",
334+groupId: "no-runtime-provider",
335+groupLabel: "No Runtime Provider",
336+});
337+});
338+339+it("keeps setup-entry providers on explicit manifest or runtime auth choices", () => {
340+setManifestPlugins([
341+{
342+id: "runtime-provider",
343+origin: "global",
344+setupSource: "/plugins/runtime-provider/setup-entry.cjs",
345+setup: {
346+providers: [
347+{
348+id: "runtime-provider",
349+authMethods: ["api-key"],
350+},
351+],
352+},
353+},
354+]);
355+356+expect(resolveManifestProviderAuthChoices()).toEqual([]);
357+});
358+359+it("does not duplicate explicit provider auth choices with setup auth methods", () => {
360+setManifestPlugins([
361+{
362+id: "explicit-provider",
363+origin: "global",
364+providerAuthChoices: [
365+{
366+provider: "explicit-provider",
367+method: "api-key",
368+choiceId: "explicit-api-key",
369+choiceLabel: "Explicit API key",
370+},
371+],
372+setup: {
373+providers: [
374+{
375+id: "explicit-provider",
376+authMethods: ["api-key", "oauth"],
377+},
378+],
379+requiresRuntime: false,
380+},
381+},
382+]);
383+384+expect(resolveManifestProviderAuthChoices()).toEqual([
385+{
386+pluginId: "explicit-provider",
387+providerId: "explicit-provider",
388+methodId: "api-key",
389+choiceId: "explicit-api-key",
390+choiceLabel: "Explicit API key",
391+},
392+{
393+pluginId: "explicit-provider",
394+providerId: "explicit-provider",
395+methodId: "oauth",
396+choiceId: "explicit-provider-oauth",
397+choiceLabel: "Explicit Provider OAuth",
398+groupId: "explicit-provider",
399+groupLabel: "Explicit Provider",
400+},
401+]);
402+});
403+233404it("prefers bundled auth-choice handlers when choice IDs collide across origins", () => {
234405setManifestPlugins([
235406{
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。