Open History to see the last commit
1import { expect, it } from 'vitest'
2
3import {
4 ANTHROPIC_THINKING_URL,
5 anthropicServerTools,
6} from './anthropic-features.ts'
7import { ANTHROPIC_PRICING_URL } from './anthropic-pricing.ts'
8import { anthropicProvider } from './anthropic.ts'
9import { ANTHROPIC_MODELS_OVERVIEW_URL } from './provider-aliases.ts'
10
11it('keeps the poll when the docs host serves pages with no tables', async () => {
12 const original = globalThis.fetch
13 globalThis.fetch = ((url: string) => {
14 if (String(url).includes('platform.claude.com'))
15 return Promise.resolve(new Response('# Docs\n\nNothing tabulated here.'))
16 return Promise.resolve(
17 new Response(
18 JSON.stringify({
19 data: [
20 {
21 id: 'claude-opus-5-5',
22 display_name: 'Claude Opus 5.5',
23 created_at: '2026-09-01T00:00:00Z',
24 capabilities: {
25 thinking: { types: { adaptive: { supported: true } } },
26 },
27 },
28 ],
29 has_more: false,
30 }),
31 ),
32 )
33 }) as typeof fetch
34 try {
35 const result = await anthropicProvider.listModels({
36 ANTHROPIC_API_KEY: 'test-key',
37 })
38 expect(result.models).toHaveLength(1)
39 const model = result.models[0]
40 expect(model?.rawId).toBe('claude-opus-5-5')
41 expect(model?.pricing).toBeUndefined()
42 expect(model?.reasoning).toBeNull()
43 expect(model?.capabilities).toBeNull()
44 expect(model?.unsupportedCapabilities).toEqual([
45 'temperature',
46 'top_p',
47 'top_k',
48 ])
49 const tools = anthropicServerTools('claude-opus-5-5').serverTools
50 expect(tools.length).toBeGreaterThan(0)
51 expect(model?.serverTools).toEqual(tools)
52 expect(model?.absent).toEqual({
53 pricing: 'unavailable',
54 reasoning: 'unavailable',
55 aliases: 'unavailable',
56 })
57 for (const failure of result.docsFailures?.first ?? []) {
58 expect(failure.error).toMatch(/parsed 0 model rows$/)
59 }
60 expect(
61 result.docsFailures?.first.map((failure) => failure.source).sort(),
62 ).toEqual(
63 [
64 ANTHROPIC_MODELS_OVERVIEW_URL,
65 ANTHROPIC_PRICING_URL,
66 ANTHROPIC_THINKING_URL,
67 ].sort(),
68 )
69 } finally {
70 globalThis.fetch = original
71 }
72})
73
74const OVERVIEW_LINKS = [
75 'https://platform.claude.com/docs/en/about-claude/model-deprecations',
76 'https://platform.claude.com/docs/en/models/claude-opus-5-5/overview',
77].join('\n')
78
79it('loads the docs through the US egress, like the listing (#482)', async () => {
80 const original = globalThis.fetch
81 globalThis.fetch = ((url: string) =>
82 Promise.reject(
83 new Error(`global fetch called for ${String(url)}`),
84 )) as typeof fetch
85 const egressed: Array<string> = []
86 const ns = {
87 idFromName: () => 'id',
88 get: () => ({
89 fetch(url: string) {
90 egressed.push(String(url))
91 if (url === ANTHROPIC_MODELS_OVERVIEW_URL)
92 return Promise.resolve(new Response(OVERVIEW_LINKS))
93 if (url.includes('platform.claude.com'))
94 return Promise.resolve(new Response('# Docs'))
95 return Promise.resolve(Response.json({ data: [], has_more: false }))
96 },
97 }),
98 }
99 try {
100 const result = await anthropicProvider.listModels({
101 ANTHROPIC_API_KEY: 'test-key',
102 US_EGRESS: ns as unknown as DurableObjectNamespace,
103 })
104 for (const failure of result.docsFailures?.first ?? []) {
105 expect(failure.error).not.toMatch(/global fetch called/)
106 }
107 expect(egressed).toEqual(
108 expect.arrayContaining([
109 ANTHROPIC_PRICING_URL,
110 ANTHROPIC_THINKING_URL,
111 ANTHROPIC_MODELS_OVERVIEW_URL,
112 // The alias map's follow-up loads: deprecations and a model page.
113 'https://platform.claude.com/docs/en/about-claude/model-deprecations.md',
114 'https://platform.claude.com/docs/en/models/claude-opus-5-5/overview.md',
115 ]),
116 )
117 } finally {
118 globalThis.fetch = original
119 }
120})