d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
142 lines
4.7 KiB
TypeScript
142 lines
4.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
type TriggerInputKind,
|
|
type TriggerRunOption,
|
|
validateTriggerInput,
|
|
} from '@/lib/workflows/triggers/run-options'
|
|
import { StartBlockPath } from '@/lib/workflows/triggers/triggers'
|
|
import type { InputFormatField } from '@/lib/workflows/types'
|
|
|
|
function makeOption(overrides: Partial<TriggerRunOption>): TriggerRunOption {
|
|
const inputKind: TriggerInputKind = overrides.inputKind ?? 'fields'
|
|
return {
|
|
triggerBlockId: 'blk_1',
|
|
blockName: 'Test Trigger',
|
|
triggerType: 'api_trigger',
|
|
path: StartBlockPath.SPLIT_API,
|
|
isDefault: true,
|
|
inputKind,
|
|
inputSchema: { type: 'object' },
|
|
mockPayload: {},
|
|
inputFormat: [],
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
const fields = (...f: InputFormatField[]): InputFormatField[] => f
|
|
|
|
describe('validateTriggerInput', () => {
|
|
describe('fields', () => {
|
|
it('accepts input that provides all declared fields with correct types', () => {
|
|
const option = makeOption({
|
|
inputFormat: fields({ name: 'city', type: 'string' }, { name: 'days', type: 'number' }),
|
|
})
|
|
expect(validateTriggerInput(option, { city: 'SF', days: 3 }).ok).toBe(true)
|
|
})
|
|
|
|
it('rejects a missing required field (no default)', () => {
|
|
const option = makeOption({ inputFormat: fields({ name: 'city', type: 'string' }) })
|
|
const result = validateTriggerInput(option, {})
|
|
expect(result.ok).toBe(false)
|
|
expect(result.error).toContain('city')
|
|
})
|
|
|
|
it('treats a field with an author default as optional (matches executor)', () => {
|
|
const option = makeOption({
|
|
inputFormat: fields(
|
|
{ name: 'city', type: 'string' },
|
|
{ name: 'limit', type: 'number', value: 10 }
|
|
),
|
|
})
|
|
// limit omitted -> still valid because the workflow defaults it
|
|
expect(validateTriggerInput(option, { city: 'SF' }).ok).toBe(true)
|
|
})
|
|
|
|
it('rejects a wrong field type', () => {
|
|
const option = makeOption({ inputFormat: fields({ name: 'days', type: 'number' }) })
|
|
expect(validateTriggerInput(option, { days: 'three' }).ok).toBe(false)
|
|
})
|
|
|
|
it('rejects unknown keys for non-UNIFIED triggers', () => {
|
|
const option = makeOption({
|
|
path: StartBlockPath.SPLIT_API,
|
|
inputFormat: fields({ name: 'city', type: 'string' }),
|
|
})
|
|
expect(validateTriggerInput(option, { city: 'SF', extra: 1 }).ok).toBe(false)
|
|
})
|
|
|
|
it('allows passthrough keys for UNIFIED start blocks', () => {
|
|
const option = makeOption({
|
|
path: StartBlockPath.UNIFIED,
|
|
triggerType: 'start_trigger',
|
|
inputFormat: fields({ name: 'city', type: 'string' }),
|
|
})
|
|
expect(validateTriggerInput(option, { city: 'SF', files: [], conversationId: 'c1' }).ok).toBe(
|
|
true
|
|
)
|
|
})
|
|
|
|
it('accepts an empty object when the trigger declares no fields', () => {
|
|
const option = makeOption({ inputFormat: [] })
|
|
expect(validateTriggerInput(option, {}).ok).toBe(true)
|
|
expect(validateTriggerInput(option, undefined).ok).toBe(true)
|
|
})
|
|
|
|
it('rejects non-object input when fields are declared', () => {
|
|
const option = makeOption({ inputFormat: fields({ name: 'city', type: 'string' }) })
|
|
expect(validateTriggerInput(option, 'SF').ok).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('event_payload', () => {
|
|
const option = makeOption({
|
|
inputKind: 'event_payload',
|
|
path: StartBlockPath.EXTERNAL_TRIGGER,
|
|
triggerType: 'gmail',
|
|
})
|
|
|
|
it('accepts a non-empty object', () => {
|
|
expect(validateTriggerInput(option, { email: { from: 'a@b.com' } }).ok).toBe(true)
|
|
})
|
|
|
|
it('rejects an empty object', () => {
|
|
expect(validateTriggerInput(option, {}).ok).toBe(false)
|
|
})
|
|
|
|
it('rejects missing/non-object input', () => {
|
|
expect(validateTriggerInput(option, undefined).ok).toBe(false)
|
|
expect(validateTriggerInput(option, []).ok).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('chat', () => {
|
|
const option = makeOption({
|
|
inputKind: 'chat',
|
|
path: StartBlockPath.SPLIT_CHAT,
|
|
triggerType: 'chat_trigger',
|
|
})
|
|
|
|
it('accepts a non-empty input string', () => {
|
|
expect(validateTriggerInput(option, { input: 'hello' }).ok).toBe(true)
|
|
})
|
|
|
|
it('rejects empty or missing input', () => {
|
|
expect(validateTriggerInput(option, {}).ok).toBe(false)
|
|
expect(validateTriggerInput(option, { input: '' }).ok).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('none', () => {
|
|
const option = makeOption({
|
|
inputKind: 'none',
|
|
path: StartBlockPath.EXTERNAL_TRIGGER,
|
|
triggerType: 'schedule',
|
|
})
|
|
|
|
it('accepts any input (no input required)', () => {
|
|
expect(validateTriggerInput(option, undefined).ok).toBe(true)
|
|
expect(validateTriggerInput(option, { anything: 1 }).ok).toBe(true)
|
|
})
|
|
})
|
|
})
|