Open History to see the last commit
1import { expect, it } from 'vitest'
2import {
3 OPENAI_GPT51_GUIDE_URL,
4 OPENAI_GPT52_GUIDE_URL,
5 OPENAI_GPT5_GUIDE_URL,
6} from './openai-gpt5-guides.ts'
7import {
8 OPENAI_MODELS_INDEX_URL,
9 OPENAI_MODEL_PAGE,
10 OPENAI_PRICING_URL,
11} from './openai-model-docs.ts'
12import { OPENAI_REALTIME_EFFORT_URL } from './openai-realtime-efforts.ts'
13import { openaiProvider } from './openai.ts'
14
15it('loads the docs through the US egress (#505)', async () => {
16 const original = globalThis.fetch
17 // The listing itself stays on the global fetch; a docs load there fails.
18 globalThis.fetch = ((url: string) =>
19 String(url).includes('developers.openai.com')
20 ? Promise.reject(new Error(`global fetch called for ${String(url)}`))
21 : Promise.resolve(
22 Response.json({
23 data: [{ id: 'gpt-5-mini' }, { id: 'gpt-realtime-2' }],
24 }),
25 )) as typeof fetch
26 const egressed: Array<string> = []
27 const ns = {
28 idFromName: () => 'id',
29 get: () => ({
30 fetch(url: string) {
31 egressed.push(String(url))
32 if (url === OPENAI_MODELS_INDEX_URL)
33 return Promise.resolve(
34 new Response('- [GPT-5 mini](/api/docs/models/gpt-5-mini.md)'),
35 )
36 return Promise.resolve(new Response('# Docs'))
37 },
38 }),
39 }
40 try {
41 const result = await openaiProvider.listModels({
42 OPENAI_API_KEY: 'test-key',
43 US_EGRESS: ns as unknown as DurableObjectNamespace,
44 })
45 for (const failure of result.docsFailures?.first ?? []) {
46 expect(failure.error).not.toMatch(/global fetch called/)
47 }
48 expect(egressed).toEqual(
49 expect.arrayContaining([
50 OPENAI_MODELS_INDEX_URL,
51 OPENAI_PRICING_URL,
52 OPENAI_MODEL_PAGE('gpt-5-mini'),
53 OPENAI_REALTIME_EFFORT_URL,
54 OPENAI_GPT5_GUIDE_URL,
55 OPENAI_GPT51_GUIDE_URL,
56 OPENAI_GPT52_GUIDE_URL,
57 ]),
58 )
59 } finally {
60 globalThis.fetch = original
61 }
62})