|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { setEnv } from '#tests/env-disposable.ts' |
| 3 | +import { getWorkersAiRunUrl } from '../cloudflare-ai-utils.server.ts' |
| 4 | + |
| 5 | +test('getWorkersAiRunUrl routes embeddinggemma requests through CLOUDFLARE_AI_EMBEDDING_GATEWAY_ID', () => { |
| 6 | + using ignoredEnv = setEnv({ |
| 7 | + CLOUDFLARE_ACCOUNT_ID: 'cf-account', |
| 8 | + CLOUDFLARE_AI_GATEWAY_ID: 'runtime-gateway', |
| 9 | + CLOUDFLARE_AI_EMBEDDING_GATEWAY_ID: 'embedding-gateway', |
| 10 | + }) |
| 11 | + |
| 12 | + const url = getWorkersAiRunUrl('@cf/google/embeddinggemma-300m') |
| 13 | + expect(url).toContain('/embedding-gateway/') |
| 14 | + expect(url).not.toContain('/runtime-gateway/') |
| 15 | +}) |
| 16 | + |
| 17 | +test('getWorkersAiRunUrl keeps non-embedding models on CLOUDFLARE_AI_GATEWAY_ID', () => { |
| 18 | + using ignoredEnv = setEnv({ |
| 19 | + CLOUDFLARE_ACCOUNT_ID: 'cf-account', |
| 20 | + CLOUDFLARE_AI_GATEWAY_ID: 'runtime-gateway', |
| 21 | + CLOUDFLARE_AI_EMBEDDING_GATEWAY_ID: 'embedding-gateway', |
| 22 | + }) |
| 23 | + |
| 24 | + const url = getWorkersAiRunUrl('@cf/openai/whisper-large-v3-turbo') |
| 25 | + expect(url).toContain('/runtime-gateway/') |
| 26 | + expect(url).not.toContain('/embedding-gateway/') |
| 27 | +}) |
| 28 | + |
| 29 | +test('getWorkersAiRunUrl prefers explicit gatewayId overrides', () => { |
| 30 | + using ignoredEnv = setEnv({ |
| 31 | + CLOUDFLARE_ACCOUNT_ID: 'cf-account', |
| 32 | + CLOUDFLARE_AI_GATEWAY_ID: 'runtime-gateway', |
| 33 | + CLOUDFLARE_AI_EMBEDDING_GATEWAY_ID: 'embedding-gateway', |
| 34 | + }) |
| 35 | + |
| 36 | + const url = getWorkersAiRunUrl({ |
| 37 | + model: '@cf/google/embeddinggemma-300m', |
| 38 | + gatewayId: 'explicit-gateway', |
| 39 | + }) |
| 40 | + expect(url).toContain('/explicit-gateway/') |
| 41 | + expect(url).not.toContain('/embedding-gateway/') |
| 42 | +}) |
0 commit comments