:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { HogFlow } from '~/cdp/schema/hogflow'
import { PostgresRouter, PostgresUse } from '~/common/utils/db/postgres'
import { UUIDT } from '~/common/utils/utils'
import { insertRow } from '~/tests/helpers/sql'
import { CyclotronJobInvocationHogFlow, CyclotronPerson, HogFlowInvocationContext } from '../types'
import { convertToHogFunctionFilterGlobal } from '../utils/hog-function-filtering'
import { createHogExecutionGlobals } from './fixtures'
export const insertHogFlow = async (postgres: PostgresRouter, hogFlow: HogFlow): Promise<HogFlow> => {
// This is only used for testing so we need to override some values
const res = await insertRow(postgres, 'posthog_hogflow', {
...hogFlow,
description: '',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
created_by_id: null,
})
return res
}
export const hideHogFlowsFromReplica = (
postgres: PostgresRouter,
ids: HogFlow['id'][]
): jest.SpyInstance<ReturnType<PostgresRouter['query']>, Parameters<PostgresRouter['query']>> => {
const query = postgres.query.bind(postgres)
return jest.spyOn(postgres, 'query').mockImplementation(async (target, queryString, values, tag, logLevel) => {
const result = await query(target, queryString, values, tag, logLevel)
if (target === PostgresUse.COMMON_READ && tag === 'fetchHogFlows') {
return { ...result, rows: result.rows.filter((row) => !ids.includes(row.id)) }
}
return result
})
}
export const createHogFlowInvocationContext = (
data: Partial<HogFlowInvocationContext> = {}
): HogFlowInvocationContext => {
return {
event: {
...createHogExecutionGlobals().event,
...data.event,
},
actionStepCount: 0,
...data,
}
}
export const createExampleHogFlowInvocation = (
hogFlow: HogFlow,
_context: Partial<HogFlowInvocationContext> = {},
_person: Partial<CyclotronPerson> | undefined = undefined
): CyclotronJobInvocationHogFlow => {
// Add the source of the trigger to the globals
const context = createHogFlowInvocationContext(_context)
const person: CyclotronPerson = {
id: 'person_id',
properties: {
name: 'John Doe',
},
name: 'John Doe',
url: '',
..._person,
}
return {
id: new UUIDT().toString(),
state: {
...context,
},
teamId: hogFlow.team_id,
functionId: hogFlow.id,
hogFlow,
person,
filterGlobals: convertToHogFunctionFilterGlobal({
event: context.event,
person,
groups: {},
variables: context.variables || {},
}),
queue: 'hogflow',
queuePriority: 0,
}
}