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

nvidia-docs-recovery.worker.test.ts

70 lines2.5 KB

1import { requestUrl } from '#/lib/text.ts'
2import { env } from 'cloudflare:test'
3import { expect, it, vi } from 'vitest'
4import { getDb } from '../../db/index.ts'
5import { providers } from '../../db/schema.ts'
6import { provider, NVIDIA_MODELS_URL } from '../providers/adapters/nvidia.ts'
7import { NVIDIA_REFERENCE_INDEXES } from '../providers/nvidia-openapi.ts'
8import native from '../providers/fixtures/nvidia-native-build-spec.json'
9import reference from '../providers/fixtures/nvidia-native-reasoning-discovery.json'
10import { recordDocsFailing, readDocsFailing } from './docs-failing.ts'
11import { pollProviderModels } from './poll-models.ts'
12​
13it('clears the previous NVIDIA docs outage after a healthy native adapter poll', async () => {
14 const rawId = 'nvidia/nemotron-3.5-content-safety'
15 const own = native[rawId]
16 const db = getDb(env)
17 const specSourceUrl = provider.specSourceUrl
18 if (!specSourceUrl)
19 throw new Error('Native NVIDIA provider source is missing')
20 await db.insert(providers).values({
21 id: provider.id,
22 displayName: provider.displayName,
23 specSourceUrl,
24 })
25 await recordDocsFailing(
26 db,
27 provider.id,
28 {
29 failed: 3,
30 skipped: 0,
31 first: [
32 {
33 source: own.sourceUrl,
34 error: 'previous native source outage',
35 elapsedMs: 1,
36 },
37 ],
38 },
39 1781150000,
40 )
41 expect(await readDocsFailing(db, provider.id)).toMatchObject({
42 failed: 3,
43 polls: 1,
44 })
45 vi.stubGlobal('fetch', async (input: RequestInfo | URL) => {
46 const url = requestUrl(input)
47 if (url === NVIDIA_MODELS_URL)
48 return Response.json({ data: [{ id: rawId }] })
49 if (url === own.sourceUrl + '.md') return new Response(own.markdown)
50 if (url === own.sourceUrl) return new Response(own.html)
51 const source = (reference as Record<string, string>)[url]
52 if (source !== undefined) return new Response(source)
53 if (NVIDIA_REFERENCE_INDEXES.includes(url))
54 return new Response('---\n---\n# No relevant models\n')
55 throw new Error('Unexpected native source request: ' + url)
56 })
57 try {
58 const outcome = await pollProviderModels(
59 { db, kv: env.SCHEMA_CACHE, secrets: {}, now: () => 1781150060 },
60 provider,
61 )
62 expect(outcome.modelsSeen).toBe(1)
63 expect(outcome.failures).toBe(0)
64 expect(outcome.docsFailures).toBeUndefined()
65 expect(outcome.docsFailing).toBeUndefined()
66 expect(await readDocsFailing(db, provider.id)).toBeNull()
67 } finally {
68 vi.unstubAllGlobals()
69 }
70})