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

runway.test.ts

118 lines4.3 KB

1import { afterEach, describe, expect, it } from 'vitest'
2​
3import { classifyAndBundle } from '#/server/ingest/sync.ts'
4import { provider } from './runway.ts'
5import type { OpenApiDocument } from '../types.ts'
6​
7const SPEC_URL =
8 'https://raw.githubusercontent.com/runwayml/openapi/next/openapi.json'
9​
10const originalFetch = globalThis.fetch
11​
12afterEach(() => {
13 globalThis.fetch = originalFetch
14})
15​
16describe('runway classify', () => {
17 it('maps generation POSTs to video, image, and audio', () => {
18 expect(provider.classify('/v1/text_to_video', {})).toBe('video')
19 expect(provider.classify('/v1/image_to_video', {})).toBe('video')
20 expect(provider.classify('/v1/video_to_video', {})).toBe('video')
21 expect(provider.classify('/v1/video_upscale', {})).toBe('video')
22 expect(provider.classify('/v1/character_performance', {})).toBe('video')
23 expect(provider.classify('/v1/generate/video', {})).toBe('video')
24 expect(provider.classify('/v1/avatar_videos', {})).toBe('video')
25 expect(provider.classify('/v1/recipes/product_ad', {})).toBe('video')
26​
27 expect(provider.classify('/v1/text_to_image', {})).toBe('image')
28 expect(provider.classify('/v1/image_upscale', {})).toBe('image')
29 expect(provider.classify('/v1/generate/image', {})).toBe('image')
30 expect(provider.classify('/v1/recipes/ad_localization', {})).toBe('image')
31​
32 expect(provider.classify('/v1/text_to_speech', {})).toBe('audio')
33 expect(provider.classify('/v1/sound_effect', {})).toBe('audio')
34 expect(provider.classify('/v1/generate/audio', {})).toBe('audio')
35 })
36​
37 it('drops task management and other platform surfaces', () => {
38 expect(provider.classify('/v1/tasks/{id}', {})).toBeNull()
39 expect(provider.classify('/v1/organization', {})).toBeNull()
40 expect(provider.classify('/v1/uploads', {})).toBeNull()
41 expect(provider.classify('/v1/avatars', {})).toBeNull()
42 expect(provider.classify('/v1/routers', {})).toBeNull()
43 expect(provider.classify('/v1/voices', {})).toBeNull()
44 expect(provider.classify('/v1/workflows/{id}', {})).toBeNull()
45 expect(provider.classify('/v1/documents', {})).toBeNull()
46 })
47})
48​
49describe('runway listModels', () => {
50 it('skips with an empty catalog when the secret is absent', async () => {
51 const result = await provider.listModels({})
52 expect(result.models).toEqual([])
53 expect(result.skipped).toMatch(/RUNWAY_API_KEY not set/)
54 })
55})
56​
57describe('runway fetchSpec', () => {
58 it('loads the public Stainless document without a key', async () => {
59 const spec: OpenApiDocument = {
60 openapi: '3.1.0',
61 info: { title: 'RunwayML API', version: '2024-11-06' },
62 paths: {
63 '/v1/text_to_video': {
64 post: {
65 summary: 'Text to video',
66 requestBody: {
67 content: {
68 'application/json': {
69 schema: {
70 type: 'object',
71 properties: { promptText: { type: 'string' } },
72 },
73 },
74 },
75 },
76 responses: {
77 '200': {
78 content: {
79 'application/json': {
80 schema: {
81 type: 'object',
82 properties: { id: { type: 'string' } },
83 },
84 },
85 },
86 },
87 },
88 },
89 },
90 '/v1/tasks/{id}': {
91 get: { summary: 'Get task detail' },
92 delete: { summary: 'Cancel or delete a task' },
93 },
94 '/v1/organization': {
95 get: { summary: 'Get organization information' },
96 },
97 },
98 }
99 const urls: Array<string> = []
100 globalThis.fetch = ((url: string) => {
101 urls.push(String(url))
102 return Promise.resolve(new Response(JSON.stringify(spec)))
103 }) as typeof fetch
104​
105 const fetched = await provider.fetchSpec({})
106 expect(urls).toEqual([SPEC_URL])
107 expect(fetched.outputStrategy).toBe('post-200')
108 expect(fetched.specs).toHaveLength(1)
109 expect(fetched.sources[0]?.url).toBe(SPEC_URL)
110 expect(fetched.sources[0]?.hash).toMatch(/^[0-9a-f]{64}$/)
111​
112 const { endpoints, warnings } = classifyAndBundle(provider, fetched)
113 expect(warnings).toEqual([])
114 expect(endpoints.map((e) => [e.path, e.activity])).toEqual([
115 ['/v1/text_to_video', 'video'],
116 ])
117 })
118})