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

byteplus-video-duration.test.ts

140 lines4.3 KB

1import { Validator } from '@cfworker/json-schema'
2import { describe, expect, it } from 'vitest'
3​
4import {
5 seedanceActivityRequests,
6 uncoveredSeedanceIds,
7} from './byteplus-video-duration.ts'
8​
9const storedDuration = {
10 type: 'integer',
11 description: 'Whole seconds. The shared schema states no per-model bounds.',
13​
14function createSchema(): {
15 type: string
16 properties: { model: { type: string }; duration: typeof storedDuration }
17} {
18 return {
19 type: 'object',
20 properties: {
21 model: { type: 'string' },
22 duration: storedDuration,
23 },
24 }
26​
27function variantsFor(rawIds: Array<string>) {
28 return seedanceActivityRequests({
29 path: '/contents/generations/tasks',
30 method: 'POST',
31 schema: createSchema(),
32 rawIds,
33 })
35​
36describe('seedanceActivityRequests', () => {
37 it('keeps an uncovered listed model on the stored duration', () => {
38 const variants = variantsFor([
39 'dreamina-seedance-2-5-260628',
40 'dreamina-not-in-the-duration-table',
41 'dreamina-not-in-the-duration-table',
42 ])
43 expect(variants?.map((variant) => variant.rawId)).toEqual([
44 'dreamina-seedance-2-5-260628',
45 'dreamina-not-in-the-duration-table',
46 ])
47 const extra = variants?.[1]
48 expect(extra?.rawId).toBe('dreamina-not-in-the-duration-table')
49 if (!extra) return
50 const schema = extra.schema as {
51 properties: { model: { enum: Array<string> }; duration: unknown }
52 }
53 expect(schema.properties.model.enum).toEqual([
54 'dreamina-not-in-the-duration-table',
55 ])
56 expect(schema.properties.duration).toEqual(storedDuration)
57 expect(schema.properties.duration).not.toHaveProperty('minimum')
58 })
59​
60 it('states 4–30 seconds and -1 for Seedance 2.5 flash', () => {
61 const variant = variantsFor(['dreamina-seedance-2-5-flash-261115'])?.[0]
62 expect(variant?.rawId).toBe('dreamina-seedance-2-5-flash-261115')
63 if (!variant) return
64 const schema = variant.schema as {
65 properties: {
66 duration: {
67 minimum?: number
68 anyOf?: Array<{ minimum?: number; maximum?: number; const?: number }>
69 }
70 }
71 }
72 const duration = schema.properties.duration
73 expect(duration.minimum).toBeUndefined()
74 expect(duration.anyOf?.[0]).toMatchObject({ minimum: 4, maximum: 30 })
75 expect(duration.anyOf?.[1]).toMatchObject({ const: -1 })
76 })
77​
78 it('accepts -1 for Seedance 2.0 fast and mini', () => {
79 const variants = variantsFor([
80 'dreamina-seedance-2-0-fast-260128',
81 'dreamina-seedance-2-0-mini-260615',
82 'seedance-1-0-pro-fast-251015',
83 ])
84 const durationOf = (rawId: string) => {
85 const variant = variants?.find((item) => item.rawId === rawId)
86 expect(variant).toBeDefined()
87 if (!variant) return undefined
88 const schema = variant.schema as {
89 properties: { duration: Record<string, unknown> }
90 }
91 return schema.properties.duration
92 }
93 for (const rawId of [
94 'dreamina-seedance-2-0-fast-260128',
95 'dreamina-seedance-2-0-mini-260615',
96 ]) {
97 const duration = durationOf(rawId)
98 expect(duration).toBeDefined()
99 if (!duration) return
100 expect(duration.minimum).toBeUndefined()
101 const validator = new Validator(duration, '2020-12', false)
102 expect(validator.validate(-1).valid).toBe(true)
103 expect(validator.validate(4).valid).toBe(true)
104 expect(validator.validate(15).valid).toBe(true)
105 expect(validator.validate(3).valid).toBe(false)
106 expect(validator.validate(16).valid).toBe(false)
107 }
108 const proFast = durationOf('seedance-1-0-pro-fast-251015')
109 expect(proFast).toBeDefined()
110 if (!proFast) return
111 expect(new Validator(proFast, '2020-12', false).validate(-1).valid).toBe(
112 false,
113 )
114 })
115​
116 it('leaves a non-create operation alone', () => {
117 expect(
118 seedanceActivityRequests({
119 path: '/contents/generations/tasks/{id}',
120 method: 'GET',
121 schema: createSchema(),
122 rawIds: ['dreamina-not-in-the-duration-table'],
123 }),
124 ).toBeUndefined()
125 expect(variantsFor([])).toBeUndefined()
126 })
127})
128​
129describe('uncoveredSeedanceIds', () => {
130 it('names each missing id once and skips a row that exists', () => {
131 expect(
132 uncoveredSeedanceIds([
133 'dreamina-seedance-2-5-flash-261115',
134 'zzz-new',
135 'aaa-new',
136 'zzz-new',
137 ]),
138 ).toEqual(['zzz-new', 'aaa-new'])
139 })
140})