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.

chore(flags): guard mcp group-targeting merge against type drift (#98620)

Phil Haack8b5db2e2eeda
diff --git a/products/feature_flags/backend/test/test_filters_validation.py b/products/feature_flags/backend/test/test_filters_validation.py
index f54aaf3cbf64..6539b26bd551 100644
--- a/products/feature_flags/backend/test/test_filters_validation.py
+++ b/products/feature_flags/backend/test/test_filters_validation.py
@@ -7,10 +7,11 @@ from rest_framework import serializers
from rest_framework.exceptions import ErrorDetail
from products.feature_flags.backend.api.feature_flag import _reject_serde_unsafe_filters
-from products.feature_flags.backend.api.filters_schema import FeatureFlagFiltersSerializer
+from products.feature_flags.backend.api.filters_schema import FEATURE_FLAG_PROPERTY_TYPES, FeatureFlagFiltersSerializer
from products.feature_flags.backend.encrypted_flag_payloads import REDACTED_PAYLOAD_VALUE
from products.feature_flags.backend.filters_validation import (
CROSS_FIELD_CHECKS,
+ PERSON_AGGREGATED_PROPERTY_TYPES,
Violation,
check_groups_non_empty_for_create,
check_variant_rollout_sum,
@@ -324,6 +325,20 @@ class TestFiltersValidation(SimpleTestCase):
]
assert check_groups_non_empty_for_create({"groups": [{"properties": []}]}) == []
+ def test_group_is_the_only_property_type_outside_person_aggregation(self) -> None:
+ assert set(FEATURE_FLAG_PROPERTY_TYPES) - set(PERSON_AGGREGATED_PROPERTY_TYPES) == {"group"}, (
+ "services/mcp/src/tools/featureFlags/preserveGroupTargeting.ts encodes the person-aggregation rule as "
+ "`type !== 'group'` (in mergeConditionGroup and mergeProperty). That is the complement of "
+ "PERSON_AGGREGATED_PROPERTY_TYPES only while 'group' is the sole type outside it. A group-side type "
+ "that slips through as person-aggregated lets that merge helper silently clear a flag's group "
+ "targeting. If the new type belongs under person aggregation, add it to "
+ "PERSON_AGGREGATED_PROPERTY_TYPES and the TypeScript needs no change. If the difference came out "
+ "empty instead, 'group' was added to PERSON_AGGREGATED_PROPERTY_TYPES, and the merge helper's "
+ "`!== 'group'` check no longer separates the two aggregations at all; that change needs its own "
+ "review, not a wider tuple here. Otherwise update the merge helper and "
+ "services/mcp/tests/unit/preserve-group-targeting.test.ts, then this assertion."
+ )
+
class TestRejectSerdeUnsafeFilters(SimpleTestCase):
# The only cache-poisoning guard that runs while the enforcement switch is off, and the