Skip to content

Commit 965cea6

Browse files
committed
test(shared): strengthen profile validator coverage
1 parent cab2d53 commit 965cea6

1 file changed

Lines changed: 41 additions & 52 deletions

File tree

src/shared/__tests__/ProfileValidator.spec.ts

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -47,48 +47,37 @@ describe("ProfileValidator", () => {
4747
}
4848

4949
expect(ProfileValidator.isProfileAllowed(profile, allowList)).toBe(true)
50+
51+
const negativeAllowList: OrganizationAllowList = {
52+
allowAll: false,
53+
providers: {
54+
[canonicalIdentifier]: { allowAll: false, models: ["other-model"] },
55+
},
56+
}
57+
58+
expect(ProfileValidator.isProfileAllowed(profile, negativeAllowList)).toBe(false)
5059
} finally {
5160
identifiers[identifierKey] = originalIdentifier
5261
}
5362
})
5463

5564
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-
},
65+
{ providerAllowAll: false, expected: false },
66+
{ providerAllowAll: true, expected: true },
6467
])(
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
68+
"preserves missing-model fallback behavior when provider allowAll is $providerAllowAll",
69+
({ providerAllowAll, expected }) => {
70+
const profile: ProviderSettings = {
71+
apiProvider: providerIdentifiers.openai,
9172
}
73+
const allowList: OrganizationAllowList = {
74+
allowAll: false,
75+
providers: {
76+
[providerIdentifiers.openai]: { allowAll: providerAllowAll },
77+
},
78+
}
79+
80+
expect(ProfileValidator.isProfileAllowed(profile, allowList)).toBe(expected)
9281
},
9382
)
9483

@@ -254,17 +243,17 @@ describe("ProfileValidator", () => {
254243

255244
// Test specific providers that use apiModelId
256245
const apiModelProviders = [
257-
"anthropic",
258-
"openai-native",
259-
"bedrock",
260-
"vertex",
261-
"gemini",
262-
"mistral",
263-
"deepseek",
264-
"xai",
265-
"sambanova",
266-
"fireworks",
267-
"friendli",
246+
providerIdentifiers.anthropic,
247+
providerIdentifiers.openaiNative,
248+
providerIdentifiers.bedrock,
249+
providerIdentifiers.vertex,
250+
providerIdentifiers.gemini,
251+
providerIdentifiers.mistral,
252+
providerIdentifiers.deepseek,
253+
providerIdentifiers.xai,
254+
providerIdentifiers.sambanova,
255+
providerIdentifiers.fireworks,
256+
providerIdentifiers.friendli,
268257
]
269258

270259
apiModelProviders.forEach((provider) => {
@@ -276,7 +265,7 @@ describe("ProfileValidator", () => {
276265
},
277266
}
278267
const profile: ProviderSettings = {
279-
apiProvider: provider as any, // Type assertion needed here
268+
apiProvider: provider,
280269
apiModelId: "test-model",
281270
}
282271

@@ -289,11 +278,11 @@ describe("ProfileValidator", () => {
289278
const allowList: OrganizationAllowList = {
290279
allowAll: false,
291280
providers: {
292-
litellm: { allowAll: false, models: ["test-model"] },
281+
[providerIdentifiers.litellm]: { allowAll: false, models: ["test-model"] },
293282
},
294283
}
295284
const profile: ProviderSettings = {
296-
apiProvider: "litellm" as any,
285+
apiProvider: providerIdentifiers.litellm,
297286
litellmModelId: "test-model",
298287
}
299288

@@ -304,11 +293,11 @@ describe("ProfileValidator", () => {
304293
const allowList: OrganizationAllowList = {
305294
allowAll: false,
306295
providers: {
307-
"vscode-lm": { allowAll: false, models: ["copilot-gpt-3.5"] },
296+
[providerIdentifiers.vscodeLm]: { allowAll: false, models: ["copilot-gpt-3.5"] },
308297
},
309298
}
310299
const profile: ProviderSettings = {
311-
apiProvider: "vscode-lm",
300+
apiProvider: providerIdentifiers.vscodeLm,
312301
vsCodeLmModelSelector: { id: "copilot-gpt-3.5" },
313302
}
314303

@@ -364,11 +353,11 @@ describe("ProfileValidator", () => {
364353
const allowList: OrganizationAllowList = {
365354
allowAll: false,
366355
providers: {
367-
"fake-ai": { allowAll: false },
356+
[providerIdentifiers.fakeAi]: { allowAll: false },
368357
},
369358
}
370359
const profile: ProviderSettings = {
371-
apiProvider: "fake-ai",
360+
apiProvider: providerIdentifiers.fakeAi,
372361
}
373362

374363
expect(ProfileValidator.isProfileAllowed(profile, allowList)).toBe(false)

0 commit comments

Comments
 (0)