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