: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
feat(workflows): hide the test event for triggers that run without an event (#115366)
Meikel Ratz7ddcaf329287
diff --git a/products/workflows/frontend/Workflows/hogflows/panel/testing/HogFlowEditorPanelTest.tsx b/products/workflows/frontend/Workflows/hogflows/panel/testing/HogFlowEditorPanelTest.tsxindex 96a7ade6003a..923aeaf0cd93 100644--- a/products/workflows/frontend/Workflows/hogflows/panel/testing/HogFlowEditorPanelTest.tsx+++ b/products/workflows/frontend/Workflows/hogflows/panel/testing/HogFlowEditorPanelTest.tsx@@ -2,34 +2,16 @@ import { useActions, useValues } from 'kea'import { Form } from 'kea-forms'import { useEffect } from 'react'-import { IconInfo, IconPlayFilled, IconRedo, IconTestTube } from '@posthog/icons'-import {- LemonBanner,- LemonButton,- LemonCollapse,- LemonDivider,- LemonLabel,- LemonSwitch,- Link,- ProfilePicture,- Spinner,- Tooltip,-} from '@posthog/lemon-ui'+import { IconInfo, IconPlayFilled, IconTestTube } from '@posthog/icons'+import { LemonBanner, LemonButton, LemonDivider, LemonLabel, LemonSwitch, Tooltip } from '@posthog/lemon-ui'-import { TaxonomicFilter } from 'lib/components/TaxonomicFilter/TaxonomicFilter'-import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'-import { TZLabel } from 'lib/components/TZLabel'import { LemonField } from 'lib/lemon-ui/LemonField'-import { Popover } from 'lib/lemon-ui/Popover/Popover'-import { HogFunctionTestEditor } from 'scenes/hog-functions/configuration/HogFunctionTest'import { LogsViewerTable } from 'scenes/hog-functions/logs/LogsViewer'-import { urls } from 'scenes/urls'--import { asDisplay } from 'products/persons/frontend/person-utils'import { renderWorkflowLogMessage } from '../../../logs/log-utils'import { TRIGGER_NODE_ID, workflowLogic } from '../../../workflowLogic'import { hogFlowEditorLogic } from '../../hogFlowEditorLogic'+import { HogFlowEditorTestEvent } from './HogFlowEditorTestEvent'import { hogFlowEditorTestLogic } from './hogFlowEditorTestLogic'export function HogFlowTestPanelNonSelected(): JSX.Element {@@ -47,32 +29,10 @@ export function HogFlowEditorPanelTest(): JSX.Element | null {const { setSelectedNodeId } = useActions(hogFlowEditorLogic)const { logicProps } = useValues(workflowLogic)- const {- sampleGlobals,- sampleGlobalsLoading,- sampleGlobalsError,- noMatchingEvents,- canTryExtendedSearch,- isTestInvocationSubmitting,- testResult,- shouldLoadSampleGlobals,- nextActionId,- eventPanelOpen,- eventSelectorOpen,- lastSearchedEventName,- } = useValues(hogFlowEditorTestLogic(logicProps))- const {- submitTestInvocation,- setTestResult,- loadSampleGlobals,- loadSampleEventByName,- setSampleGlobals,- setEventPanelOpen,- setEventSelectorOpen,- } = useActions(hogFlowEditorTestLogic(logicProps))-- const display = asDisplay(sampleGlobals?.person)- const url = urls.personByDistinctId(sampleGlobals?.event?.distinct_id || '')+ const { sampleGlobals, isTestInvocationSubmitting, testResult, nextActionId, showTestEvent } = useValues(+ hogFlowEditorTestLogic(logicProps)+ )+ const { submitTestInvocation, setTestResult } = useActions(hogFlowEditorTestLogic(logicProps))useEffect(() => {setTestResult(null)@@ -176,151 +136,12 @@ export function HogFlowEditorPanelTest(): JSX.Element | null {</div><LemonDivider className="my-0" /><div className="flex flex-col flex-1 overflow-y-auto">- {/* Event Information */}- <div className="flex-0">- <LemonCollapse- embedded- multiple- activeKeys={eventPanelOpen}- onChange={setEventPanelOpen}- panels={[- {- key: 'event',- header: sampleGlobalsLoading ? (- <>- Loading test event... <Spinner />- </>- ) : (- <>Test event: {sampleGlobals?.event?.event} </>- ),- className: 'bg-surface-secondary',- content: (- <div>- <div className="bg-surface-secondary">- {sampleGlobalsError && (- <div>- <LemonBanner type="info" className="mb-2">- {sampleGlobalsError}- </LemonBanner>- {canTryExtendedSearch && (- <div className="mb-2 text-center">- <LemonButton- type="primary"- onClick={() => {- if (shouldLoadSampleGlobals) {- loadSampleGlobals({ extendedSearch: true })- } else {- // For non-event triggers, reload with the last searched event name- loadSampleEventByName({- eventName:- lastSearchedEventName || '$pageview',- extendedSearch: true,- })- }- }}- loading={sampleGlobalsLoading}- >- Try searching last 30 days (slower)- </LemonButton>- </div>- )}- </div>- )}- <div className="flex gap-2 items-center">- <ProfilePicture name={display} />- <div className="flex-1">- {sampleGlobals?.person ? (- <Link to={url} className="flex gap-2 items-center">- <span className="font-semibold">{display}</span>- </Link>- ) : sampleGlobals ? (- <span className="text-muted">No associated person</span>- ) : (- <span className="text-muted">Loading...</span>- )}{' '}- <span className="text-muted">performed</span>{' '}- <span className="space-y-1 font-semibold text-md">- {sampleGlobals?.event?.event}- </span>{' '}- {sampleGlobals?.event?.timestamp && (- <TZLabel time={sampleGlobals?.event?.timestamp} />- )}- </div>- {shouldLoadSampleGlobals ? (- <LemonButton- type="secondary"- onClick={() => loadSampleGlobals()}- tooltip={- noMatchingEvents- ? 'No events match the current filters. Try adjusting your trigger filters.'- : 'Find the last event matching the trigger event filters, and use it to populate the globals for a test run.'- }- disabledReason={- noMatchingEvents- ? 'No matching events found - adjust your trigger filters'- : undefined- }- icon={<IconRedo />}- size="small"- >- Load new event- </LemonButton>- ) : (- <Popover- overlay={- <TaxonomicFilter- groupType={TaxonomicFilterGroupType.Events}- value={sampleGlobals?.event?.event || ''}- onChange={(_, value) => {- if (typeof value === 'string') {- loadSampleEventByName({ eventName: value })- }- }}- allowNonCapturedEvents- taxonomicGroupTypes={[- TaxonomicFilterGroupType.CustomEvents,- TaxonomicFilterGroupType.Events,- ]}- />- }- visible={eventSelectorOpen}- onClickOutside={() => setEventSelectorOpen(false)}- placement="bottom-end"- >- <LemonButton- type="secondary"- onClick={() => setEventSelectorOpen(!eventSelectorOpen)}- tooltip="Select an event type to load test data"- size="small"- >- {sampleGlobals?.event?.event || 'Select event'}- </LemonButton>- </Popover>- )}- </div>-- {/* Event Properties */}- {sampleGlobals && (- <>- <div className="text-sm mt-2">- Here are all the global variables you can use in your workflow:- </div>- <div className="flex-col gap-2 my-3 max-h-48 overflow-auto">- <HogFunctionTestEditor- value={JSON.stringify(sampleGlobals, null, 2)}- onChange={setSampleGlobals}- />- </div>- </>- )}- </div>- </div>- ),- },- ]}- />- </div>- <LemonDivider className="my-0" />+ {showTestEvent && (+ <>+ <HogFlowEditorTestEvent />+ <LemonDivider className="my-0" />+ </>+ )}<div className="flex flex-col flex-1 gap-2 p-2"><h3 className="mb-0">Test results</h3>{!testResult ? (diff --git a/products/workflows/frontend/Workflows/hogflows/panel/testing/HogFlowEditorTestEvent.tsx b/products/workflows/frontend/Workflows/hogflows/panel/testing/HogFlowEditorTestEvent.tsxnew file mode 100644index 000000000000..fe96aba925ee--- /dev/null+++ b/products/workflows/frontend/Workflows/hogflows/panel/testing/HogFlowEditorTestEvent.tsx@@ -0,0 +1,181 @@+import { useActions, useValues } from 'kea'++import { IconRedo } from '@posthog/icons'+import { LemonBanner, LemonButton, LemonCollapse, Link, ProfilePicture, Spinner } from '@posthog/lemon-ui'++import { TaxonomicFilter } from 'lib/components/TaxonomicFilter/TaxonomicFilter'+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'+import { TZLabel } from 'lib/components/TZLabel'+import { Popover } from 'lib/lemon-ui/Popover/Popover'+import { HogFunctionTestEditor } from 'scenes/hog-functions/configuration/HogFunctionTest'+import { urls } from 'scenes/urls'++import { asDisplay } from 'products/persons/frontend/person-utils'++import { workflowLogic } from '../../../workflowLogic'+import { hogFlowEditorTestLogic } from './hogFlowEditorTestLogic'++export function HogFlowEditorTestEvent(): JSX.Element {+ const { logicProps } = useValues(workflowLogic)+ const {+ sampleGlobals,+ sampleGlobalsLoading,+ sampleGlobalsError,+ noMatchingEvents,+ canTryExtendedSearch,+ shouldLoadSampleGlobals,+ eventPanelOpen,+ eventSelectorOpen,+ lastSearchedEventName,+ } = useValues(hogFlowEditorTestLogic(logicProps))+ const { loadSampleGlobals, loadSampleEventByName, setSampleGlobals, setEventPanelOpen, setEventSelectorOpen } =+ useActions(hogFlowEditorTestLogic(logicProps))++ const display = asDisplay(sampleGlobals?.person)+ const url = urls.personByDistinctId(sampleGlobals?.event?.distinct_id || '')++ return (+ <div className="flex-0">+ <LemonCollapse+ embedded+ multiple+ activeKeys={eventPanelOpen}+ onChange={setEventPanelOpen}+ panels={[+ {+ key: 'event',+ header: sampleGlobalsLoading ? (+ <>+ Loading test event... <Spinner />+ </>+ ) : (+ <>Test event: {sampleGlobals?.event?.event} </>+ ),+ className: 'bg-surface-secondary',+ content: (+ <div>+ <div className="bg-surface-secondary">+ {sampleGlobalsError && (+ <div>+ <LemonBanner type="info" className="mb-2">+ {sampleGlobalsError}+ </LemonBanner>+ {canTryExtendedSearch && (+ <div className="mb-2 text-center">+ <LemonButton+ type="primary"+ onClick={() => {+ if (shouldLoadSampleGlobals) {+ loadSampleGlobals({ extendedSearch: true })+ } else {+ // For non-event triggers, reload with the last searched event name+ loadSampleEventByName({+ eventName: lastSearchedEventName || '$pageview',+ extendedSearch: true,+ })+ }+ }}+ loading={sampleGlobalsLoading}+ >+ Try searching last 30 days (slower)+ </LemonButton>+ </div>+ )}+ </div>+ )}+ <div className="flex gap-2 items-center">+ <ProfilePicture name={display} />+ <div className="flex-1">+ {sampleGlobals?.person ? (+ <Link to={url} className="flex gap-2 items-center">+ <span className="font-semibold">{display}</span>+ </Link>+ ) : sampleGlobals ? (+ <span className="text-muted">No associated person</span>+ ) : (+ <span className="text-muted">Loading...</span>+ )}{' '}+ <span className="text-muted">performed</span>{' '}+ <span className="space-y-1 font-semibold text-md">+ {sampleGlobals?.event?.event}+ </span>{' '}+ {sampleGlobals?.event?.timestamp && (+ <TZLabel time={sampleGlobals?.event?.timestamp} />+ )}+ </div>+ {shouldLoadSampleGlobals ? (+ <LemonButton+ type="secondary"+ onClick={() => loadSampleGlobals()}+ tooltip={+ noMatchingEvents+ ? 'No events match the current filters. Try adjusting your trigger filters.'+ : 'Find the last event matching the trigger event filters, and use it to populate the globals for a test run.'+ }+ disabledReason={+ noMatchingEvents+ ? 'No matching events found - adjust your trigger filters'+ : undefined+ }+ icon={<IconRedo />}+ size="small"+ >+ Load new event+ </LemonButton>+ ) : (+ <Popover+ overlay={+ <TaxonomicFilter+ groupType={TaxonomicFilterGroupType.Events}+ value={sampleGlobals?.event?.event || ''}+ onChange={(_, value) => {+ if (typeof value === 'string') {+ loadSampleEventByName({ eventName: value })+ }+ }}+ allowNonCapturedEvents+ taxonomicGroupTypes={[+ TaxonomicFilterGroupType.CustomEvents,+ TaxonomicFilterGroupType.Events,+ ]}+ />+ }+ visible={eventSelectorOpen}+ onClickOutside={() => setEventSelectorOpen(false)}+ placement="bottom-end"+ >+ <LemonButton+ type="secondary"+ onClick={() => setEventSelectorOpen(!eventSelectorOpen)}+ tooltip="Select an event type to load test data"+ size="small"+ >+ {sampleGlobals?.event?.event || 'Select event'}+ </LemonButton>+ </Popover>+ )}+ </div>++ {/* Event Properties */}+ {sampleGlobals && (+ <>+ <div className="text-sm mt-2">+ Here are all the global variables you can use in your workflow:+ </div>+ <div className="flex-col gap-2 my-3 max-h-48 overflow-auto">+ <HogFunctionTestEditor+ value={JSON.stringify(sampleGlobals, null, 2)}+ onChange={setSampleGlobals}+ />+ </div>+ </>+ )}+ </div>+ </div>+ ),+ },+ ]}+ />+ </div>+ )+}diff --git a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.test.ts b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.test.tsindex 5a3c4b3eb290..0397ea25cb46 100644--- a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.test.ts+++ b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.test.ts@@ -512,6 +512,31 @@ describe('hogFlowEditorTestLogic', () => {})})+ describe('showTestEvent', () => {+ it.each([+ [{ type: 'event', filters: {} }, true],+ [{ type: 'webhook', template_id: 'template-source-webhook', inputs: {} }, true],+ [{ type: 'tracking_pixel', template_id: 'template-source-tracking-pixel', inputs: {} }, true],+ [{ type: 'schedule' }, false],+ [{ type: 'manual', template_id: 'template-source-manual', inputs: {} }, false],+ [{ type: 'batch', filters: { properties: [] } }, false],+ ])('for a %o trigger is %s', async (config, expected) => {+ logic = hogFlowEditorTestLogic({ id: 'test-workflow' })+ logic.mount()+ const flowLogic = workflowLogic({ id: 'test-workflow' })+ await expectLogic(flowLogic).toDispatchActions(['loadWorkflowSuccess'])++ flowLogic.actions.setWorkflowValue(+ 'actions',+ WORKFLOW_FIXTURE.actions.map((action) =>+ action.id === 'trigger_node' ? { ...action, config } : action+ )+ )++ expect(logic.values.showTestEvent).toBe(expected)+ })+ })+describe('groupTypesForTest gating on group_analytics', () => {const orgWithFeatures = (features: AvailableFeature[]): OrganizationType => ({...MOCK_DEFAULT_ORGANIZATION,diff --git a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.tsindex 8d99583b6056..724eae28bdff 100644--- a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts+++ b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts@@ -100,6 +100,8 @@ export const parseGroupsFromResult = (return groups}+const NON_EVENT_TRIGGER_TYPES: TriggerAction['config']['type'][] = ['schedule', 'manual', 'batch']+export const createGlobalsFromResponse = (event: any,person: any,@@ -168,6 +170,7 @@ export interface hogFlowEditorTestLogicValues {sampleGlobalsStale: booleanshouldFilterTestAccounts: booleanshouldLoadSampleGlobals: boolean+ showTestEvent: booleanshowTestInvocationErrors: booleantestInvocation: HogflowTestInvocationtestInvocationAllErrors: Record<string, any>@@ -458,6 +461,135 @@ export interface hogFlowEditorTestLogicMeta {} & Record<string, unknown>)| null) => boolean+ showTestEvent: (+ triggerAction:+ | ({+ config:+ | {+ type: 'schedule'+ }+ | {+ filters: {+ all_roles_unassigned?: boolean | undefined+ assigned_to_user_ids?: number[] | undefined+ assignment_status?: 'all' | 'assigned' | 'unassigned' | undefined+ audience_type?: 'accounts' | 'persons' | undefined+ properties: any[]+ tag_names?: string[] | undefined+ }+ type: 'batch'+ }+ | {+ filters: {+ actions?: any[] | undefined+ events?: any[] | undefined+ filter_test_accounts?: boolean | undefined+ properties?: any[] | undefined+ }+ type: 'event'+ }+ | {+ filters: {+ events: any[]+ properties?: any[] | undefined+ source: 'internal-events'+ }+ type: 'internal-event'+ }+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-table'+ }+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }+ | {+ inputs: Record<+ string,+ {+ bytecode?: any+ order?: number | undefined+ secret?: boolean | undefined+ templating?: 'hog' | 'liquid' | undefined+ value: any+ }+ >+ template_id: string+ template_uuid?: string | undefined+ type: 'manual'+ }+ | {+ inputs: Record<+ string,+ {+ bytecode?: any+ order?: number | undefined+ secret?: boolean | undefined+ templating?: 'hog' | 'liquid' | undefined+ value: any+ }+ >+ template_id: string+ template_uuid?: string | undefined+ type: 'tracking_pixel'+ }+ | {+ inputs: Record<+ string,+ {+ bytecode?: any+ order?: number | undefined+ secret?: boolean | undefined+ templating?: 'hog' | 'liquid' | undefined+ value: any+ }+ >+ template_id: string+ template_uuid?: string | undefined+ type: 'webhook'+ }+ created_at?: number | undefined+ description: string+ filters?:+ | {+ actions?: any[] | undefined+ events?: any[] | undefined+ properties?: any[] | undefined+ }+ | null+ | undefined+ id: string+ name: string+ on_error?: 'abort' | 'continue' | null | undefined+ output_variable?:+ | {+ key: string+ label?: string | null | undefined+ result_path?: string | null | undefined+ spread?: boolean | null | undefined+ }+ | {+ key: string+ label?: string | null | undefined+ result_path?: string | null | undefined+ spread?: boolean | null | undefined+ }[]+ | null+ | undefined+ type: 'trigger'+ updated_at?: number | undefined+ } & Record<string, unknown>)+ | null+ ) => booleangroupTypesForTest: (groupsEnabled: boolean,groupTypes: Map<GroupTypeIndex, GroupType>@@ -1054,11 +1186,17 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([selectors(() => ({shouldLoadSampleGlobals: [(s) => [s.triggerAction],- (triggerAction: null | import('../../../workflowLogic').TriggerAction): boolean => {+ (triggerAction: TriggerAction | null): boolean => {// Only load samples if the trigger is eventreturn !!(triggerAction && triggerAction.config.type === 'event')},],+ // These triggers start a run without an event, so a test event has no effect on the run.+ showTestEvent: [+ (s) => [s.triggerAction],+ (triggerAction: TriggerAction | null): boolean =>+ !triggerAction || !NON_EVENT_TRIGGER_TYPES.includes(triggerAction.config.type),+ ],// Mirror real execution: the worker's getGroupsForEvent gates on group_analytics, so without// the addon the test run must also resolve no groups (otherwise a group condition could match// here but never in production).@@ -1071,7 +1209,7 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([// event from a test account that the live trigger would reject.shouldFilterTestAccounts: [(s) => [s.triggerAction],- (triggerAction: null | import('../../../workflowLogic').TriggerAction): boolean => {+ (triggerAction: TriggerAction | null): boolean => {if (!triggerAction || triggerAction.config.type !== 'event') {return false}@@ -1081,7 +1219,7 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([// TODO(workflows): DRY up matchingFilters with implementation in hogFunctionConfigurationLogicmatchingFilters: [(s) => [s.triggerAction],- (triggerAction: null | import('../../../workflowLogic').TriggerAction): PropertyGroupFilter => {+ (triggerAction: TriggerAction | null): PropertyGroupFilter => {if (!triggerAction || triggerAction.config.type !== 'event') {return {type: FilterLogicalOperator.And,@@ -1150,7 +1288,7 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([],workflowVariableDefaults: [(s) => [s.workflow],- (workflow: import('../../types').HogFlow): Record<string, any> =>+ (workflow: HogFlow): Record<string, any> =>workflow.variables?.reduce((acc, variable) => {acc[variable.key] = variable.default