|
1 | 1 | // npx vitest run src/shared/__tests__/ProfileValidator.spec.ts |
2 | 2 |
|
3 | | -import type { ProviderSettings, OrganizationAllowList } from "@roo-code/types" |
| 3 | +import { providerIdentifiers, type ProviderSettings, type OrganizationAllowList } from "@roo-code/types" |
4 | 4 |
|
5 | 5 | import { ProfileValidator } from "../ProfileValidator" |
6 | 6 |
|
7 | 7 | describe("ProfileValidator", () => { |
8 | 8 | describe("isProfileAllowed", () => { |
| 9 | + it.each([ |
| 10 | + ["openai", { openAiModelId: "model" }], |
| 11 | + ["anthropic", { apiModelId: "model" }], |
| 12 | + ["openaiNative", { apiModelId: "model" }], |
| 13 | + ["bedrock", { apiModelId: "model" }], |
| 14 | + ["vertex", { apiModelId: "model" }], |
| 15 | + ["gemini", { apiModelId: "model" }], |
| 16 | + ["mistral", { apiModelId: "model" }], |
| 17 | + ["deepseek", { apiModelId: "model" }], |
| 18 | + ["xai", { apiModelId: "model" }], |
| 19 | + ["sambanova", { apiModelId: "model" }], |
| 20 | + ["fireworks", { apiModelId: "model" }], |
| 21 | + ["friendli", { apiModelId: "model" }], |
| 22 | + ["litellm", { litellmModelId: "model" }], |
| 23 | + ["lmstudio", { lmStudioModelId: "model" }], |
| 24 | + ["vscodeLm", { vsCodeLmModelSelector: { id: "model" } }], |
| 25 | + ["openrouter", { openRouterModelId: "model" }], |
| 26 | + ["ollama", { ollamaModelId: "model" }], |
| 27 | + ["requesty", { requestyModelId: "model" }], |
| 28 | + ["unbound", { unboundModelId: "model" }], |
| 29 | + ])("resolves %s model fields through canonical identifiers", (identifierKey, profileSettings) => { |
| 30 | + const identifiers = providerIdentifiers as Record<string, string> |
| 31 | + const originalIdentifier = identifiers[identifierKey] |
| 32 | + const canonicalIdentifier = `canonical-${identifierKey}` |
| 33 | + const modelId = "model" |
| 34 | + |
| 35 | + try { |
| 36 | + identifiers[identifierKey] = canonicalIdentifier |
| 37 | + |
| 38 | + const profile = { |
| 39 | + apiProvider: canonicalIdentifier, |
| 40 | + ...profileSettings, |
| 41 | + } as ProviderSettings |
| 42 | + const allowList: OrganizationAllowList = { |
| 43 | + allowAll: false, |
| 44 | + providers: { |
| 45 | + [canonicalIdentifier]: { allowAll: false, models: [modelId] }, |
| 46 | + }, |
| 47 | + } |
| 48 | + |
| 49 | + expect(ProfileValidator.isProfileAllowed(profile, allowList)).toBe(true) |
| 50 | + } finally { |
| 51 | + identifiers[identifierKey] = originalIdentifier |
| 52 | + } |
| 53 | + }) |
| 54 | + |
| 55 | + it.each([ |
| 56 | + { identifierKey: "fakeAi", profileSettings: {}, modelId: undefined, expected: false }, |
| 57 | + { |
| 58 | + identifierKey: "fakeAi", |
| 59 | + profileSettings: {}, |
| 60 | + modelId: undefined, |
| 61 | + expected: true, |
| 62 | + providerAllowAll: true, |
| 63 | + }, |
| 64 | + ])( |
| 65 | + "preserves canonical fallback behavior when provider allowAll is $providerAllowAll", |
| 66 | + ({ identifierKey, profileSettings, modelId, expected, providerAllowAll = false }) => { |
| 67 | + const identifiers = providerIdentifiers as Record<string, string> |
| 68 | + const originalIdentifier = identifiers[identifierKey] |
| 69 | + const canonicalIdentifier = `canonical-${identifierKey}` |
| 70 | + |
| 71 | + try { |
| 72 | + identifiers[identifierKey] = canonicalIdentifier |
| 73 | + |
| 74 | + const profile = { |
| 75 | + apiProvider: canonicalIdentifier, |
| 76 | + ...profileSettings, |
| 77 | + } as unknown as ProviderSettings |
| 78 | + const allowList: OrganizationAllowList = { |
| 79 | + allowAll: false, |
| 80 | + providers: { |
| 81 | + [canonicalIdentifier]: { |
| 82 | + allowAll: providerAllowAll, |
| 83 | + models: modelId ? [modelId] : undefined, |
| 84 | + }, |
| 85 | + }, |
| 86 | + } |
| 87 | + |
| 88 | + expect(ProfileValidator.isProfileAllowed(profile, allowList)).toBe(expected) |
| 89 | + } finally { |
| 90 | + identifiers[identifierKey] = originalIdentifier |
| 91 | + } |
| 92 | + }, |
| 93 | + ) |
| 94 | + |
9 | 95 | it("should allow any profile when allowAll is true", () => { |
10 | 96 | const allowList: OrganizationAllowList = { |
11 | 97 | allowAll: true, |
|
0 commit comments