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

client-smoke.ts

53 lines1.5 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// bun scripts/client-smoke.ts [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​
32const withSchemas = providerList.find((p) => p.counts.schemas > 0)
33if (!withSchemas) {
34 console.error('no provider with synced schemas — run an admin sync first')
35 process.exit(1)
37​
38const schema = await getSchema({
39 client,
40 path: {
41 provider: withSchemas.id,
42 activity: 'chat',
43 endpointId:
44 withSchemas.id === 'anthropic' ? 'v1/messages' : 'chat/completions',
45 },
46 query: { kind: 'input' },
47})
48if (schema.error !== undefined) {
49 console.error('getSchema failed:', schema.error)
50 process.exit(1)
52const result = schema.data as { contentHash: string }
53console.log(`getSchema ok (contentHash ${result.contentHash.slice(0, 12)}…)`)