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(mcp): keep group property types in person-aggregated conditions (#118830)

Phil Haack1f298eeeab83
diff --git a/services/mcp/src/tools/featureFlags/preserveGroupTargeting.ts b/services/mcp/src/tools/featureFlags/preserveGroupTargeting.ts
index 2c7d6935efe7..82596dedbef0 100644
--- a/services/mcp/src/tools/featureFlags/preserveGroupTargeting.ts
+++ b/services/mcp/src/tools/featureFlags/preserveGroupTargeting.ts
@@ -20,16 +20,23 @@
* person-aggregated type that its source holds for the key. A group-aggregated set with no source
* looks the key up in every stored set instead when the stored sets all aggregate the same way, or
* when the set states or implies its own group type. It types every other untyped property as
- * `group` against the set's own group type index. A person-aggregated set restores every stored
- * type except `group`.
+ * `group` against the set's own group type index.
+ *
+ * A person-aggregated set can filter on a group property. The flag evaluator reads each property
+ * by its own type and group_type_index (see mixed_targeting_flag in
+ * rust/feature-flags/src/flags/test_flag_matching.rs). A person-aggregated set therefore restores
+ * `group` and the stored group_type_index from a source that is also stored as person-aggregated.
+ * From a group-aggregated source, or from another stored set, it restores only person-aggregated
+ * types. A group property in a group-aggregated set says nothing about a person set. An echo of a
+ * group property that a person-aggregated source holds does not move the set to group aggregation.
* check_property_types_match_aggregation in products/feature_flags/backend/filters_validation.py
- * reports a person-aggregated property in a group set. The flag evaluator reads each property by
- * its own type, so a group set keeps the stored type of a person-aggregated property it holds.
+ * reports a group property in a person set and a person-aggregated property in a group set. The
+ * evaluator supports both shapes. The merge keeps them where the stored flag already has them.
*
* `aggregation_group_type_index: null` means person aggregation. Only a missing key is
* filled from the existing flag.
*
- * A condition set pinned to person aggregation never gains group targeting. A set is
+ * A condition set pinned to person aggregation never gains group aggregation. A set is
* pinned when it clears its own aggregation, when the payload changes the flag level to null, or
* when it carries an explicit property of any type except `group` without setting a group index
* itself.
@@ -128,15 +135,36 @@ function indexProperties(properties: FlagProperty[] | null | undefined): Map<str
return byKey
}
-type ExistingSet = { group: FlagConditionGroup; propsByKey: Map<string, FlagProperty[]> }
+/** A set with no index of its own aggregates on the flag level, which the API distributes on write. */
+function storedAggregation(group: FlagConditionGroup, flagLevelGroupIndex: number | undefined): number | null {
+ return (
+ resolveGroupIndex(
+ explicitlyClearsAggregation(group),
+ group.aggregation_group_type_index,
+ flagLevelGroupIndex
+ ) ?? null
+ )
+}
+
+/** `aggregation` is null for a set that aggregates on persons. */
+type ExistingSet = { group: FlagConditionGroup; propsByKey: Map<string, FlagProperty[]>; aggregation: number | null }
-function indexExistingSets(existing: FlagFilters | null | undefined): (ExistingSet | undefined)[] {
+function indexExistingSets(
+ existing: FlagFilters | null | undefined,
+ flagLevelGroupIndex: number | undefined
+): (ExistingSet | undefined)[] {
const groups = existing?.groups
if (!Array.isArray(groups)) {
return []
}
return groups.map((group) =>
- isRecord(group) ? { group, propsByKey: indexProperties(group.properties) } : undefined
+ isRecord(group)
+ ? {
+ group,
+ propsByKey: indexProperties(group.properties),
+ aggregation: storedAggregation(group, flagLevelGroupIndex),
+ }
+ : undefined
)
}
@@ -152,20 +180,17 @@ function hasSameKeySet(incoming: ReadonlyMap<string, unknown>, existing: Readonl
return incoming.size === existing.size && [...incoming.keys()].every((key) => existing.has(key))
}
-/** A set with no index of its own aggregates on the flag level, which the API distributes on write. */
-function storedAggregation(group: FlagConditionGroup, flagLevelGroupIndex: number | undefined): number | null {
+/** The flag evaluator reads a missing operator as `exact`. */
+function matchesFilter(stored: FlagProperty, incoming: FlagProperty): boolean {
return (
- resolveGroupIndex(
- explicitlyClearsAggregation(group),
- group.aggregation_group_type_index,
- flagLevelGroupIndex
- ) ?? null
+ (stored.operator ?? 'exact') === (incoming.operator ?? 'exact') &&
+ isDeepStrictEqual(stored.value, incoming.value)
)
}
/**
* The filters under each key compare as a multiset of operator and value pairs, so a removed, added,
- * or changed filter on a key is a change. The flag evaluator reads a missing operator as `exact`.
+ * or changed filter on a key is a change.
*/
function keepsFilters(incoming: FlagConditionGroup, source: ExistingSet): boolean {
return [...indexProperties(incoming.properties)].every(([key, props]) => {
@@ -173,11 +198,7 @@ function keepsFilters(incoming: FlagConditionGroup, source: ExistingSet): boolea
return (
props.length === unmatched.length &&
props.every((prop) => {
- const match = unmatched.findIndex(
- (stored) =>
- (stored.operator ?? 'exact') === (prop.operator ?? 'exact') &&
- isDeepStrictEqual(stored.value, prop.value)
- )
+ const match = unmatched.findIndex((stored) => matchesFilter(stored, prop))
if (match === -1) {
return false
}
@@ -206,25 +227,26 @@ function resolveGroupIndex(
return isPresentGroupIndex(explicitIndex) ? explicitIndex : fallbackIndex
}
-function pickPersonAggregatedCandidate(
+function pickCandidate(
candidates: FlagProperty[] | undefined,
- incoming: FlagProperty
+ incoming: FlagProperty,
+ usableType: (type: unknown) => boolean
): FlagProperty | undefined {
- const usable = (candidates ?? []).filter((candidate) => isPersonAggregatedType(candidate.type))
- if (incoming.operator) {
- const byOperator = usable.find((candidate) => candidate.operator === incoming.operator)
- if (byOperator) {
- return byOperator
- }
- }
- return usable[0]
+ const usable = (candidates ?? []).filter((candidate) => usableType(candidate.type))
+ // Two group filters on one key can share an operator and differ only in group type and value.
+ return (
+ usable.find((candidate) => matchesFilter(candidate, incoming)) ??
+ (incoming.operator ? usable.find((candidate) => candidate.operator === incoming.operator) : undefined) ??
+ usable[0]
+ )
}
function mergeProperty(
incoming: FlagProperty,
candidates: FlagProperty[] | undefined,
otherCandidates: FlagProperty[] | undefined,
- setGroupTypeIndex: number | undefined
+ setGroupTypeIndex: number | undefined,
+ sourceAggregatesOnPersons: boolean
): FlagProperty {
const out: FlagProperty = { ...incoming }
@@ -233,16 +255,20 @@ function mergeProperty(
// Candidates that also hold the key as a group property leave the type ambiguous.
out.type = candidates?.some((candidate) => candidate.type === 'group')
? 'group'
- : (pickPersonAggregatedCandidate(candidates, out)?.type ?? 'group')
+ : (pickCandidate(candidates, out, isPersonAggregatedType)?.type ?? 'group')
} else {
- // Leaving the type unset makes the API report the property the agent actually
- // sent. Restoring `group` here would name fields the agent never sent.
- // A source set can lack the key, or hold it only as a group property that a person
- // set cannot use. The type then comes from another set that holds the key.
+ // A person-aggregated source restores the group property it filters on, index
+ // included. Any other candidate restores only a person-aggregated type, because
+ // restoring `group` from it would name fields the agent never sent. Leaving the type
+ // unset then makes the API report the property the agent actually sent.
const restored =
- pickPersonAggregatedCandidate(candidates, out) ?? pickPersonAggregatedCandidate(otherCandidates, out)
+ pickCandidate(candidates, out, sourceAggregatesOnPersons ? isPresentType : isPersonAggregatedType) ??
+ pickCandidate(otherCandidates, out, isPersonAggregatedType)
if (restored) {
out.type = restored.type
+ if (restored.type === 'group' && !isPresentGroupIndex(out.group_type_index)) {
+ out.group_type_index = restored.group_type_index
+ }
}
}
}
@@ -259,16 +285,32 @@ function mergeProperty(
type MergeConditionOptions = {
/** The payload changes the flag-level aggregation, which decides every set that sends none. */
payloadChangesFlagAggregation: boolean
- /** This set never gains group targeting. See isPinnedToPerson. */
+ /** This set never gains group aggregation. See isPinnedToPerson. */
pinnedToPerson: boolean
}
-function explicitGroupPropertyIndex(group: FlagConditionGroup): number | undefined {
+function holdsGroupProperty(existingSet: ExistingSet | undefined, prop: FlagProperty): boolean {
+ return (
+ typeof prop.key === 'string' &&
+ !!existingSet?.propsByKey
+ .get(prop.key)
+ ?.some((stored) => stored.type === 'group' && stored.group_type_index === prop.group_type_index)
+ )
+}
+
+function explicitGroupPropertyIndex(
+ group: FlagConditionGroup,
+ personSource: ExistingSet | undefined
+): number | undefined {
const properties = Array.isArray(group.properties) ? group.properties : []
- const indexes = properties.flatMap((prop) =>
- prop?.type === 'group' && isPresentGroupIndex(prop.group_type_index) ? [prop.group_type_index] : []
+ const typed = properties.filter(
+ (prop): prop is FlagProperty & { group_type_index: number } =>
+ prop?.type === 'group' && isPresentGroupIndex(prop.group_type_index)
)
- const unique = [...new Set(indexes)]
+ if (typed.every((prop) => holdsGroupProperty(personSource, prop))) {
+ return undefined
+ }
+ const unique = [...new Set(typed.map((prop) => prop.group_type_index))]
return unique.length === 1 ? unique[0] : undefined
}
@@ -292,9 +334,13 @@ function resolveSetAggregation(
// that changes the flag level already decides this set, the same way the API distributes
// the flag level into every set that sends no index of its own. A group property that the
// agent typed with an index names the group type of its own set. A retarget that the agent
- // sends only on the property therefore survives.
+ // sends only on the property therefore survives. A set whose typed group properties all
+ // repeat ones its person-aggregated source holds names no group type, because that set
+ // filters on them without aggregating on their group type.
if (!pinnedToPerson && !payloadChangesFlagAggregation && !hasKey(out, 'aggregation_group_type_index')) {
- const restored = explicitGroupPropertyIndex(incoming) ?? sourceSet?.group.aggregation_group_type_index
+ const restored =
+ explicitGroupPropertyIndex(incoming, sourceSet?.aggregation === null ? sourceSet : undefined) ??
+ sourceSet?.group.aggregation_group_type_index
if (isPresentGroupIndex(restored)) {
out.aggregation_group_type_index = restored
}
@@ -307,7 +353,8 @@ function typeSetProperties(
group: FlagConditionGroup,
typeCandidatesByKey: Map<string, FlagProperty[]> | undefined,
crossSetPropsByKey: Map<string, FlagProperty[]>,
- setGroupTypeIndex: number | undefined
+ setGroupTypeIndex: number | undefined,
+ sourceAggregatesOnPersons: boolean
): FlagConditionGroup {
const out: FlagConditionGroup = { ...group }
if (Array.isArray(out.properties)) {
@@ -322,7 +369,8 @@ function typeSetProperties(
prop,
typeCandidatesByKey?.get(prop.key),
crossSetPropsByKey.get(prop.key),
- setGroupTypeIndex
+ setGroupTypeIndex,
+ sourceAggregatesOnPersons
)
})
}
@@ -384,14 +432,12 @@ export function preserveGroupTargetingFilters(
)
if (Array.isArray(result.groups)) {
- const existingSets = indexExistingSets(existing)
+ const existingSets = indexExistingSets(existing, existingFlagGroupIndex)
const crossSetPropsByKey = indexPropertiesAcrossSets(existingSets)
const pinnedToPerson = result.groups.map(
(group) => isRecord(group) && isPinnedToPerson(group, incomingClearsAggregation)
)
- const aggregations = existingSets.map((existingSet) =>
- existingSet ? storedAggregation(existingSet.group, existingFlagGroupIndex) : undefined
- )
+ const aggregations = existingSets.map((existingSet) => existingSet?.aggregation)
const mixedAggregation = new Set(aggregations.filter((aggregation) => aggregation !== undefined)).size > 1
const incomingGroups = result.groups
const sharesKeysAcrossAggregations = (existingSet: ExistingSet, index: number): boolean =>
@@ -455,7 +501,8 @@ export function preserveGroupTargetingFilters(
pinnedToPerson[index] ?? false,
group.aggregation_group_type_index,
effectiveFlagGroupIndex
- )
+ ),
+ sourceSets[index]?.aggregation === null
)
})
}
diff --git a/services/mcp/tests/unit/preserve-group-targeting.test.ts b/services/mcp/tests/unit/preserve-group-targeting.test.ts
index dc182d9c0641..3b91596df096 100644
--- a/services/mcp/tests/unit/preserve-group-targeting.test.ts
+++ b/services/mcp/tests/unit/preserve-group-targeting.test.ts
@@ -1,16 +1,48 @@
import { describe, expect, it } from 'vitest'
import { ToolInputValidationError } from '@/lib/errors'
-import { type FlagFilters, preserveGroupTargetingFilters } from '@/tools/featureFlags/preserveGroupTargeting'
+import {
+ type FlagConditionGroup,
+ type FlagFilters,
+ type FlagProperty,
+ preserveGroupTargetingFilters,
+} from '@/tools/featureFlags/preserveGroupTargeting'
const PERSON_AGGREGATED_PROPERTY_TYPES = ['person', 'cohort', 'flag']
+function setAggregation(group: FlagConditionGroup, flagLevel: number | null | undefined): number | null | undefined {
+ return 'aggregation_group_type_index' in group ? group.aggregation_group_type_index : flagLevel
+}
+
+function isGroupPropertyOfStoredPersonSet(existing: FlagFilters, groupIndex: number, property: FlagProperty): boolean {
+ const stored = existing.groups?.[groupIndex]
+ if (!stored) {
+ return false
+ }
+ const storedAggregation = setAggregation(stored, existing.aggregation_group_type_index)
+ return (
+ (storedAggregation === undefined || storedAggregation === null) &&
+ property.type === 'group' &&
+ !!stored.properties?.some(
+ (candidate) =>
+ candidate.key === property.key &&
+ candidate.type === 'group' &&
+ candidate.group_type_index === property.group_type_index
+ )
+ )
+}
+
/**
* Mirrors check_property_types_match_aggregation in
* products/feature_flags/backend/filters_validation.py, over the state that validator sees:
* the flag level the backend keeps when the payload omits it, then each set's own key. This helper
* skips a property with no type, which the backend rule reports. A test asserts the fields of a
* property left untyped instead.
+ *
+ * The backend rule also reports a group property in a person-aggregated set. The flag evaluator
+ * supports that shape. This helper accepts it only where the stored set at the same index already
+ * held it: that set aggregates on persons and holds the key as a group property on the same group
+ * type. A group property that the merge adds to a person-aggregated set still counts as a violation.
*/
function aggregationViolations(existing: FlagFilters, merged: FlagFilters | null | undefined): string[] {
const violations: string[] = []
@@ -19,14 +51,17 @@ function aggregationViolations(existing: FlagFilters, merged: FlagFilters | null
? merged.aggregation_group_type_index
: existing.aggregation_group_type_index
for (const [groupIndex, group] of (merged?.groups ?? []).entries()) {
- const aggregation = 'aggregation_group_type_index' in group ? group.aggregation_group_type_index : flagLevel
+ const aggregation = setAggregation(group, flagLevel)
for (const [propertyIndex, property] of (group.properties ?? []).entries()) {
const path = `groups[${groupIndex}].properties[${propertyIndex}]`
if (typeof property.type !== 'string') {
continue
}
if (aggregation === undefined || aggregation === null) {
- if (!PERSON_AGGREGATED_PROPERTY_TYPES.includes(property.type)) {
+ if (
+ !PERSON_AGGREGATED_PROPERTY_TYPES.includes(property.type) &&
+ !isGroupPropertyOfStoredPersonSet(existing, groupIndex, property)
+ ) {
violations.push(`${path}: person_aggregation_property_type`)
}
} else if (property.type !== 'group') {
@@ -190,8 +225,8 @@ describe('preserveGroupTargetingFilters', () => {
expect(merged?.groups?.[0]?.aggregation_group_type_index).toBeNull()
})
- // A person-aggregated set cannot hold a group property. A key that matches an existing
- // group property must not resurrect one, or the API error names a field the agent never sent.
+ // The agent moves a set that aggregates on group type 0 to persons. The stored group property
+ // filtered on that group type. A key that matches it must not resurrect it.
it.each([
{ name: 'a key with no existing match', key: 'email', operator: 'icontains', value: '@acme.com' },
{ name: 'a key matching an existing group property', key: 'plan', operator: 'exact', value: 'pro' },
@@ -470,38 +505,63 @@ describe('preserveGroupTargetingFilters', () => {
expect(merged?.groups?.[0]?.properties?.[0]?.value).toBe('.*')
})
+ const personAndCohortCandidates = [
+ { key: 'name', type: 'person', operator: 'icontains', value: 'acme' },
+ { key: 'name', type: 'cohort', operator: 'in', value: 42 },
+ ]
+ const groupAndPersonCandidates = [
+ { key: 'name', type: 'group', group_type_index: 0, operator: 'icontains', value: 'acme' },
+ { key: 'name', type: 'person', operator: 'exact', value: 'acme' },
+ ]
+
// The set aggregates on person, so the candidates decide the type. The operator picks
- // between two candidates that share a key. Without an operator match, the first one wins.
+ // between two candidates that share a key, and the value picks between those. Without a
+ // match, the first one wins.
it.each([
- { name: 'the operator matches the cohort candidate', operator: 'in', expectedType: 'cohort' },
- { name: 'the operator matches the person candidate', operator: 'icontains', expectedType: 'person' },
- { name: 'the operator matches neither candidate', operator: 'regex', expectedType: 'person' },
- ])('picks a duplicate-key candidate by operator when $name', ({ operator, expectedType }) => {
- const existing = {
- groups: [
- {
- properties: [
- { key: 'name', type: 'person', operator: 'icontains', value: 'acme' },
- { key: 'name', type: 'cohort', operator: 'in', value: 42 },
- ],
- rollout_percentage: 100,
- },
- ],
- }
- const incoming = {
- groups: [
- {
- properties: [{ key: 'name', operator, value: 'acme' }],
- rollout_percentage: 100,
- },
+ { name: 'the operator matches the cohort candidate', operator: 'in', expected: { type: 'cohort' } },
+ { name: 'the operator matches the person candidate', operator: 'icontains', expected: { type: 'person' } },
+ { name: 'the operator matches neither candidate', operator: 'regex', expected: { type: 'person' } },
+ {
+ name: 'the operator matches a group candidate',
+ stored: groupAndPersonCandidates,
+ operator: 'icontains',
+ expected: { type: 'group', group_type_index: 0 },
+ },
+ {
+ name: 'the operator matches a person candidate next to a group candidate',
+ stored: groupAndPersonCandidates,
+ operator: 'exact',
+ expected: { type: 'person' },
+ },
+ {
+ name: 'the value matches one of two group candidates with the same operator',
+ stored: [
+ { key: 'name', type: 'group', group_type_index: 0, operator: 'exact', value: 'acme' },
+ { key: 'name', type: 'group', group_type_index: 1, operator: 'exact', value: 'globex' },
],
- }
+ operator: 'exact',
+ value: 'globex',
+ expected: { type: 'group', group_type_index: 1 },
+ },
+ ])(
+ 'picks a duplicate-key candidate by operator and value when $name',
+ ({ stored = personAndCohortCandidates, operator, value = 'acme', expected }) => {
+ const existing = { groups: [{ properties: stored, rollout_percentage: 100 }] }
+ const incoming = {
+ groups: [
+ {
+ properties: [{ key: 'name', operator, value }],
+ rollout_percentage: 100,
+ },
+ ],
+ }
- const merged = preserveGroupTargetingFilters(existing, incoming)
+ const merged = preserveGroupTargetingFilters(existing, incoming)
- expect(merged?.groups?.[0]?.properties?.[0]?.type).toBe(expectedType)
- expect(aggregationViolations(existing, merged)).toEqual([])
- })
+ expect(merged?.groups?.[0]?.properties?.[0]).toEqual({ key: 'name', operator, value, ...expected })
+ expect(aggregationViolations(existing, merged)).toEqual([])
+ }
+ )
it('does not copy set-level aggregation onto a newly appended condition set', () => {
const existing = {
@@ -550,38 +610,85 @@ describe('preserveGroupTargetingFilters', () => {
expect(merged?.groups?.[1]?.properties?.[0]?.type).toBe('person')
})
- // The existing flag holds a group property with no aggregation index anywhere, which the
- // backend validator reports. Restoring the type would carry that contradiction into the new payload.
- it('does not restore a group property type into a set with no group aggregation', () => {
+ // The flag evaluator reads each property by its own type and group_type_index. A
+ // person-aggregated set can therefore filter on a group property. No set or flag level in this
+ // flag carries a group index. The restored index can only come from the stored property.
+ it.each([
+ { name: 'the set omits its aggregation' },
+ { name: 'the payload sends a null flag level', flag: { aggregation_group_type_index: null } },
+ { name: 'the set carries an explicit person property', email: { type: 'person' } },
+ {
+ name: 'the agent echoes the property with its group type and index',
+ region: { type: 'group', group_type_index: 1 },
+ },
+ ])(
+ 'keeps a stored group property in a person-aggregated set when $name',
+ ({ flag = {}, email = {}, region = {} }) => {
+ const existing = {
+ groups: [
+ {
+ properties: [
+ { key: 'email', type: 'person', operator: 'icontains', value: '@acme.com' },
+ { key: 'region', type: 'group', group_type_index: 1, operator: 'exact', value: 'us' },
+ ],
+ rollout_percentage: 100,
+ },
+ ],
+ }
+
+ const merged = preserveGroupTargetingFilters(existing, {
+ ...flag,
+ groups: [
+ {
+ properties: [
+ { key: 'email', operator: 'icontains', value: '@acme.com', ...email },
+ { key: 'region', operator: 'exact', value: 'eu', ...region },
+ ],
+ rollout_percentage: 100,
+ },
+ ],
+ })
+
+ expect(merged?.groups?.[0]?.properties?.[1]).toEqual({
+ key: 'region',
+ type: 'group',
+ group_type_index: 1,
+ operator: 'exact',
+ value: 'eu',
+ })
+ expect(merged?.groups?.[0]?.aggregation_group_type_index ?? null).toBeNull()
+ expect(aggregationViolations(existing, merged)).toEqual([])
+ }
+ )
+
+ // The backend rule reports this payload. This test therefore skips the oracle that copies the rule.
+ it('keeps a person-aggregated set when an echoed group property disagrees with a moved one', () => {
const existing = {
groups: [
{
properties: [
- {
- key: 'region',
- type: 'group',
- group_type_index: 1,
- operator: 'exact',
- value: 'us',
- },
+ { key: 'region', type: 'group', group_type_index: 1, operator: 'exact', value: 'us' },
+ { key: 'plan', type: 'group', group_type_index: 1, operator: 'exact', value: 'pro' },
],
rollout_percentage: 100,
},
],
}
- const incoming = {
+
+ const merged = preserveGroupTargetingFilters(existing, {
groups: [
{
- properties: [{ key: 'region', operator: 'exact', value: 'eu' }],
+ properties: [
+ { key: 'region', type: 'group', group_type_index: 1, operator: 'exact', value: 'us' },
+ { key: 'plan', type: 'group', group_type_index: 0, operator: 'exact', value: 'pro' },
+ ],
rollout_percentage: 100,
},
],
- }
-
- const merged = preserveGroupTargetingFilters(existing, incoming)
+ })
- expect(merged?.groups?.[0]?.properties?.[0]?.type).toBeUndefined()
- expect(merged?.groups?.[0]?.properties?.[0]?.group_type_index).toBeUndefined()
+ expect(merged?.groups?.[0]?.aggregation_group_type_index ?? null).toBeNull()
+ expect(merged?.groups?.[0]?.properties?.map((prop) => prop.group_type_index)).toEqual([1, 0])
})
it('passes through multivariate and payloads without restoring from existing', () => {
@@ -1010,6 +1117,117 @@ describe('preserveGroupTargetingFilters', () => {
[undefined, 'group', 1],
],
},
+ // The tool tells agents to echo a null aggregation on the person sets of a mixed flag.
+ {
+ name: 'a person set echoes its null aggregation and filters on a group property',
+ existing: {
+ aggregation_group_type_index: null,
+ groups: [
+ {
+ aggregation_group_type_index: 0,
+ properties: [
+ { key: 'plan', type: 'group', group_type_index: 0, operator: 'exact', value: 'enterprise' },
+ ],
+ rollout_percentage: 100,
+ },
+ {
+ aggregation_group_type_index: null,
+ properties: [
+ { key: 'region', type: 'group', group_type_index: 1, operator: 'exact', value: 'us' },
+ ],
+ rollout_percentage: 100,
+ },
+ ],
+ },
+ incoming: {
+ aggregation_group_type_index: null,
+ groups: [
+ {
+ aggregation_group_type_index: 0,
+ properties: [{ key: 'plan', operator: 'exact', value: 'pro' }],
+ rollout_percentage: 100,
+ },
+ {
+ aggregation_group_type_index: null,
+ properties: [{ key: 'region', operator: 'exact', value: 'eu' }],
+ rollout_percentage: 100,
+ },
+ ],
+ },
+ expected: [
+ [0, 'group', 0],
+ [null, 'group', 1],
+ ],
+ },
+ // An appended set has no source, so the group property of another set must not type it.
+ {
+ name: 'a set is appended next to a person set that filters on a group property',
+ existing: {
+ aggregation_group_type_index: null,
+ groups: [
+ {
+ aggregation_group_type_index: null,
+ properties: [
+ { key: 'plan', type: 'group', group_type_index: 0, operator: 'exact', value: 'enterprise' },
+ ],
+ rollout_percentage: 100,
+ },
+ ],
+ },
+ incoming: {
+ groups: [
+ { properties: [{ key: 'plan', operator: 'exact', value: 'pro' }], rollout_percentage: 100 },
+ { properties: [{ key: 'plan', operator: 'exact', value: 'free' }], rollout_percentage: 100 },
+ ],
+ },
+ expected: [
+ [undefined, 'group', 0],
+ [undefined, undefined, undefined],
+ ],
+ },
+ {
+ name: 'a person set moves its group property to another group type',
+ existing: {
+ groups: [
+ {
+ properties: [
+ { key: 'region', type: 'group', group_type_index: 1, operator: 'exact', value: 'us' },
+ ],
+ rollout_percentage: 100,
+ },
+ ],
+ },
+ incoming: {
+ groups: [
+ {
+ properties: [
+ { key: 'region', type: 'group', group_type_index: 2, operator: 'exact', value: 'eu' },
+ ],
+ rollout_percentage: 100,
+ },
+ ],
+ },
+ expected: [[2, 'group', 2]],
+ },
+ {
+ name: 'a stored set that inherits a group flag level moves to persons',
+ existing: {
+ aggregation_group_type_index: 0,
+ groups: [
+ {
+ properties: [
+ { key: 'plan', type: 'group', group_type_index: 0, operator: 'exact', value: 'enterprise' },
+ ],
+ rollout_percentage: 100,
+ },
+ ],
+ },
+ incoming: {
+ aggregation_group_type_index: null,
+ groups: [{ properties: [{ key: 'plan', operator: 'exact', value: 'pro' }], rollout_percentage: 100 }],
+ },
+ expected: [[undefined, undefined, undefined]],
+ },
])('keeps each condition set on its own aggregation when $name', ({ existing, incoming, expected }) => {
const merged = preserveGroupTargetingFilters(existing, incoming)