mirror of
https://github.com/langgenius/dify.git
synced 2026-07-25 21:48:30 +08:00
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { CONFIG_FILE_NAME } from '@/store/manager'
|
|
import {
|
|
ALLOWED_FORMATS,
|
|
ConfigFileSchema,
|
|
CURRENT_SCHEMA_VERSION,
|
|
emptyConfig,
|
|
} from './schema'
|
|
|
|
describe('config schema', () => {
|
|
it('CURRENT_SCHEMA_VERSION is 1', () => {
|
|
expect(CURRENT_SCHEMA_VERSION).toBe(1)
|
|
})
|
|
|
|
it('CONFIG_FILE_NAME is config.yml', () => {
|
|
expect(CONFIG_FILE_NAME).toBe('config.yml')
|
|
})
|
|
|
|
it('ALLOWED_FORMATS matches Go set (json/yaml/table/wide/name/text)', () => {
|
|
expect([...ALLOWED_FORMATS].sort()).toEqual(
|
|
['json', 'name', 'table', 'text', 'wide', 'yaml'],
|
|
)
|
|
})
|
|
|
|
it('emptyConfig fills defaults + state with empty objects', () => {
|
|
const cfg = emptyConfig()
|
|
expect(cfg.schema_version).toBe(0)
|
|
expect(cfg.defaults).toEqual({})
|
|
expect(cfg.state).toEqual({})
|
|
})
|
|
|
|
it('rejects defaults.limit out of bounds', () => {
|
|
expect(ConfigFileSchema.safeParse({ defaults: { limit: 0 } }).success).toBe(false)
|
|
expect(ConfigFileSchema.safeParse({ defaults: { limit: 201 } }).success).toBe(false)
|
|
expect(ConfigFileSchema.safeParse({ defaults: { limit: 50 } }).success).toBe(true)
|
|
})
|
|
|
|
it('rejects defaults.format outside the enum', () => {
|
|
expect(ConfigFileSchema.safeParse({ defaults: { format: 'csv' } }).success).toBe(false)
|
|
expect(ConfigFileSchema.safeParse({ defaults: { format: 'json' } }).success).toBe(true)
|
|
})
|
|
|
|
it('accepts the full v1 shape', () => {
|
|
const r = ConfigFileSchema.safeParse({
|
|
schema_version: 1,
|
|
defaults: { format: 'yaml', limit: 100 },
|
|
state: { current_app: 'app-123' },
|
|
})
|
|
expect(r.success).toBe(true)
|
|
if (r.success) {
|
|
expect(r.data.defaults.format).toBe('yaml')
|
|
expect(r.data.defaults.limit).toBe(100)
|
|
expect(r.data.state.current_app).toBe('app-123')
|
|
}
|
|
})
|
|
|
|
it('parses an empty object into emptyConfig() shape', () => {
|
|
const r = ConfigFileSchema.safeParse({})
|
|
expect(r.success).toBe(true)
|
|
if (r.success)
|
|
expect(r.data).toEqual(emptyConfig())
|
|
})
|
|
})
|