: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(experiments): show the health panel to impersonating staff (#126763)
Marcel Poelker03cb9b808617
diff --git a/frontend/src/scenes/experiments/experimentLogic.test.ts b/frontend/src/scenes/experiments/experimentLogic.test.tsindex 77ca95c66f9f..2ae4241a316b 100644--- a/frontend/src/scenes/experiments/experimentLogic.test.ts+++ b/frontend/src/scenes/experiments/experimentLogic.test.ts@@ -2435,6 +2435,7 @@ describe('experimentLogic', () => {health?: ExperimentHealthApiexpected: ExperimentWarning | nullhealthFindingsFlag?: boolean+ impersonated?: boolean}>([{desc: 'running experiment with active flag and normal rollout',@@ -2614,8 +2615,17 @@ describe('experimentLogic', () => {healthFindingsFlag: false,expected: { key: 'running_but_flag_disabled' },},- ])('$desc → $expected', ({ overrides, health, expected, healthFindingsFlag = true }) => {+ {+ desc: 'server findings replace the local rules for staff impersonating a customer without the flag',+ overrides: { ...running, feature_flag: flag(false, multivariantFilters) },+ health: { findings: [], checks: [] },+ healthFindingsFlag: false,+ impersonated: true,+ expected: null,+ },+ ])('$desc → $expected', ({ overrides, health, expected, healthFindingsFlag = true, impersonated = false }) => {setHealthFindingsFlag(healthFindingsFlag)+ userLogic.actions.loadUserSuccess({ ...userLogic.values.user!, is_impersonated: impersonated })logic.actions.setExperiment(createExperiment(overrides))if (health) {logic.actions.loadExperimentHealthSuccess(health)diff --git a/frontend/src/scenes/experiments/experimentLogic.tsx b/frontend/src/scenes/experiments/experimentLogic.tsxindex e77aac5739de..f453219b9b24 100644--- a/frontend/src/scenes/experiments/experimentLogic.tsx+++ b/frontend/src/scenes/experiments/experimentLogic.tsx@@ -39,6 +39,7 @@ import { featureFlagsLogic } from 'scenes/feature-flags/featureFlagsLogic'import { projectLogic } from 'scenes/projectLogic'import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'+import { userLogic } from 'scenes/userLogic'import { refreshTreeItem } from '~/layout/panel-layout/ProjectTree/projectTreeLogic'import { cohortsModel } from '~/models/cohortsModel'@@ -67,6 +68,7 @@ import {ExperimentStatsMethod,FeatureFlagType,MultivariateFlagVariant,+ UserType,} from '~/types'import { EXPERIMENT_MIN_EXPOSURES_FOR_RESULTS, NEW_EXPERIMENT } from 'products/experiments/frontend/constants'@@ -349,6 +351,7 @@ export interface experimentLogicValues {currentProjectId: number | null // projectLogicsharedMetrics: SharedMetric[] // sharedMetricsLogiccurrentTeamId: number | null // teamLogic+ user: UserType | null // userLogicbrowserExperimentWarning: ExperimentWarning | nullbrowserNoMetricsWarning: booleancurrentRefresh: CurrentRefreshSnapshot | null@@ -394,6 +397,7 @@ export interface experimentLogicValues {shippedVariantKey: string | nullshowDebugPanel: booleanshownHealth: ExperimentHealthApi | null+ showsHealthFindings: booleanstatsMethod: ExperimentStatsMethodunfreezeExposureLoading: booleanunmodifiedExperiment: Experiment | null@@ -957,12 +961,13 @@ export interface experimentLogicMeta {isSingleVariantShipped: boolean,shippedVariantKey: string | null) => ExperimentWarning | null+ showsHealthFindings: (featureFlags: FeatureFlagsSet, user: UserType | null) => booleanshownHealth: (experimentHealth: ExperimentHealthApi | null,- featureFlags: FeatureFlagsSet+ showsHealthFindings: boolean) => ExperimentHealthApi | nullhealthPending: (- featureFlags: FeatureFlagsSet,+ showsHealthFindings: boolean,experimentHealth: ExperimentHealthApi | null,experimentHealthLoading: boolean) => boolean@@ -1023,6 +1028,8 @@ export const experimentLogic = kea<experimentLogicType>([['holdouts'],sharedMetricsLogic,['sharedMetrics'],+ userLogic,+ ['user'],],actions: [experimentsLogic,@@ -2843,27 +2850,31 @@ export const experimentLogic = kea<experimentLogicType>([return null},],+ showsHealthFindings: [+ (s) => [s.featureFlags, s.user],+ (featureFlags: FeatureFlagsSet, user: UserType | null): boolean =>+ // While impersonating, the flag evaluates on the customer, so the impersonation itself counts.+ !!featureFlags[FEATURE_FLAGS.EXPERIMENT_HEALTH_FINDINGS] || !!user?.is_impersonated,+ ],shownHealth: [- (s) => [s.experimentHealth, s.featureFlags],- (experimentHealth: ExperimentHealthApi | null, featureFlags: FeatureFlagsSet): ExperimentHealthApi | null =>+ (s) => [s.experimentHealth, s.showsHealthFindings],+ (experimentHealth: ExperimentHealthApi | null, showsHealthFindings: boolean): ExperimentHealthApi | null =>// Every reader loads the findings, so every load can compare them with the browser's rules. The- // page shows them only with the experiment-health-findings flag, and the browser's rules cover+ // page shows them only to the readers in `showsHealthFindings`, and the browser's rules cover// everyone else.- featureFlags[FEATURE_FLAGS.EXPERIMENT_HEALTH_FINDINGS] ? experimentHealth : null,+ showsHealthFindings ? experimentHealth : null,],healthPending: [- (s) => [s.featureFlags, s.experimentHealth, s.experimentHealthLoading],+ (s) => [s.showsHealthFindings, s.experimentHealth, s.experimentHealthLoading],(- featureFlags: FeatureFlagsSet,+ showsHealthFindings: boolean,experimentHealth: ExperimentHealthApi | null,experimentHealthLoading: boolean): boolean =>- // Until the first answer, a reader with the flag sees neither the browser's warnings nor the panel,- // so the page never shows a warning that the server then contradicts. A failed request ends the- // wait, and the browser's rules apply.- !!featureFlags[FEATURE_FLAGS.EXPERIMENT_HEALTH_FINDINGS] &&- experimentHealthLoading &&- experimentHealth === null,+ // Until the first answer, a reader who gets the findings sees neither the browser's warnings nor+ // the panel, so the page never shows a warning that the server then contradicts. A failed request+ // ends the wait, and the browser's rules apply.+ showsHealthFindings && experimentHealthLoading && experimentHealth === null,],healthUi: [(s) => [s.experiment, s.shownHealth, s.healthPending],diff --git a/frontend/src/scenes/experiments/experimentSceneLogic.test.ts b/frontend/src/scenes/experiments/experimentSceneLogic.test.tsindex 37c7afb8ea32..e0aa0134b378 100644--- a/frontend/src/scenes/experiments/experimentSceneLogic.test.ts+++ b/frontend/src/scenes/experiments/experimentSceneLogic.test.ts@@ -287,13 +287,13 @@ describe('experimentSceneLogic', () => {true,],[- 'staff impersonating',- { superpowersEnabled: false, isImpersonated: true, healthFindingsEnabled: true },+ 'staff impersonating a customer without the flag',+ { superpowersEnabled: false, isImpersonated: true, healthFindingsEnabled: false },true,],['staff without the flag',- { superpowersEnabled: true, isImpersonated: true, healthFindingsEnabled: false },+ { superpowersEnabled: true, isImpersonated: false, healthFindingsEnabled: false },false,],[diff --git a/frontend/src/scenes/experiments/experimentSceneLogic.tsx b/frontend/src/scenes/experiments/experimentSceneLogic.tsxindex 20c29e9d162c..567b2c995aa2 100644--- a/frontend/src/scenes/experiments/experimentSceneLogic.tsx+++ b/frontend/src/scenes/experiments/experimentSceneLogic.tsx@@ -91,8 +91,8 @@ export const getAvailableExperimentTabs = (})}-// Staff only. While impersonating, the user is the customer, so superpowers are off for the staff member at the-// keyboard and the impersonation itself counts.+// Staff only. While impersonating, the user is the customer: superpowers are off for the staff member at the keyboard+// and the flag evaluates on the customer, so the impersonation itself counts.export const canSeeHealthDebugTab = ({superpowersEnabled,isImpersonated,@@ -101,7 +101,7 @@ export const canSeeHealthDebugTab = ({superpowersEnabled: booleanisImpersonated: booleanhealthFindingsEnabled: boolean-}): boolean => (superpowersEnabled || isImpersonated) && healthFindingsEnabled+}): boolean => isImpersonated || (superpowersEnabled && healthFindingsEnabled)// kea-router coerces numeric-looking params to numbers, so check the type before membershipconst isExperimentTab = (tab: unknown): tab is ExperimentTab =>