Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import {
4 buildReport,
5 originIndex,
6 parseLedger,
7 rowCompleteness,
8 scoreRow,
9} from './completeness.ts'
10import type { ModelRow } from './completeness.ts'
11
12const chat: ModelRow = {
13 provider: 'host',
14 rawId: 'm',
15 activity: 'chat',
16 contextWindow: 8,
17 maxOutput: 8,
18 modalities: { input: ['text'] },
19 pricing: {
20 tables: {
21 rate: {
22 base: { input_tokens: 1, output_tokens: 2, cache_read_tokens: 0.1 },
23 },
24 },
25 },
26 capabilities: { reasoning: true },
27 reasoning: { mode: 'effort', mandatory: true, efforts: ['low'] },
28 requestMap: { replayReasoningContent: false },
29 schemaEndpointId: 'chat/completions',
30}
31
32describe('applicable facts', () => {
33 it('scores replayReasoningContent only on chat/completions routes', () => {
34 const report = buildReport([
35 chat,
36 {
37 ...chat,
38 rawId: 'messages',
39 schemaEndpointId: 'v1/messages',
40 requestMap: null,
41 },
42 {
43 ...chat,
44 rawId: 'converse',
45 schemaEndpointId: 'model/x/converse',
46 requestMap: null,
47 },
48 {
49 ...chat,
50 rawId: 'responses',
51 schemaEndpointId: 'responses',
52 requestMap: null,
53 },
54 {
55 ...chat,
56 rawId: 'gemini',
57 schemaEndpointId: 'v1beta/models/{modelsId}:generateContent',
58 requestMap: { maxTokensField: 'max_tokens' },
59 },
60 ])
61 const host = report.providers[0]
62 expect(host?.activities.chat?.facts?.replayReasoningContent).toEqual({
63 have: 1,
64 need: 1,
65 })
66 expect(host?.activities.chat?.facts?.requestMap).toEqual({
67 have: 1,
68 need: 2,
69 })
70 })
71
72 it('does not score requestMap on a native route', () => {
73 const report = buildReport([
74 {
75 ...chat,
76 schemaEndpointId: 'v1/messages',
77 requestMap: null,
78 reasoning: null,
79 capabilities: { tools: true },
80 },
81 ])
82 expect(report.providers[0]?.activities.chat?.facts?.requestMap).toEqual({
83 have: 0,
84 need: 0,
85 })
86 expect(
87 report.providers[0]?.activities.chat?.facts?.replayReasoningContent,
88 ).toEqual({
89 have: 0,
90 need: 0,
91 })
92 })
93
94 it('counts a stated cache absence and not a made-up price', () => {
95 const report = buildReport([
96 {
97 ...chat,
98 pricing: {
99 tables: { rate: { base: { input_tokens: 1, output_tokens: 2 } } },
100 },
101 factSources: { cacheRead: { path: 'not-offered' } },
102 },
103 ])
104 expect(report.providers[0]?.activities.chat?.facts?.cacheRead).toEqual({
105 have: 1,
106 need: 1,
107 })
108 })
109
110 it('leaves a native replay row out of a model-scoped ledger denominator', () => {
111 const report = buildReport(
112 [{ ...chat, schemaEndpointId: 'v1/messages', requestMap: null }],
113 parseLedger('- host/m: replayReasoningContent — native route'),
114 )
115 const host = report.providers[0]?.activities.chat
116 expect(host?.facts?.replayReasoningContent?.need).toBe(0)
117 expect(host?.modelSilent.replayReasoningContent).toBeUndefined()
118 })
119})
120
121describe('activities other than chat', () => {
122 const speech: ModelRow = {
123 provider: 'speech',
124 rawId: 'tts',
125 activity: 'audio',
126 modalities: { input: ['text'], output: ['audio'] },
127 pricing: { tables: {} },
128 schemaEndpointId: 'v1/text-to-speech',
129 }
130
131 it('scores an audio-only provider on its media facts', () => {
132 const report = buildReport([
133 speech,
134 { ...speech, rawId: 'bare', modalities: null, pricing: null },
135 ])
136 const audio = report.providers[0]?.activities.audio
137 expect(audio?.facts).toEqual({
138 priced: { have: 1, need: 2 },
139 endpoint: { have: 2, need: 2 },
140 modalities: { have: 1, need: 2 },
141 outputModalities: { have: 1, need: 2 },
142 })
143 expect(audio?.score).toBe(5 / 8)
144 expect(report.providers[0]?.score).toBe(5 / 8)
145 })
146
147 it('does not count a models.dev card as a media price', () => {
148 const report = buildReport([
149 {
150 ...speech,
151 pricing: { tables: {}, source: { url: 'https://models.dev/x' } },
152 },
153 ])
154 expect(report.providers[0]?.activities.audio?.facts?.priced).toEqual({
155 have: 0,
156 need: 1,
157 })
158 })
159
160 it('counts an unclassified row as a gap on every provider', () => {
161 const report = buildReport([speech, { provider: 'speech', activity: null }])
162 const p = report.providers[0]
163 expect(p?.noActivity).toBe(1)
164 expect(p?.activities.unclassified?.facts).toEqual({
165 activity: { have: 0, need: 1 },
166 })
167 expect(p?.score).toBe(4 / 5)
168 const only = buildReport([{ provider: 'x', activity: null }])
169 expect(only.providers[0]?.score).toBe(0)
170 })
171
172 it('lists an activity with no fact set without scoring it', () => {
173 const report = buildReport([
174 { provider: 'embed', rawId: 'e', activity: 'embeddings' },
175 ])
176 const p = report.providers[0]
177 expect(p?.activities.embeddings).toMatchObject({
178 rows: 1,
179 facts: null,
180 score: null,
181 })
182 expect(p?.score).toBeNull()
183 })
184})
185
186describe('origin links', () => {
187 const origin: ModelRow = { provider: 'maker', rawId: 'model-4-5' }
188 const linked: ModelRow = {
189 provider: 'gateway',
190 rawId: 'model-4.5',
191 sameAs: { provider: 'maker', rawId: 'model-4-5' },
192 }
193
194 it('needs a link where another provider lists the same id', () => {
195 const report = buildReport([
196 origin,
197 linked,
198 { provider: 'host', rawId: 'model-4.5' },
199 { provider: 'host', rawId: 'own-model' },
200 ])
201 const by = (id: string) =>
202 report.providers.find((p) => p.provider === id)?.originLink
203 // The link target is the origin: it needs no link of its own.
204 expect(by('maker')).toEqual({ have: 0, need: 0, modelSilent: 0 })
205 expect(by('gateway')).toEqual({ have: 1, need: 1, modelSilent: 0 })
206 // Matches after dots are read as hyphens; `own-model` matches nothing.
207 expect(by('host')).toEqual({ have: 0, need: 1, modelSilent: 0 })
208 })
209
210 it('matches by alias and ignores ids at the same provider', () => {
211 const report = buildReport([
212 { provider: 'maker', rawId: 'm-latest', aliases: ['m-1'] },
213 { provider: 'maker', rawId: 'm-1' },
214 { provider: 'host', rawId: 'm-1' },
215 ])
216 const by = (id: string) =>
217 report.providers.find((p) => p.provider === id)?.originLink.need
218 expect(by('maker')).toBe(2)
219 expect(by('host')).toBe(1)
220 })
221
222 it('names the missing facts of one row', () => {
223 const row: ModelRow = { ...chat, maxOutput: null }
224 const origins = originIndex([row, { provider: 'other', rawId: 'm' }])
225 expect(
226 rowCompleteness(
227 scoreRow(row, parseLedger('- host: cacheRead — none'), origins),
228 ),
229 ).toEqual({ filled: 9, needed: 11, missing: ['maxOutput', 'originLink'] })
230 })
231})