Skip to content

: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.

fix(workflows): gate test-run groups on group_analytics (#62225)

Harley Alexander1f214df7c624
diff --git a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.test.ts b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.test.ts
index 52610322c15d..7318b3799819 100644
--- a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.test.ts
+++ b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.test.ts
@@ -1,7 +1,12 @@
+import { MOCK_DEFAULT_ORGANIZATION, MOCK_GROUP_TYPES } from 'lib/api.mock'
+
import { expectLogic } from 'kea-test-utils'
+import { useAvailableFeatures } from '~/mocks/features'
+import { useMocks } from '~/mocks/jest'
+import { groupsModel } from '~/models/groupsModel'
import { initKeaTests } from '~/test/init'
-import { GroupType, GroupTypeIndex } from '~/types'
+import { AvailableFeature, GroupType, GroupTypeIndex, OrganizationType } from '~/types'
import {
createGlobalsFromResponse,
@@ -109,6 +114,45 @@ describe('hogFlowEditorTestLogic', () => {
initKeaTests()
})
+ describe('groupTypesForTest gating on group_analytics', () => {
+ const orgWithFeatures = (features: AvailableFeature[]): OrganizationType => ({
+ ...MOCK_DEFAULT_ORGANIZATION,
+ available_product_features: features.map((key) => ({ key, name: key })),
+ })
+
+ it('exposes all group types when group_analytics is available', () => {
+ initKeaTests(true, undefined as any, undefined as any, orgWithFeatures([AvailableFeature.GROUP_ANALYTICS]))
+ useMocks({ get: { '/api/projects/:team/groups_types': MOCK_GROUP_TYPES } })
+ useAvailableFeatures([AvailableFeature.GROUP_ANALYTICS])
+ groupsModel.mount()
+ groupsModel.actions.loadAllGroupTypesSuccess(MOCK_GROUP_TYPES)
+ logic = hogFlowEditorTestLogic({ id: 'test-workflow' })
+ logic.mount()
+
+ expect(logic.values.groupsEnabled).toBe(true)
+ expect(logic.values.groupTypesForTest.size).toBe(MOCK_GROUP_TYPES.length)
+ expect(groupSelectColumns(logic.values.groupTypesForTest)).toHaveLength(MOCK_GROUP_TYPES.length)
+ })
+
+ it('resolves no group types without group_analytics, matching gated real execution', () => {
+ initKeaTests(true, undefined as any, undefined as any, orgWithFeatures([]))
+ useMocks({ get: { '/api/projects/:team/groups_types': MOCK_GROUP_TYPES } })
+ useAvailableFeatures([])
+ groupsModel.mount()
+ // Group types load ungated, mirroring groupsModel.afterMount in real usage
+ groupsModel.actions.loadAllGroupTypesSuccess(MOCK_GROUP_TYPES)
+ logic = hogFlowEditorTestLogic({ id: 'test-workflow' })
+ logic.mount()
+
+ expect(logic.values.groupsEnabled).toBe(false)
+ // groupsModel still loaded the types ungated...
+ expect(logic.values.groupTypes.size).toBe(MOCK_GROUP_TYPES.length)
+ // ...but the test run must not use them, so no group columns are queried and groups stay empty
+ expect(logic.values.groupTypesForTest.size).toBe(0)
+ expect(groupSelectColumns(logic.values.groupTypesForTest)).toEqual([])
+ })
+ })
+
describe('accumulatedVariables reducer', () => {
beforeEach(() => {
logic = hogFlowEditorTestLogic({ id: 'test-workflow' })
diff --git a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts
index 50d938d5f12c..64d45b9007f6 100644
--- a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts
+++ b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts
@@ -7,6 +7,7 @@ import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
import { dayjs } from 'lib/dayjs'
+import { groupsAccessLogic } from 'lib/introductions/groupsAccessLogic'
import { uuid } from 'lib/utils'
import { groupsModel } from '~/models/groupsModel'
@@ -179,6 +180,8 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([
['selectedNodeId'],
groupsModel,
['groupTypes'],
+ groupsAccessLogic,
+ ['groupsEnabled'],
],
actions: [hogFlowEditorLogic, ['setSelectedNodeId', 'setAnimatingEdgePair']],
})),
@@ -315,7 +318,7 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([
const query: EventsQuery = {
kind: NodeKind.EventsQuery,
fixedProperties: [values.matchingFilters],
- select: ['*', 'person', ...groupSelectColumns(values.groupTypes)],
+ select: ['*', 'person', ...groupSelectColumns(values.groupTypesForTest)],
after: timeRange,
limit: 10,
orderBy: ['timestamp DESC'],
@@ -368,7 +371,7 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([
const event = response.results[resultIndex][0]
const person = response.results[resultIndex][1]
- const groups = parseGroupsFromResult(response.results[resultIndex], values.groupTypes)
+ const groups = parseGroupsFromResult(response.results[resultIndex], values.groupTypesForTest)
return createGlobalsFromResponse(
event,
@@ -405,7 +408,7 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([
],
},
],
- select: ['*', 'person', ...groupSelectColumns(values.groupTypes)],
+ select: ['*', 'person', ...groupSelectColumns(values.groupTypesForTest)],
after: timeRange,
limit: 1,
orderBy: ['timestamp DESC'],
@@ -439,7 +442,7 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([
const event = response.results[0][0]
const person = response.results[0][1]
- const groups = parseGroupsFromResult(response.results[0], values.groupTypes)
+ const groups = parseGroupsFromResult(response.results[0], values.groupTypesForTest)
actions.setSampleGlobalsError(null)
actions.setCanTryExtendedSearch(false)
@@ -466,6 +469,13 @@ export const hogFlowEditorTestLogic = kea<hogFlowEditorTestLogicType>([
return !!(triggerAction && triggerAction.config.type === 'event')
},
],
+ // 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).
+ groupTypesForTest: [
+ (s) => [s.groupsEnabled, s.groupTypes],
+ (groupsEnabled, groupTypes): Map<GroupTypeIndex, GroupType> => (groupsEnabled ? groupTypes : new Map()),
+ ],
// TODO(workflows): DRY up matchingFilters with implementation in hogFunctionConfigurationLogic
matchingFilters: [
(s) => [s.triggerAction],