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

cohere-model-pages.test.ts

89 lines3.1 KB

1import { describe, expect, it } from 'vitest'
2​
3import {
4 commandFamilyPageUrls,
5 parseCohereModelPage,
6} from './cohere-model-pages.ts'
7​
8const SOURCE = {
9 url: 'https://docs.cohere.com/docs/command-a-plus',
10 hash: 'abc',
11 extractedAt: '2026-10-23T00:00:00.000Z',
13​
14function page(box: string): string {
15 return `<html><body><h1>Model</h1> ${box} <h2>Description</h2><p>later Pricing mention</p></body></html>`
17​
18const FREE = page(`
19 <div>Pricing</div>
20 <p>For both trial keys and production keys, Command A+ is free until rate limits are reached. Learn more about rate limits.</p>
21 <p>Command A+ can be used in production through Cohere's Model Vault.</p>
22 <div>Specifications</div>
23 <p>Context Window: 128,000 tokens</p>
24 <p>Max Output Tokens: 64,000 tokens</p>
25 <p>Knowledge Cutoff: April 1, 2025</p>
26 <div>Model ID</div>
27 <p>command-a-plus-05-2026</p>
28 <p>Try in Playground</p>
29`)
30​
31describe('command model pages', () => {
32 it('reads the family links as docs URLs', () => {
33 const markdown = `* The Command family of models includes [Command A+](command-a-plus), [Command A](command-a),
34 [Command A Reasoning](command-a-reasoning), and [Command](command).`
35 expect(commandFamilyPageUrls(markdown)).toEqual([
36 'https://docs.cohere.com/docs/command-a-plus',
37 'https://docs.cohere.com/docs/command-a',
38 'https://docs.cohere.com/docs/command-a-reasoning',
39 'https://docs.cohere.com/docs/command',
40 ])
41 expect(() => commandFamilyPageUrls('# Models\nno family sentence')).toThrow(
42 /Command family links are missing/,
43 )
44 })
45​
46 it('treats the free sentence as a quota, and leaves the context cell', () => {
47 const parsed = parseCohereModelPage(FREE, SOURCE)
48 expect(parsed?.id).toBe('command-a-plus-05-2026')
49 expect(parsed?.facts.pricing).toBeUndefined()
50 expect(parsed?.facts.knowledgeCutoff).toBe('2025-04-01')
51 expect(parsed?.facts).not.toHaveProperty('contextWindow')
52 })
53​
54 it('reads a token price the showcase states', () => {
55 const html = page(`
56 Pricing Input $ 2.5 / 1M tokens Output $ 10 / 1M tokens
57 Specifications Context Window: 256,000 tokens
58 Knowledge Cutoff: June 1, 2024
59 Model ID command-a-03-2025
60 Try in Playground
61 `)
62 const parsed = parseCohereModelPage(html, SOURCE)
63 expect(parsed?.facts.pricing?.tables).toEqual({
64 rate: { base: { input_tokens: 2.5e-6, output_tokens: 1e-5 } },
65 })
66 expect(parsed?.facts.knowledgeCutoff).toBe('2024-06-01')
67 })
68​
69 it('writes nothing when the price sentence changes, or both forms appear', () => {
70 const reworded = FREE.replace(
71 'is free until rate limits are reached',
72 'is free for trial keys',
73 )
74 expect(
75 parseCohereModelPage(reworded, SOURCE)?.facts.pricing,
76 ).toBeUndefined()
77 expect(parseCohereModelPage(reworded, SOURCE)?.facts.knowledgeCutoff).toBe(
78 '2025-04-01',
79 )
80 const both = FREE.replace(
81 'Specifications',
82 'Input $ 2.5 / 1M tokens Output $ 10 / 1M tokens Specifications',
83 )
84 expect(parseCohereModelPage(both, SOURCE)?.facts.pricing).toBeUndefined()
85 expect(
86 parseCohereModelPage('<html>Page Not Found</html>', SOURCE),
87 ).toBeNull()
88 })
89})