Skip to content

Commit f9b4240

Browse files
fix(tests): isolate embedding provider credentials
1 parent dd9c165 commit f9b4240

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

apps/sim/app/api/knowledge/utils.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ describe('Knowledge Utils', () => {
169169
for (const key of Object.keys(env)) {
170170
delete (env as Record<string, unknown>)[key]
171171
}
172+
/** Keep provider selection independent of credentials loaded from local environment files. */
173+
vi.stubEnv('OPENAI_API_KEY', '')
174+
vi.stubEnv('OPENROUTER_API_KEY', '')
175+
vi.stubEnv('AZURE_OPENAI_API_KEY', '')
172176
Object.assign(env, { ...defaultMockEnv, OPENAI_API_KEY: 'test-key' })
173177
retrySpy.mockImplementation(((fn: () => unknown) => fn()) as never)
174178
applyBillingSpies()
@@ -324,16 +328,13 @@ describe('Knowledge Utils', () => {
324328

325329
it('should throw error when no API configuration provided', async () => {
326330
Object.keys(env).forEach((key) => delete (env as Record<string, unknown>)[key])
327-
/** Prevent local credentials from satisfying the missing-configuration scenario. */
328-
vi.stubEnv('OPENAI_API_KEY', '')
329-
const configurationError = new Error('No rotation keys configured')
330331
const rotationSpy = vi.spyOn(apiKeysModule, 'getRotatingApiKey').mockImplementation(() => {
331-
throw configurationError
332+
throw new Error('No rotation keys configured')
332333
})
333334

334335
try {
335-
await expect(generateEmbeddings(['test text'], DEFAULT_EMBEDDING_TARGET)).rejects.toBe(
336-
configurationError
336+
await expect(generateEmbeddings(['test text'], DEFAULT_EMBEDDING_TARGET)).rejects.toThrow(
337+
'OPENAI_API_KEY is not configured'
337338
)
338339
expect(rotationSpy).toHaveBeenCalledWith('openai')
339340
expect(fetch).not.toHaveBeenCalled()

0 commit comments

Comments
 (0)