Open History to see the last commit
1import { beforeAll, describe, expect, it } from 'vitest'
2import { env } from 'cloudflare:test'
3import { Validator } from '@cfworker/json-schema'
4
5import type { Schema } from '@cfworker/json-schema'
6import { getDb } from './../db/index.ts'
7import type { Db } from './../db/index.ts'
8import { models, providers } from '../db/schema.ts'
9import { GPT_4O } from '../../packages/rate-card/src/fixtures/gpt-4o.ts'
10import { NANO_BANANA_2 } from '../../packages/rate-card/src/fixtures/nano-banana-2.ts'
11import {
12 getModelDetail,
13 listModelsCatalog,
14 listProviderModels,
15 listProvidersCatalog,
16} from './catalog.ts'
17import { openApiDocument } from './openapi.ts'
18import { sourceSilentEvidenceLedger } from './source-silent.ts'
19import { parseSourceSilentEvidence } from './source-silent-facts.ts'
20
21const NOW = 1_781_150_000
22let db: Db
23
24beforeAll(async () => {
25 db = getDb(env)
26 await db.insert(providers).values([
27 {
28 id: 'cat-alpha',
29 displayName: 'Catalog Alpha',
30 specSourceUrl: 'https://example.com/a.json',
31 },
32 {
33 id: 'cat-beta',
34 displayName: 'Catalog Beta',
35 specSourceUrl: 'https://example.com/b.json',
36 },
37 ])
38 await db.insert(models).values([
39 {
40 id: 'cat-alpha-chatty',
41 providerId: 'cat-alpha',
42 rawId: 'chatty-1',
43 activity: 'chat',
44 displayName: 'Chatty One',
45 contextWindow: 100_000,
46 factSources: {
47 contextWindow: {
48 derivation: 'listing',
49 sourceUrl: 'https://example.com/catalog.json',
50 sourceHash: 'a'.repeat(64),
51 },
52 },
53 capabilities: { tools: true, vision: true, seed: false },
54 reasoning: { mode: 'toggle', mandatory: false },
55 firstSeenAt: NOW,
56 lastSeenAt: NOW,
57 },
58 {
59 id: 'cat-alpha-paint',
60 providerId: 'cat-alpha',
61 rawId: 'painter-xl',
62 activity: 'image',
63 displayName: 'Painter XL',
64 firstSeenAt: NOW,
65 lastSeenAt: NOW,
66 },
67 {
68 id: 'cat-beta-chatter',
69 providerId: 'cat-beta',
70 rawId: 'beta/chatter',
71 activity: 'chat',
72 displayName: 'Beta Chatter',
73 capabilities: { tools: true },
74 reasoning: { mode: 'effort', mandatory: null, efforts: ['low', 'max'] },
75 firstSeenAt: NOW,
76 lastSeenAt: NOW,
77 },
78 {
79 id: 'cat-beta-oldie',
80 providerId: 'cat-beta',
81 rawId: 'oldie',
82 activity: 'chat',
83 displayName: 'Oldie',
84 firstSeenAt: NOW,
85 lastSeenAt: NOW,
86 deprecatedAt: NOW,
87 },
88 ])
89})
90
91const catalogIds = async (filters: Parameters<typeof listModelsCatalog>[1]) =>
92 (await listModelsCatalog(db, filters)).models
93 .map((m) => m.id)
94 .filter((id) => id.startsWith('cat-'))
95
96describe('listModelsCatalog filters', () => {
97 it('excludes deprecated models by default, includes them on request', async () => {
98 expect(await catalogIds({ provider: 'cat-beta' })).toEqual([
99 'cat-beta-chatter',
100 ])
101 expect(
102 await catalogIds({ provider: 'cat-beta', includeDeprecated: true }),
103 ).toEqual(['cat-beta-chatter', 'cat-beta-oldie'])
104 })
105
106 it('filters by activity and provider', async () => {
107 expect(await catalogIds({ activity: 'chat' })).toEqual([
108 'cat-alpha-chatty',
109 'cat-beta-chatter',
110 ])
111 expect(await catalogIds({ activity: 'image' })).toEqual(['cat-alpha-paint'])
112 expect(await catalogIds({ provider: 'cat-alpha' })).toEqual([
113 'cat-alpha-chatty',
114 'cat-alpha-paint',
115 ])
116 })
117
118 it('filters by a capability flag stated true, and by free text', async () => {
119 // A stated false, a prefix of a flag, and a quote are not matches.
120 expect(await catalogIds({ capability: 'seed' })).toEqual([])
121 expect(await catalogIds({ capability: 'tool' })).toEqual([])
122 expect(await catalogIds({ capability: 'x"y' })).toEqual([])
123 expect(await catalogIds({ capability: 'vision' })).toEqual([
124 'cat-alpha-chatty',
125 ])
126 expect(await catalogIds({ capability: 'tools' })).toEqual([
127 'cat-alpha-chatty',
128 'cat-beta-chatter',
129 ])
130 expect(await catalogIds({ q: 'painter' })).toEqual(['cat-alpha-paint'])
131 expect(await catalogIds({ q: 'CHATT' })).toEqual([
132 'cat-alpha-chatty',
133 'cat-beta-chatter',
134 ])
135 })
136
137 it('combines filters and attaches _links', async () => {
138 const result = await listModelsCatalog(db, {
139 activity: 'chat',
140 provider: 'cat-alpha',
141 })
142 expect(result.models.map((m) => m.id)).toEqual(['cat-alpha-chatty'])
143 expect(result.models[0]?._links).toEqual({
144 provider: {
145 href: '/v1/providers/cat-alpha/models',
146 method: 'GET',
147 contentType: 'application/json',
148 },
149 schemas: {
150 href: '/v1/schemas/cat-alpha',
151 method: 'GET',
152 contentType: 'application/json',
153 },
154 })
155 expect(result.models[0]?._links).not.toHaveProperty('openapi')
156 })
157
158 it('advertises spec grain and OpenAPI links for registered providers', async () => {
159 await db
160 .insert(providers)
161 .values({
162 id: 'fal',
163 displayName: 'FAL',
164 specSourceUrl: 'https://example.com/f.json',
165 })
166 .onConflictDoNothing()
167 const fal = (await listProvidersCatalog(db)).providers.find(
168 (p) => p.id === 'fal',
169 )
170 expect(fal?.spec.grain).toBe('model')
171 expect(fal?._links.openapi).toMatchObject({
172 href: '/v1/openapi/fal{?model}',
173 contentType: 'application/openapi+json',
174 templated: true,
175 })
176 })
177})
178
179describe('provider-scoped queries', () => {
180 it('lists one provider, including deprecated models', async () => {
181 const result = await listProviderModels(db, 'cat-beta')
182 expect(result?.count).toBe(2)
183 expect(await listProviderModels(db, 'nope')).toBeNull()
184 })
185
186 it('resolves model detail by slug and by raw id', async () => {
187 const bySlug = await getModelDetail(db, 'cat-beta', 'cat-beta-chatter')
188 const byRaw = await getModelDetail(db, 'cat-beta', 'beta/chatter')
189 expect(bySlug?.id).toBe('cat-beta-chatter')
190 expect(byRaw?.id).toBe('cat-beta-chatter')
191 expect(byRaw?._links.schemas.href).toBe('/v1/schemas/cat-beta')
192 expect(byRaw?.schemaEndpointId).toBeNull()
193 expect(byRaw?.factSources).toBeNull()
194 expect(byRaw?.discrepancies).toEqual([])
195 expect(await getModelDetail(db, 'cat-beta', 'missing')).toBeNull()
196 })
197
198 it('serves a toggle and an unstated mandatory as stored, on list and detail', async () => {
199 const toggle = { mode: 'toggle', mandatory: false }
200 // null is "the source does not say": it must not come back as false.
201 const unstated = {
202 mode: 'effort',
203 mandatory: null,
204 efforts: ['low', 'max'],
205 }
206 const listed = async (provider: string, id: string) =>
207 (await listModelsCatalog(db, { provider })).models.find(
208 (model) => model.id === id,
209 )?.reasoning
210 const rows = [
211 await listed('cat-alpha', 'cat-alpha-chatty'),
212 (await getModelDetail(db, 'cat-alpha', 'chatty-1'))?.reasoning,
213 await listed('cat-beta', 'cat-beta-chatter'),
214 (await getModelDetail(db, 'cat-beta', 'beta/chatter'))?.reasoning,
215 ]
216 expect(rows).toEqual([toggle, toggle, unstated, unstated])
217
218 const schema = openApiDocument.components.schemas.Model.properties.reasoning
219 const validator = new Validator(
220 schema as unknown as Schema,
221 '2020-12',
222 false,
223 )
224 for (const row of rows) expect(validator.validate(row).errors).toEqual([])
225 expect(validator.validate({ mode: 'switch', mandatory: false }).valid).toBe(
226 false,
227 )
228 expect(validator.validate({ mode: 'toggle' }).valid).toBe(false)
229 })
230
231 it('surfaces recorded sources by default without inventing missing provenance', async () => {
232 const listed = await listModelsCatalog(db, { provider: 'cat-alpha' })
233 const recorded = {
234 derivation: 'listing',
235 sourceUrl: 'https://example.com/catalog.json',
236 sourceHash: 'a'.repeat(64),
237 }
238 expect(
239 listed.models.find((row) => row.rawId === 'chatty-1')?.factSources
240 ?.contextWindow,
241 ).toEqual(recorded)
242 expect(
243 listed.models.find((row) => row.rawId === 'painter-xl')?.factSources,
244 ).toBeNull()
245 const providerList = await listProviderModels(db, 'cat-alpha')
246 expect(
247 providerList?.models.find((row) => row.rawId === 'chatty-1')?.factSources
248 ?.contextWindow,
249 ).toEqual(recorded)
250 const compact = await listModelsCatalog(db, {
251 provider: 'cat-alpha',
252 provenance: false,
253 })
254 expect(compact.models.every((row) => !('factSources' in row))).toBe(true)
255 })
256
257 it('binds grain=provider models to a generation route and FAL to its raw id', async () => {
258 await db
259 .insert(providers)
260 .values([
261 {
262 id: 'grok',
263 displayName: 'xAI Grok',
264 specSourceUrl: 'https://example.com/g.json',
265 },
266 {
267 id: 'fal',
268 displayName: 'FAL',
269 specSourceUrl: 'https://example.com/f.json',
270 },
271 ])
272 .onConflictDoNothing()
273 await db.insert(models).values([
274 {
275 id: 'grok-grok-imagine-image-2-0',
276 providerId: 'grok',
277 rawId: 'grok-imagine-image-2.0',
278 activity: 'image',
279 displayName: 'Grok Imagine Image 2.0',
280 firstSeenAt: NOW,
281 lastSeenAt: NOW,
282 },
283 {
284 id: 'fal-xai-grok-imagine',
285 providerId: 'fal',
286 rawId: 'xai/grok-imagine-image/v2.0/text-to-image',
287 activity: 'image',
288 firstSeenAt: NOW,
289 lastSeenAt: NOW,
290 },
291 ])
292
293 const grok = await getModelDetail(db, 'grok', 'grok-imagine-image-2.0')
294 expect(grok?.schemaEndpointId).toBe('v1/images/generations')
295 expect(grok?._links.schema).toMatchObject({
296 href: '/v1/schemas/grok/image/v1/images/generations',
297 method: 'GET',
298 })
299 expect(
300 (await listModelsCatalog(db, { provider: 'grok', activity: 'image' }))
301 .models,
302 ).toHaveLength(1)
303
304 const fal = await getModelDetail(
305 db,
306 'fal',
307 'xai/grok-imagine-image/v2.0/text-to-image',
308 )
309 expect(fal?.schemaEndpointId).toBe(
310 'xai/grok-imagine-image/v2.0/text-to-image',
311 )
312 })
313
314 it('lists providers with status and links', async () => {
315 const result = await listProvidersCatalog(db)
316 const alpha = result.providers.find((p) => p.id === 'cat-alpha')
317 expect(alpha?._links.models.href).toBe('/v1/providers/cat-alpha/models')
318 expect(alpha?.counts.models).toBe(2)
319 })
320})
321
322describe('catalog rate cards', () => {
323 beforeAll(async () => {
324 await db.insert(providers).values({
325 id: 'cat-price',
326 displayName: 'Catalog Price',
327 specSourceUrl: 'https://example.com/p.json',
328 })
329 await db.insert(models).values([
330 {
331 id: 'cat-price-gpt-4o',
332 providerId: 'cat-price',
333 rawId: 'gpt-4o',
334 activity: 'chat',
335 displayName: 'GPT-4o',
336 pricing: GPT_4O,
337 factSources: { pricing: { derivation: 'listing' } },
338 firstSeenAt: NOW,
339 lastSeenAt: NOW,
340 },
341 {
342 id: 'cat-price-nano',
343 providerId: 'cat-price',
344 rawId: 'nano-banana-2',
345 activity: 'image',
346 displayName: 'Nano Banana 2',
347 pricing: NANO_BANANA_2,
348 firstSeenAt: NOW,
349 lastSeenAt: NOW,
350 },
351 {
352 id: 'cat-price-blob',
353 providerId: 'cat-price',
354 rawId: 'blob',
355 activity: 'chat',
356 pricing: { prompt: '0.0000025', completion: '0.00001' },
357 firstSeenAt: NOW,
358 lastSeenAt: NOW,
359 },
360 ])
361 })
362
363 it('summarises every stored card on the list; null means no card', async () => {
364 const listed = await listModelsCatalog(db, { provider: 'cat-price' })
365 const byId = Object.fromEntries(listed.models.map((m) => [m.id, m]))
366 expect(byId['cat-price-gpt-4o']?.pricing).toEqual({
367 currency: 'USD',
368 per: 'token',
369 inputPerMillion: 2.5,
370 outputPerMillion: 10,
371 })
372 expect(byId['cat-price-nano']?.pricing).toEqual({
373 currency: 'USD',
374 per: 'image',
375 })
376 expect(byId['cat-price-blob']?.pricing).toBeNull()
377 expect(listed._links.self.href).toContain('pricing')
378 })
379
380 it('includes the full card on list rows when pricing=1', async () => {
381 const listed = await listModelsCatalog(db, {
382 provider: 'cat-price',
383 pricing: true,
384 })
385 const gpt = listed.models.find((m) => m.id === 'cat-price-gpt-4o')
386 const nano = listed.models.find((m) => m.id === 'cat-price-nano')
387 expect(gpt?.pricing).toEqual(GPT_4O)
388 expect(nano?.pricing).toEqual(NANO_BANANA_2)
389 })
390
391 it('always includes the full card (or null) on detail', async () => {
392 const gpt = await getModelDetail(db, 'cat-price', 'gpt-4o')
393 const nano = await getModelDetail(db, 'cat-price', 'nano-banana-2')
394 const blob = await getModelDetail(db, 'cat-price', 'blob')
395 expect(gpt?.pricing).toEqual(GPT_4O)
396 expect(gpt?.factSources).toEqual({ pricing: { derivation: 'listing' } })
397 expect(nano?.pricing).toEqual(NANO_BANANA_2)
398 expect(blob?.pricing).toBeNull()
399 })
400})
401
402describe('stored sameAs relationships', () => {
403 beforeAll(async () => {
404 await db.insert(providers).values([
405 {
406 id: 'cat-maker',
407 displayName: 'Maker',
408 specSourceUrl: 'https://example.com/maker',
409 },
410 {
411 id: 'cat-reseller',
412 displayName: 'Reseller',
413 specSourceUrl: 'https://example.com/reseller',
414 },
415 ])
416 await db.insert(models).values({
417 id: 'sameas-maker',
418 providerId: 'cat-maker',
419 rawId: 'native-1',
420 pricing: GPT_4O,
421 firstSeenAt: NOW,
422 lastSeenAt: NOW,
423 })
424 await db.insert(models).values([
425 {
426 id: 'sameas-linked',
427 providerId: 'cat-reseller',
428 rawId: 'dealer-id',
429 sameAsModelId: 'sameas-maker',
430 contextWindow: 1234,
431 upstreamProvider: 'cat-maker',
432 upstreamRawId: 'native-1',
433 upstreamSource: {
434 derivation: 'docs-derived',
435 sourceUrl: 'https://example.com/reseller/model',
436 },
437 factSources: { contextWindow: { derivation: 'listing' } },
438 firstSeenAt: NOW,
439 lastSeenAt: NOW,
440 },
441 {
442 id: 'sameas-no-link',
443 providerId: 'cat-reseller',
444 rawId: 'cat-maker/native-1',
445 firstSeenAt: NOW,
446 lastSeenAt: NOW,
447 },
448 {
449 id: 'sameas-unresolved',
450 providerId: 'cat-reseller',
451 rawId: 'unresolved',
452 upstreamProvider: 'cat-maker',
453 upstreamRawId: 'missing',
454 upstreamSource: { derivation: 'listing' },
455 firstSeenAt: NOW,
456 lastSeenAt: NOW,
457 },
458 {
459 // A link reconcile has not caught up with: the evidence is gone.
460 id: 'sameas-stale',
461 providerId: 'cat-reseller',
462 rawId: 'stale',
463 sameAsModelId: 'sameas-maker',
464 firstSeenAt: NOW,
465 lastSeenAt: NOW,
466 },
467 {
468 id: 'sameas-normalized',
469 providerId: 'cat-reseller',
470 rawId: 'dotted',
471 sameAsModelId: 'sameas-maker',
472 upstreamProvider: 'cat-maker',
473 upstreamRawId: 'native.1',
474 upstreamSource: { derivation: 'listing' },
475 firstSeenAt: NOW,
476 lastSeenAt: NOW,
477 },
478 ])
479 })
480
481 it('serves the stored link, with its evidence as provenance only when resolved', async () => {
482 const linked = await getModelDetail(db, 'cat-reseller', 'dealer-id')
483 expect(linked?.sameAs).toEqual({
484 provider: 'cat-maker',
485 rawId: 'native-1',
486 })
487 expect(linked?.factSources).toEqual({
488 contextWindow: { derivation: 'listing' },
489 sameAs: {
490 derivation: 'docs-derived',
491 sourceUrl: 'https://example.com/reseller/model',
492 },
493 })
494 expect(linked?.contextWindow).toBe(1234)
495 expect(linked?.pricing).toBeNull()
496 for (const rawId of ['cat-maker/native-1', 'unresolved', 'stale']) {
497 const unlinked = await getModelDetail(db, 'cat-reseller', rawId)
498 expect(unlinked?.sameAs).toBeNull()
499 expect(unlinked?.factSources).toBeNull()
500 }
501 const dotted = await getModelDetail(db, 'cat-reseller', 'dotted')
502 expect(dotted?.factSources?.sameAs).toEqual({
503 derivation: 'listing',
504 normalized: true,
505 })
506 })
507
508 it('joins the stored target on catalog and provider lists', async () => {
509 const listed = await listModelsCatalog(db, {
510 provider: 'cat-reseller',
511 provenance: true,
512 })
513 const linked = listed.models.find((row) => row.id === 'sameas-linked')
514 expect(linked?.sameAs).toEqual({
515 provider: 'cat-maker',
516 rawId: 'native-1',
517 })
518 expect(linked?.factSources?.sameAs?.derivation).toBe('docs-derived')
519 const provider = await listProviderModels(db, 'cat-reseller')
520 expect(
521 provider?.models.find((row) => row.id === 'sameas-linked')?.sameAs,
522 ).toEqual({ provider: 'cat-maker', rawId: 'native-1' })
523 expect(provider?.models[0]?.factSources?.sameAs?.sourceUrl).toBe(
524 'https://example.com/reseller/model',
525 )
526 const compact = await listProviderModels(db, 'cat-reseller', false)
527 expect(compact?.models[0]).not.toHaveProperty('factSources')
528 })
529})
530
531describe('source-silent catalog provenance', () => {
532 it('serves verified ledger evidence on detail and default lists', async () => {
533 await db
534 .insert(providers)
535 .values({
536 id: 'grok',
537 displayName: 'Grok',
538 specSourceUrl: 'https://docs.x.ai/openapi.json',
539 })
540 .onConflictDoNothing()
541 await db.insert(models).values({
542 id: 'silent-grok-test',
543 providerId: 'grok',
544 rawId: 'silent-grok-test',
545 activity: 'chat',
546 firstSeenAt: NOW,
547 lastSeenAt: NOW,
548 })
549 const detail = await getModelDetail(db, 'grok', 'silent-grok-test')
550 const expected = {
551 derivation: 'source-silent',
552 sourceUrl: 'https://docs.x.ai/openapi.json',
553 checkedAt: '2026-10-22',
554 }
555 expect(detail?.maxOutput).toBeNull()
556 expect(detail?.factSources?.maxOutput).toEqual(expected)
557 expect(detail?.factSources).not.toHaveProperty('contextWindow')
558 const listed = await listModelsCatalog(db, {
559 provider: 'grok',
560 provenance: true,
561 })
562 expect(
563 listed.models.find((model) => model.id === 'silent-grok-test')
564 ?.factSources?.maxOutput,
565 ).toEqual(expected)
566 const compact = await listModelsCatalog(db, {
567 provider: 'grok',
568 provenance: false,
569 })
570 expect(
571 compact.models.find((model) => model.id === 'silent-grok-test'),
572 ).not.toHaveProperty('factSources')
573 })
574
575 it('retains sourced output caps despite a provider ledger entry', async () => {
576 await db
577 .insert(providers)
578 .values({
579 id: 'grok',
580 displayName: 'Grok',
581 specSourceUrl: 'https://docs.x.ai/openapi.json',
582 })
583 .onConflictDoNothing()
584 const source = {
585 derivation: 'listing',
586 sourceUrl: 'https://api.x.ai/v1/language-models',
587 }
588 await db.insert(models).values({
589 id: 'sourced-grok-test',
590 providerId: 'grok',
591 rawId: 'sourced-grok-test',
592 activity: 'chat',
593 maxOutput: 2048,
594 factSources: { maxOutput: source },
595 firstSeenAt: NOW,
596 lastSeenAt: NOW,
597 })
598 const detail = await getModelDetail(db, 'grok', 'sourced-grok-test')
599 expect(detail?.maxOutput).toBe(2048)
600 expect(detail?.factSources?.maxOutput).toEqual(source)
601 })
602})
603
604it('serves exact-model replay leaf silence on detail and default lists', async () => {
605 const scope = 'scoped-catalog/maker/model:variant'
606 const evidence = parseSourceSilentEvidence(
607 `- ${scope}: replayReasoningContent — absent, https://example.com/exact-model, checked 2026-10-09`,
608 ).get(scope)!
609 sourceSilentEvidenceLedger.set(scope, evidence)
610 try {
611 await db.insert(providers).values({
612 id: 'scoped-catalog',
613 displayName: 'Scoped catalog',
614 specSourceUrl: 'https://example.com/docs',
615 })
616 await db.insert(models).values([
617 {
618 id: 'scoped-catalog-exact',
619 providerId: 'scoped-catalog',
620 rawId: 'maker/model:variant',
621 activity: 'chat',
622 requestMap: { replayReasoningContent: null },
623 firstSeenAt: NOW,
624 lastSeenAt: NOW,
625 },
626 {
627 id: 'scoped-catalog-sibling',
628 providerId: 'scoped-catalog',
629 rawId: 'maker/model:variant-snapshot',
630 activity: 'chat',
631 requestMap: { replayReasoningContent: null },
632 firstSeenAt: NOW,
633 lastSeenAt: NOW,
634 },
635 ])
636 const detail = await getModelDetail(
637 db,
638 'scoped-catalog',
639 'maker/model:variant',
640 )
641 expect(detail?.requestMap).toEqual({ replayReasoningContent: null })
642 expect(
643 detail?.factSources?.requestMapFields?.replayReasoningContent,
644 ).toEqual(evidence.get('replayReasoningContent'))
645 expect(detail?.factSources).not.toHaveProperty('requestMap')
646 const listed = await listModelsCatalog(db, {
647 provider: 'scoped-catalog',
648 provenance: true,
649 })
650 expect(
651 listed.models.find((row) => row.rawId === 'maker/model:variant')
652 ?.factSources?.requestMapFields?.replayReasoningContent,
653 ).toEqual(evidence.get('replayReasoningContent'))
654 expect(
655 listed.models.find((row) => row.rawId === 'maker/model:variant-snapshot')
656 ?.factSources?.requestMapFields,
657 ).toBeUndefined()
658 const compact = await listModelsCatalog(db, {
659 provider: 'scoped-catalog',
660 provenance: false,
661 })
662 expect(compact.models.every((row) => !('factSources' in row))).toBe(true)
663 } finally {
664 sourceSilentEvidenceLedger.delete(scope)
665 }
666})
667
668describe('served rows match the published row schema', () => {
669 const validatorFor = (name: string) =>
670 new Validator(
671 {
672 $ref: `#/components/schemas/${name}`,
673 components: openApiDocument.components,
674 },
675 '2020-12',
676 false,
677 )
678
679 it('validates list, provider-list and detail responses', async () => {
680 const list = await listModelsCatalog(db, { includeDeprecated: true })
681 expect(validatorFor('ModelList').validate(list).errors).toEqual([])
682 const { capabilities: _dropped, ...missingField } = list.models[0] ?? {}
683 expect(
684 validatorFor('ModelList').validate({ ...list, models: [missingField] })
685 .valid,
686 ).toBe(false)
687 const full = await listModelsCatalog(db, { pricing: true })
688 expect(validatorFor('ModelList').validate(full).errors).toEqual([])
689 const bare = await listModelsCatalog(db, { provenance: false })
690 expect(validatorFor('ModelList').validate(bare).errors).toEqual([])
691 const byProvider = await listProviderModels(db, 'cat-alpha')
692 expect(
693 validatorFor('ProviderModelList').validate(byProvider).errors,
694 ).toEqual([])
695 const detail = validatorFor('ModelDetail')
696 for (const row of list.models) {
697 const body = await getModelDetail(db, row.provider, row.id)
698 expect(detail.validate(body).errors).toEqual([])
699 }
700 })
701})