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

worldlabs.test.ts

238 lines7.4 KB

1import { afterEach, describe, expect, it } from 'vitest'
2​
3import { classifyAndBundle } from '#/server/ingest/sync.ts'
4​
5import type { OpenApiDocument } from '../types.ts'
6import {
7 WORLDLABS_MODELS_URL,
8 WORLDLABS_OPENAPI_URL,
9 parseWorldlabsModels,
10 provider,
11} from './worldlabs.ts'
12​
13const originalFetch = globalThis.fetch
14​
15afterEach(() => {
16 globalThis.fetch = originalFetch
17})
18​
19const MODELS_PAGE = `
20| Marble model | API \`model\` |
21| - | - |
22| \`Marble 1.1 Plus\` | \`marble-1.1-plus\` |
23| \`Marble 1.1\` | \`marble-1.1\` |
24| \`Marble 1.0\` | \`marble-1.0\` |
25| \`Marble 1.0 Draft\` | \`marble-1.0-draft\` |
26​
27| Current \`model\` value | Legacy \`model\` value |
28| - | - |
29| \`marble-1.0\` | \`Marble 0.1-plus\` |
30| \`marble-1.0-draft\` | \`Marble 0.1-mini\` |
32​
33const PRICING_PAGE = `
34You may purchase credits at a fixed rate of $1.00 USD per 1,250 credits.
35​
36#### Draft model totals (\`marble-1.0-draft\`)
37​
38| Input type | Pano generation | World generation | Total |
39| - | -: | -: | -: |
40| Image (pano) | 0 | 150 | 150 |
41| Text | 80 | 150 | 230 |
42| Image (non-pano) | 80 | 150 | 230 |
43| Multi-image | 100 | 150 | 250 |
44| Video | 100 | 150 | 250 |
45​
46#### Standard model totals (\`marble-1.0\`, \`marble-1.1\`)
47​
48| Input type | Pano generation | World generation | Total |
49| - | -: | -: | -: |
50| Image (pano) | 0 | 1,500 | 1,500 |
51| Text | 80 | 1,500 | 1,580 |
52| Image (non-pano) | 80 | 1,500 | 1,580 |
53| Multi-image | 100 | 1,500 | 1,600 |
54| Video | 100 | 1,500 | 1,600 |
55​
56#### Marble 1.1 Plus totals (\`marble-1.1-plus\`)
57​
58| Input type | Pano generation | Base world generation | Variable world generation | Total |
59| - | -: | -: | - | - |
60| Image (pano) | 0 | 1,500 | 0-1,500 | 1,500-3,000 |
61| Text | 80 | 1,500 | 0-1,500 | 1,580-3,080 |
62| Image (non-pano) | 80 | 1,500 | 0-1,500 | 1,580-3,080 |
63| Multi-image | 100 | 1,500 | 0-1,500 | 1,600-3,100 |
64| Video | 100 | 1,500 | 0-1,500 | 1,600-3,100 |
66​
67function operation(
68 summary: string,
69 method: 'get' | 'post',
70): NonNullable<OpenApiDocument['paths']>[string] {
71 const op = {
72 summary,
73 responses: {
74 '200': {
75 content: {
76 'application/json': {
77 schema: { type: 'object', properties: { id: { type: 'string' } } },
78 },
79 },
80 },
81 },
82 }
83 if (method === 'get') return { get: op }
84 return {
85 post: {
86 ...op,
87 requestBody: {
88 content: {
89 'application/json': {
90 schema: {
91 type: 'object',
92 properties: {
93 world_prompt: { type: 'object' },
94 model: { type: 'string' },
95 },
96 },
97 },
98 },
99 },
100 },
101 }
103​
104describe('worldlabs classify', () => {
105 it('keeps the Marble generation paths, including operation polling', () => {
106 expect(provider.classify('/marble/v1/worlds:generate', {})).toBe('world')
107 expect(provider.classify('/marble/v1/operations/{operation_id}', {})).toBe(
108 'world',
109 )
110 expect(provider.classify('/marble/v1/worlds/{world_id}', {})).toBe('world')
111 expect(provider.classify('/marble/v1/worlds/{world_id}:export', {})).toBe(
112 'world',
113 )
114 expect(provider.classify('/marble/v1/worlds:list', {})).toBe('world')
115 expect(
116 provider.classify('/marble/v1/media-assets:prepare_upload', {}),
117 ).toBe('world')
118 expect(
119 provider.classify('/marble/v1/media-assets/{media_asset_id}', {}),
120 ).toBe('world')
121 expect(provider.classify('/marble/v1/pano:depth_to_rgb', {})).toBe('world')
122 expect(provider.classify('/marble/v1/credits', {})).toBe('world')
123 })
124​
125 it('drops paths the Marble document does not publish as generation', () => {
126 expect(
127 provider.classify('/marble/v1/worlds/{world_id}/share', {}),
128 ).toBeNull()
129 })
130})
131​
132describe('parseWorldlabsModels', () => {
133 it('reads the mapping table and the legacy aliases it states', () => {
134 const models = parseWorldlabsModels(MODELS_PAGE)
135 expect(models.get('marble-1.1')?.displayName).toBe('Marble 1.1')
136 expect(models.get('marble-1.0')?.aliases).toEqual(['Marble 0.1-plus'])
137 expect(models.get('marble-1.0-draft')?.aliases).toEqual(['Marble 0.1-mini'])
138 expect(models.get('marble-1.1-plus')?.aliases).toEqual([])
139 })
140})
141​
142describe('worldlabs listModels', () => {
143 it('lists the public catalog without an API key', async () => {
144 globalThis.fetch = ((url: string) => {
145 const body =
146 String(url) === WORLDLABS_MODELS_URL ? MODELS_PAGE : PRICING_PAGE
147 return Promise.resolve(new Response(body))
148 }) as typeof fetch
149​
150 const result = await provider.listModels({})
151 expect(result.skipped).toBeUndefined()
152 expect(result.models.map((model) => model.rawId)).toEqual([
153 'marble-1.1-plus',
154 'marble-1.1',
155 'marble-1.0',
156 'marble-1.0-draft',
157 ])
158 expect(result.models.every((model) => model.activity === 'world')).toBe(
159 true,
160 )
161 const plus = result.models.find(
162 (model) => model.rawId === 'marble-1.1-plus',
163 )
164 const standard = result.models.find((model) => model.rawId === 'marble-1.1')
165 expect(plus?.pricing).toBeUndefined()
166 expect(standard?.pricing).toMatchObject({
167 price: {
168 lookup: {
169 table: 'rate',
170 keys: [{ var: 'world_prompt_kind' }],
171 },
172 },
173 })
174 })
175})
176​
177describe('worldlabs fetchSpec', () => {
178 it('loads the public Marble document and bundles every covered path', async () => {
179 const spec: OpenApiDocument = {
180 openapi: '3.1.0',
181 info: { title: 'Marble Public API v1', version: '1.0.0' },
182 paths: {
183 '/marble/v1/worlds:generate': operation('Generate World', 'post'),
184 '/marble/v1/worlds/{world_id}': operation('Get World', 'get'),
185 '/marble/v1/worlds/{world_id}:export': operation(
186 'Export World',
187 'post',
188 ),
189 '/marble/v1/worlds:list': operation('List Worlds', 'post'),
190 '/marble/v1/operations/{operation_id}': operation(
191 'Get Operation',
192 'get',
193 ),
194 '/marble/v1/media-assets:prepare_upload': operation(
195 'Prepare upload',
196 'post',
197 ),
198 '/marble/v1/media-assets/{media_asset_id}': operation(
199 'Get Media Asset',
200 'get',
201 ),
202 '/marble/v1/pano:depth_to_rgb': operation('Pano Depth To Rgb', 'post'),
203 '/marble/v1/credits': operation('Get Credits', 'get'),
204 '/marble/v1/admin': operation('Admin', 'get'),
205 },
206 }
207 const urls: Array<string> = []
208 globalThis.fetch = ((url: string) => {
209 urls.push(String(url))
210 return Promise.resolve(new Response(JSON.stringify(spec)))
211 }) as typeof fetch
212​
213 const fetched = await provider.fetchSpec({})
214 expect(urls).toEqual([WORLDLABS_OPENAPI_URL])
215 const { endpoints, warnings } = classifyAndBundle(provider, fetched)
216 expect(warnings).toEqual([])
217 expect(endpoints.map((endpoint) => endpoint.path).sort()).toEqual([
218 '/marble/v1/credits',
219 '/marble/v1/media-assets/{media_asset_id}',
220 '/marble/v1/media-assets:prepare_upload',
221 '/marble/v1/operations/{operation_id}',
222 '/marble/v1/pano:depth_to_rgb',
223 '/marble/v1/worlds/{world_id}',
224 '/marble/v1/worlds/{world_id}:export',
225 '/marble/v1/worlds:generate',
226 '/marble/v1/worlds:list',
227 ])
228 expect(endpoints.every((endpoint) => endpoint.activity === 'world')).toBe(
229 true,
230 )
231 expect(
232 provider.generationEndpointId?.({
233 rawId: 'marble-1.1',
234 activity: 'world',
235 }),
236 ).toBe('marble/v1/worlds:generate')
237 })
238})