Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.7 KB
Raw Blame
import { describe, expect, it } from 'vite-plus/test'
import {
  zGetAppsByAppIdExportResponse,
  zPostAppsImportsBody,
} from './generated/api/console/apps/zod.gen.ts'
import { zPostFilesUploadBody } from './generated/api/console/files/zod.gen.ts'
import { zPostWorkspacesCurrentPluginUploadPkgBody } from './generated/api/console/workspaces/zod.gen.ts'

describe('generated binary schemas', () => {
  it('accepts binary package imports alongside YAML import requests', () => {
    const file = new File(['PK'], 'agent.ifpkg', { type: 'application/zip' })
    expect(zPostAppsImportsBody.safeParse({ file }).success).toBe(true)
    expect(
      zPostAppsImportsBody.safeParse({ mode: 'yaml-content', yaml_content: 'kind: app' }).success,
    ).toBe(true)
    expect(zPostAppsImportsBody.safeParse({ file: 'not a binary file' }).success).toBe(false)
  })

  it('accepts both Agent archives and YAML JSON export responses', () => {
    const archive = new File(['PK'], 'agent.ifpkg', { type: 'application/zip' })
    expect(zGetAppsByAppIdExportResponse.safeParse(archive).success).toBe(true)
    expect(zGetAppsByAppIdExportResponse.safeParse({ data: 'kind: app' }).success).toBe(true)
    expect(zGetAppsByAppIdExportResponse.safeParse('kind: app').success).toBe(false)
  })

  it.each([
    ['file upload', zPostFilesUploadBody, 'file'],
    ['plugin package upload', zPostWorkspacesCurrentPluginUploadPkgBody, 'pkg'],
  ] as const)('validates %s values at runtime', (_, schema, field) => {
    const file = new File(['test'], 'test.txt', { type: 'text/plain' })

    expect(schema.safeParse({ [field]: file }).success).toBe(true)
    expect(schema.safeParse({ [field]: 123 }).success).toBe(false)
  })
})