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

ollaya.test.ts

148 lines4.6 KB

1import { Validator } from '@cfworker/json-schema'
2import { afterEach, describe, expect, it, vi } from 'vitest'
3​
4import { classifyAndBundle } from '../../ingest/sync.ts'
5import { sha256Text } from '../types.ts'
6import {
7 OLLAYA_CONTRACT_URL,
8 parseOllayaConfig,
9 provider,
10 registryTags,
11} from './ollaya.ts'
12​
13afterEach(() => {
14 vi.unstubAllGlobals()
15})
16​
17/** Serve docs/api.md with this text; any other URL fails the test. */
18function serveContract(text: string) {
19 vi.stubGlobal('fetch', (url: string) =>
20 Promise.resolve(
21 url === OLLAYA_CONTRACT_URL
22 ? new Response(text)
23 : new Response('unexpected', { status: 500 }),
24 ),
25 )
27​
28describe('ollaya', () => {
29 it('hashes the contract text, so a docs/api.md edit is a new source', async () => {
30 serveContract('# contract v1')
31 const first = await provider.fetchSpec({})
32 expect(first.sources[0]?.hash).toBe(await sha256Text('# contract v1'))
33 serveContract('# contract v2')
34 const second = await provider.fetchSpec({})
35 expect(second.sources[0]?.hash).not.toBe(first.sources[0]?.hash)
36 })
37​
38 it('bundles POST /v1/systemone as a decision endpoint', async () => {
39 serveContract('# contract')
40 const bundled = classifyAndBundle(provider, await provider.fetchSpec({}))
41 expect(bundled.endpoints).toHaveLength(1)
42 const [endpoint] = bundled.endpoints
43 expect(endpoint?.path).toBe('/v1/systemone')
44 expect(endpoint?.activity).toBe('decision')
45​
46 const input = new Validator(endpoint?.input as object, '2020-12', false)
47 const ok = {
48 model: 'laya',
49 state: { message: 'Can I get an invoice?' },
50 questions: {
51 intent: { type: 'choice', criteria: { invoice: 'x', other: 'y' } },
52 tags: { type: 'choice', criteria: ['a', 'b'], ordinal: true },
53 urgency: { type: 'score', criteria: ['low', 'high'] },
54 billing: { type: 'noul', instructions: 'About billing?' },
55 },
56 }
57 expect(input.validate(ok).valid).toBe(true)
58 expect(input.validate({ ...ok, questions: {} }).valid).toBe(false)
59 expect(
60 input.validate({
61 ...ok,
62 questions: { q: { type: 'box', instructions: 'x' } },
63 }).valid,
64 ).toBe(false)
65​
66 const output = new Validator(endpoint?.output as object, '2020-12', false)
67 expect(
68 output.validate({
69 model: 'laya:en',
70 answers: {
71 intent: {
72 type: 'choice',
73 choice: 'invoice',
74 confidence: 0.8995,
75 probabilities: { invoice: 0.933, other: 0.067 },
76 },
77 billing: { type: 'noul', noul: 0.9641 },
78 },
79 usage: { input_tokens: 71, output_tokens: 0 },
80 }).valid,
81 ).toBe(true)
82 })
83​
84 it('lists tags, skipping digests and precision pins of a listed tag', () => {
85 const blob = (path: string) => ({ path, type: 'blob' })
86 expect(
87 registryTags({
88 truncated: false,
89 tree: [
90 { path: 'laya', type: 'tree' },
91 blob('laya/manifests/en'),
92 blob('laya/manifests/en-fp32'),
93 blob('laya/manifests/latest'),
94 blob('laya/manifests/sha256-abc'),
95 blob('kev/manifests/9b-fp16'),
96 ],
97 }),
98 ).toEqual(['kev:9b-fp16', 'laya:en', 'laya:latest'])
99 expect(() => registryTags({ truncated: true, tree: [] })).toThrow()
100 })
101​
102 it('reads a config blob', () => {
103 expect(
104 parseOllayaConfig('laya:en', {
105 family: 'laya',
106 context_length: 512,
107 source:
108 'huggingface.co/convaiinnovations/laya@aa8c91ca088ec597df95a0d1c76b3063cb2ae5e8',
109 release_date: '2026-09-23',
110 }),
111 ).toMatchObject({
112 rawId: 'laya:en',
113 activity: 'decision',
114 contextWindow: 512,
115 releasedAt: Date.UTC(2026, 8, 23) / 1000,
116 openWeights: true,
117 weightsUrl: 'https://huggingface.co/convaiinnovations/laya',
118 })
119 // A router has no weights and no context of its own.
120 expect(
121 parseOllayaConfig('laya:latest', {
122 model_format: 'router',
123 context_length: 0,
124 source: '',
125 }),
126 ).toMatchObject({
127 contextWindow: null,
128 openWeights: null,
129 weightsUrl: null,
130 })
131 })
132​
133 it('throws on a config value it cannot read', () => {
134 expect(() => parseOllayaConfig('x:1', { context_length: '512' })).toThrow(
135 /context_length/,
136 )
137 expect(() => parseOllayaConfig('x:1', { release_date: 'soon' })).toThrow(
138 /release_date/,
139 )
140 expect(() => parseOllayaConfig('x:1', { source: 42 })).toThrow(/source/)
141 // Absent fields are unstated, not errors.
142 expect(parseOllayaConfig('x:1', {})).toMatchObject({
143 contextWindow: null,
144 releasedAt: null,
145 openWeights: null,
146 })
147 })
148})