Files
insights/services/mcp/tests/unit/workflows-config-schema.test.ts
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

121 lines
4.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { InsightsFlowsCreateBody } from '@/generated/workflows/api'
// The MCP executor passes the zod-PARSED tool input to handlers, and a matched zod object branch
// strips keys it doesn't declare. The action config schema is a union with a free-form branch
// first, so parsing must preserve every config verbatim — the typed wait_until_condition branch
// is shape guidance only. These tests pin that invariant.
describe('workflows create schema — action config', () => {
const triggerAction = {
id: 'trigger_node',
name: 'Trigger',
type: 'trigger',
config: {
type: 'event',
filters: { events: [{ id: '$pageview', name: '$pageview', type: 'events', order: 0 }] },
},
}
it('accepts a wait_until_condition action with events to wait for and preserves config verbatim', () => {
const waitConfig = {
condition: {
filters: { properties: [{ key: 'plan', value: ['growth'], operator: 'exact', type: 'person' }] },
name: 'If plan is growth',
},
events: [
{
filters: { events: [{ id: 'purchase', name: 'purchase', type: 'events', order: 0 }] },
name: 'Purchase happened',
},
],
max_wait_duration: '30m',
// Undeclared key: must survive parsing — proves the free-form union branch wins and
// the typed branch never strips.
some_future_key: 'must survive',
}
const result = InsightsFlowsCreateBody.safeParse({
name: 'Wait until workflow',
actions: [
triggerAction,
{ id: 'wait_1', name: 'Wait for purchase', type: 'wait_until_condition', config: waitConfig },
],
})
expect(result.success).toBe(true)
if (!result.success) {
throw new Error(result.error.message)
}
expect(result.data.actions[1]?.config).toEqual(waitConfig)
})
it('accepts an events-only wait (no condition) and preserves config verbatim', () => {
// The runtime supports waits with only events to wait for; 'condition' must not be
// schema-required, or agents would be nudged into adding an empty condition to satisfy it.
const waitConfig = {
events: [
{
filters: { events: [{ id: 'purchase', name: 'purchase', type: 'events', order: 0 }] },
},
],
max_wait_duration: '1h',
}
const result = InsightsFlowsCreateBody.safeParse({
name: 'Events-only wait workflow',
actions: [
triggerAction,
{ id: 'wait_1', name: 'Wait for purchase', type: 'wait_until_condition', config: waitConfig },
],
})
expect(result.success).toBe(true)
if (!result.success) {
throw new Error(result.error.message)
}
expect(result.data.actions[1]?.config).toEqual(waitConfig)
})
it('accepts an empty condition and preserves it (runtime ignores it, relying on events/timeout)', () => {
const waitConfig = {
condition: { filters: {} },
events: [
{
filters: { events: [{ id: 'purchase', name: 'purchase', type: 'events', order: 0 }] },
},
],
max_wait_duration: '30m',
}
const result = InsightsFlowsCreateBody.safeParse({
name: 'Empty condition wait workflow',
actions: [
triggerAction,
{ id: 'wait_1', name: 'Wait for purchase', type: 'wait_until_condition', config: waitConfig },
],
})
expect(result.success).toBe(true)
if (!result.success) {
throw new Error(result.error.message)
}
expect(result.data.actions[1]?.config).toEqual(waitConfig)
})
it('preserves other action type configs verbatim', () => {
const functionConfig = {
template_id: 'template-webhook',
inputs: { url: { value: 'https://example.com' } },
}
const result = InsightsFlowsCreateBody.safeParse({
name: 'Function workflow',
actions: [triggerAction, { id: 'fn_1', name: 'Webhook', type: 'function', config: functionConfig }],
})
expect(result.success).toBe(true)
if (!result.success) {
throw new Error(result.error.message)
}
expect(result.data.actions[0]?.config).toEqual(triggerAction.config)
expect(result.data.actions[1]?.config).toEqual(functionConfig)
})
})