Open History to see the last commit
1import { readFileSync } from 'node:fs'
2import { describe, expect, it } from 'vitest'
3import { price } from '@modelschemas/rate-card'
4import {
5 claudeCardModels,
6 claudeCardPaths,
7 claudeGlobalPrices,
8} from './vertex-claude.ts'
9import { normModelName } from './vertex-text.ts'
10
11const fixture = (name: string) =>
12 readFileSync(
13 new URL(`./fixtures/vertex-claude/${name}.html.txt`, import.meta.url),
14 'utf8',
15 )
16const card = fixture('sonnet-4-6')
17const prices = fixture('global-pricing')
18const source = {
19 url: 'https://cloud.google.com/pricing',
20 hash: 'fixture-hash',
21 extractedAt: '2026-10-09',
22}
23
24describe('Google native Claude sources', () => {
25 it('reads exact hosted model identity and published facts without a body-schema guess', () => {
26 const [row] = claudeCardModels(
27 card,
28 'https://docs.cloud.google.com/card',
29 'hash',
30 )
31 expect(row).toMatchObject({
32 rawId: 'claude-sonnet-4-6',
33 contextWindow: 1_000_000,
34 maxOutput: 128_000,
35 modalities: { input: ['text', 'image', 'pdf'], output: ['text'] },
36 capabilities: ['tools', 'reasoning'],
37 reasoning: null,
38 requestMap: null,
39 schemaEndpointId: null,
40 })
41 expect(row?.factSources?.maxOutput?.sourceHash).toBe('hash')
42 })
43 it('reads the model name from a card title that leads with the vendor', () => {
44 const [row] = claudeCardModels(
45 card.replace(
46 'Claude Sonnet 4.6 on Google Cloud<devsite-actions',
47 'Anthropic's Claude Sonnet 4.6 on Google Cloud<devsite-actions',
48 ),
49 'https://docs.cloud.google.com/card',
50 'hash',
51 )
52 expect(row?.displayName).toBe('Claude Sonnet 4.6')
53 // vertexClaudeModels joins cards to prices on this key.
54 const key = normModelName(
55 (row?.displayName ?? '').replace(/^Claude\s+/i, ''),
56 )
57 expect(claudeGlobalPrices(prices, source).get(key)).toBeDefined()
58 })
59 it('does not turn unreadable identity or token limits into a successful empty listing', () => {
60 expect(() =>
61 claudeCardModels(
62 card.replaceAll('claude-sonnet-4-6', 'unknown'),
63 source.url,
64 'hash',
65 ),
66 ).toThrow('unreadable model id')
67 expect(() =>
68 claudeCardModels(
69 card.replace(
70 'Maximum output tokens: 128,000',
71 'Maximum output tokens: unknown',
72 ),
73 source.url,
74 'hash',
75 ),
76 ).toThrow('unreadable Maximum output tokens')
77 expect(() => claudeCardPaths('<article>No models</article>')).toThrow(
78 'no linked model cards',
79 )
80 })
81 it('uses the explicitly Global rates with separately published prompt-length tiers', () => {
82 const book = claudeGlobalPrices(prices, source)
83 const sonnet = book.get('sonnet 4 6')
84 expect(sonnet).toBeDefined()
85 expect(
86 price(sonnet!, {}, { input_tokens: 1_000_000, output_tokens: 1_000_000 }),
87 ).toBe(18)
88 const haiku = book.get('haiku 5 5')
89 expect(haiku).toBeDefined()
90 expect(
91 price(haiku!, {}, { input_tokens: 50_000, output_tokens: 1_000_000 }),
92 ).toBeCloseTo(0.505)
93 expect(
94 price(haiku!, {}, { input_tokens: 200_000, output_tokens: 1_000_000 }),
95 ).toBeCloseTo(2.6)
96 })
97 it('rejects malformed published prices and missing Global panels', () => {
98 expect(() =>
99 claudeGlobalPrices(prices.replace('$0.10', '$unknown'), source),
100 ).toThrow('unreadable price')
101 expect(() =>
102 claudeGlobalPrices(prices.replace(/>Global</g, '>Regional<'), source),
103 ).toThrow('no Global Claude price rows')
104 })
105 it('does not read a regional table after an empty Global panel', () => {
106 const table = prices.match(/<table\b[\s\S]*?<\/table>/i)?.[0] ?? ''
107 const emptyGlobal = prices.replace(table, '')
108 expect(() =>
109 claudeGlobalPrices(
110 `${emptyGlobal}<div role="tabpanel" aria-labelledby="regional">${table}</div>`,
111 source,
112 ),
113 ).toThrow('no Global Claude price rows')
114 })
115 it('leaves an incomplete published long tier unpriced instead of copying short rates', () => {
116 // The native Global table leaves Opus 5.5's long input cell blank while
117 // publishing other long-context prices. It supplies no complete card.
118 expect(claudeGlobalPrices(prices, source).has('opus 5 5')).toBe(false)
119 })
120})