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

client-smoke.ts

57 lines1.7 KB

1// Smoke test for @modelschemas/client against a running dev server (task
2// 7.4 acceptance): lists providers and fetches one schema, fully typed.
3//
4// pnpm run client-smoke [baseUrl]
5import {
6 createModelschemasClient,
7 getSchema,
8 listProviders,
9} from '@modelschemas/client'
10​
11const client = createModelschemasClient({
12 baseUrl: process.argv[2] ?? 'http://localhost:3100',
13})
14​
15const providers = await listProviders({ client })
16if (providers.error || !providers.data) {
17 console.error('listProviders failed:', providers.error)
18 process.exit(1)
20// `providers.data` is typed from the spec; runtime shape comes from the API.
21const providerList = (
22 providers.data as {
23 providers: Array<{ id: string; counts: { schemas: number } }>
24 }
25).providers
26console.log(
27 `providers ok (${String(providerList.length)}): ${providerList
28 .map((p) => p.id)
29 .join(', ')}`,
31​
32// The schema read below names a route only openai and anthropic share, so
33// pick one of them rather than whichever synced provider sorts first.
34const withSchemas = providerList.find(
35 (p) => (p.id === 'openai' || p.id === 'anthropic') && p.counts.schemas > 0,
37if (!withSchemas) {
38 console.error('no provider with synced schemas — run an admin sync first')
39 process.exit(1)
41​
42const schema = await getSchema({
43 client,
44 path: {
45 provider: withSchemas.id,
46 activity: 'chat',
47 endpointId:
48 withSchemas.id === 'anthropic' ? 'v1/messages' : 'chat/completions',
49 },
50 query: { kind: 'input' },
51})
52if (schema.error !== undefined) {
53 console.error('getSchema failed:', schema.error)
54 process.exit(1)
56const result = schema.data as { contentHash: string }
57console.log(`getSchema ok (contentHash ${result.contentHash.slice(0, 12)}…)`)