Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

anthropic.test.ts

66 lines2.0 KB

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 const tools = anthropicServerTools('claude-opus-5-5').serverTools
44 expect(tools.length).toBeGreaterThan(0)
45 expect(model?.serverTools).toEqual(tools)
46 expect(model?.absent).toEqual({
47 pricing: 'unavailable',
48 reasoning: 'unavailable',
49 aliases: 'unavailable',
50 })
51 for (const failure of result.docsFailures?.first ?? []) {
52 expect(failure.error).toMatch(/parsed 0 model rows$/)
53 }
54 expect(
55 result.docsFailures?.first.map((failure) => failure.source).sort(),
56 ).toEqual(
57 [
58 ANTHROPIC_MODELS_OVERVIEW_URL,
59 ANTHROPIC_PRICING_URL,
60 ANTHROPIC_THINKING_URL,
61 ].sort(),
62 )
63 } finally {
64 globalThis.fetch = original
65 }
66})