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

ant-ling-native.worker.test.ts

108 lines4.1 KB

1import { env } from 'cloudflare:test'
2import { eq } from 'drizzle-orm'
3import { afterEach, expect, it, vi } from 'vitest'
4import ledgerMarkdown from '../../../docs/source-silent/ant-ling.md?raw'
5import { buildReport, parseLedger } from '../../lib/completeness.ts'
6import type { ModelRow } from '../../lib/completeness.ts'
7import { getDb } from '../../db/index.ts'
8import { models } from '../../db/schema.ts'
9import { provider } from '../providers/adapters/ant-ling.ts'
10import type { ModelFactSources } from '../providers/types.ts'
11import fixtures from '../providers/fixtures/ant-ling-docs.json'
12import { pollProviderModels } from './poll-models.ts'
13import { syncProvider } from './sync.ts'
14​
15afterEach(() => vi.unstubAllGlobals())
16​
17it('syncs native Ant Ling schema without spreading model-specific reasoning across its rows', async () => {
18 const BROWSER = {
19 quickAction: async (action: string, options: { url?: string }) => {
20 if (action !== 'content' || !options.url)
21 throw new Error('unexpected browser action')
22 const url = options.url
23 const body = (fixtures as Record<string, string>)[url]
24 if (body === undefined) throw new Error(`unexpected native source ${url}`)
25 return Response.json({
26 success: true,
27 result: body,
28 meta: { status: 200, finalUrl: url, title: 'native fixture' },
29 })
30 },
31 } as unknown as Pick<BrowserRun, 'quickAction'>
32 vi.stubGlobal('fetch', async () => {
33 throw new Error('native browser reader must not use direct fetch')
34 })
35 const db = getDb(env)
36 const deps = { db, kv: env.SCHEMA_CACHE, secrets: { BROWSER } }
37 const synced = await syncProvider(deps, provider)
38 expect(synced.endpointsSeen).toBeGreaterThan(0)
39 const outcome = await pollProviderModels(deps, provider)
40 expect(outcome.modelsSeen).toBe(8)
41 expect(outcome.added).toBe(8)
42 expect(outcome.failures).toBe(0)
43 const rows = await db
44 .select()
45 .from(models)
46 .where(eq(models.providerId, provider.id))
47 for (const rawId of ['Ling-2.6-1T', 'Ling-2.6-flash', 'Ring-2.6-1T']) {
48 const row = rows.find((model) => model.rawId === rawId)
49 expect(row?.activity).toBe('chat')
50 expect(row?.pricing).not.toBeNull()
51 expect(row?.maxOutput).toBeNull()
52 }
53 const reasoningIds = ['Ling-3.0-flash', 'Ring-2.6-1T']
54 for (const row of rows.filter((item) => item.activity === 'chat')) {
55 expect(row.capabilities?.reasoning, row.rawId).toBe(
56 reasoningIds.includes(row.rawId) ? true : undefined,
57 )
58 }
59 expect(rows.find((row) => row.rawId === 'Ling-3.0-flash')?.reasoning).toEqual(
60 { mode: 'toggle', mandatory: false },
61 )
62 expect(rows.find((row) => row.rawId === 'Ring-2.6-1T')?.reasoning).toEqual({
63 mode: 'effort',
64 mandatory: null,
65 efforts: ['high', 'xhigh'],
66 })
67 for (const row of rows.filter((item) => item.activity === 'chat')) {
68 if (!reasoningIds.includes(row.rawId)) expect(row.reasoning).toBeNull()
69 else
70 expect(
71 (row.factSources as ModelFactSources | null)?.capabilities?.reasoning,
72 ).toMatchObject({
73 derivation: 'docs-derived',
74 sourceUrl:
75 'https://developer.ant-ling.com/en/docs/api-reference/openai/',
76 })
77 }
78 const report = buildReport(
79 rows.map((row) => ({
80 ...row,
81 provider: provider.id,
82 modalities: row.modalities as ModelRow['modalities'],
83 pricing: row.pricing as ModelRow['pricing'],
84 reasoning: row.reasoning as ModelRow['reasoning'],
85 })),
86 parseLedger(ledgerMarkdown),
87 ).providers[0]!
88 expect(report.chat).toBe(7)
89 expect(report.score).toBe(1)
90 const plain = rows.find(
91 (row) => row.activity === 'chat' && !reasoningIds.includes(row.rawId),
92 )!
93 await db
94 .update(models)
95 .set({ capabilities: { ...plain.capabilities, reasoning: true } })
96 .where(eq(models.id, plain.id))
97 const again = await pollProviderModels(deps, provider)
98 expect(again.failures).toBe(0)
99 const refreshed = await db
100 .select()
101 .from(models)
102 .where(eq(models.providerId, provider.id))
103 for (const row of refreshed.filter((item) => item.activity === 'chat')) {
104 expect(row.capabilities?.reasoning, row.rawId).toBe(
105 reasoningIds.includes(row.rawId) ? true : undefined,
106 )
107 }
108})