: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
fix(onboarding): unlock quick start tasks with one completion rule (#87480)
posthog[bot]605d070c535b
diff --git a/frontend/src/lib/components/ProductSetup/productSetupLogic.test.ts b/frontend/src/lib/components/ProductSetup/productSetupLogic.test.tsnew file mode 100644index 000000000000..0658e533aae8--- /dev/null+++ b/frontend/src/lib/components/ProductSetup/productSetupLogic.test.ts@@ -0,0 +1,116 @@+import { expectLogic } from 'kea-test-utils'++import { SetupTaskId } from 'lib/components/ProductSetup'+import { teamLogic } from 'scenes/teamLogic'++import { ProductKey } from '~/queries/schema/schema-general'+import { initKeaTests } from '~/test/init'+import { ActivationTaskStatus, TeamType } from '~/types'++import { productSetupLogic } from './productSetupLogic'+import type { SetupTaskWithState } from './types'++describe('productSetupLogic', () => {+ let logic: ReturnType<typeof productSetupLogic.build>++ beforeEach(() => {+ localStorage.clear()+ initKeaTests()+ logic = productSetupLogic({ productKey: ProductKey.PRODUCT_ANALYTICS })+ logic.mount()+ })++ afterEach(() => {+ logic.unmount()+ })++ const task = (id: SetupTaskId): SetupTaskWithState =>+ logic.values.tasksWithState.find((t) => t.id === id) as SetupTaskWithState++ const setTeam = async (overrides: Partial<TeamType>): Promise<void> => {+ await expectLogic(logic, () =>+ teamLogic.actions.loadCurrentTeamSuccess({+ ...teamLogic.values.currentTeam!,+ onboarding_tasks: {},+ ...overrides,+ } as TeamType)+ ).toFinishAllListeners()+ }++ // The reported bug: the install page reads `ingested_event`, so the checklist must too.+ // Without auto-completion, `ingest_first_event` never completes and locks all seven dependents.+ it('auto-completes ingest_first_event from ingested_event and unlocks its dependents', async () => {+ await setTeam({ ingested_event: true, onboarding_tasks: {} })++ expect(task(SetupTaskId.IngestFirstEvent).completed).toBe(true)+ expect(task(SetupTaskId.CreateFirstInsight).lockedReason).toBeUndefined()+ })++ // Guards the default: no event and no saved status keeps the gate closed.+ it('locks a dependent while its dependency is unmet', async () => {+ await setTeam({ ingested_event: false, onboarding_tasks: {} })++ expect(task(SetupTaskId.IngestFirstEvent).completed).toBe(false)+ expect(task(SetupTaskId.CreateFirstInsight).lockedReason).toContain('Ingest your first event')+ })++ // A skipped dependency counts as satisfied — skipping used to leave dependents locked forever.+ it('treats a skipped dependency as satisfied', async () => {+ await setTeam({+ ingested_event: false,+ onboarding_tasks: { [SetupTaskId.IngestFirstEvent]: ActivationTaskStatus.SKIPPED },+ })++ expect(task(SetupTaskId.IngestFirstEvent).skipped).toBe(true)+ expect(task(SetupTaskId.CreateFirstInsight).lockedReason).toBeUndefined()+ })++ // A dependency completed the normal way (saved status) still unlocks dependents.+ it('unlocks a dependent when its dependency is saved as completed', async () => {+ await setTeam({+ ingested_event: false,+ onboarding_tasks: { [SetupTaskId.IngestFirstEvent]: ActivationTaskStatus.COMPLETED },+ })++ expect(task(SetupTaskId.CreateFirstInsight).lockedReason).toBeUndefined()+ })++ // A skipped task that later auto-completes must count once, not as both completed and skipped.+ it('does not double-count a skipped task that later auto-completes', async () => {+ await setTeam({+ ingested_event: true,+ onboarding_tasks: { [SetupTaskId.IngestFirstEvent]: ActivationTaskStatus.SKIPPED },+ })++ expect(task(SetupTaskId.IngestFirstEvent).completed).toBe(true)+ expect(task(SetupTaskId.IngestFirstEvent).skipped).toBe(false)+ expect(logic.values.completedCount).toBe(logic.values.completedTasks.length)+ })++ // AI observability's ViewFirstTrace/TrackCosts depend on ingest_first_event, which is not one of that+ // product's own tasks. The dependency must still gate and unlock them.+ it('resolves a dependency that lives outside the product task list', async () => {+ const aiLogic = productSetupLogic({ productKey: ProductKey.AI_OBSERVABILITY })+ aiLogic.mount()+ const aiTask = (id: SetupTaskId): SetupTaskWithState =>+ aiLogic.values.tasksWithState.find((t) => t.id === id) as SetupTaskWithState+ try {+ // Unmet: no event and no saved status keeps the dependents locked.+ await setTeam({ ingested_event: false, onboarding_tasks: {} })+ expect(aiTask(SetupTaskId.ViewFirstTrace).lockedReason).not.toBeUndefined()++ // A saved COMPLETED unlocks even though ingest_first_event is not in this product's list.+ await setTeam({+ ingested_event: false,+ onboarding_tasks: { [SetupTaskId.IngestFirstEvent]: ActivationTaskStatus.COMPLETED },+ })+ expect(aiTask(SetupTaskId.ViewFirstTrace).lockedReason).toBeUndefined()++ // The ingested_event auto-completion also reaches it.+ await setTeam({ ingested_event: true, onboarding_tasks: {} })+ expect(aiTask(SetupTaskId.TrackCosts).lockedReason).toBeUndefined()+ } finally {+ aiLogic.unmount()+ }+ })+})diff --git a/frontend/src/lib/components/ProductSetup/productSetupLogic.ts b/frontend/src/lib/components/ProductSetup/productSetupLogic.tsindex 7bbeee5f0d51..1412b928e57b 100644--- a/frontend/src/lib/components/ProductSetup/productSetupLogic.ts+++ b/frontend/src/lib/components/ProductSetup/productSetupLogic.ts@@ -117,7 +117,8 @@ export interface productSetupLogicMeta {tasksWithState: (allTasks: SetupTask[],savedOnboardingTasks: Record<string, ActivationTaskStatus | null>,- hasReverseProxy: boolean | null+ hasReverseProxy: boolean | null,+ currentTeam: TeamPublicType | TeamType | null) => SetupTaskWithState[]activeTasks: (tasksWithState: SetupTaskWithState[]) => SetupTaskWithState[]completedTasks: (tasksWithState: SetupTaskWithState[]) => SetupTaskWithState[]@@ -251,30 +252,41 @@ export const productSetupLogic = kea<productSetupLogicType>([}),],tasksWithState: [- (s) => [s.allTasks, s.savedOnboardingTasks, s.hasReverseProxy],+ (s) => [s.allTasks, s.savedOnboardingTasks, s.hasReverseProxy, s.currentTeam],(allTasks: import('lib/components/ProductSetup').SetupTask[],savedOnboardingTasks: Record<string, ActivationTaskStatus | null>,- hasReverseProxy: boolean | null+ hasReverseProxy: boolean | null,+ currentTeam: null | import('~/types').TeamPublicType | import('~/types').TeamType): SetupTaskWithState[] => {- return allTasks.map((task) => {- // Check for auto-completion conditions- let isAutoCompleted = false-- // Reverse proxy task auto-completes if proxy is detected- if (task.id === SetupTaskId.SetUpReverseProxy && hasReverseProxy) {- isAutoCompleted = true+ // A task auto-completes when a team flag already proves it is done, even without a saved status.+ const isAutoCompleted = (taskId: SetupTaskId): boolean => {+ if (taskId === SetupTaskId.SetUpReverseProxy && hasReverseProxy) {+ return true+ }+ // The install page reads `ingested_event`, so the checklist must trust the same flag.+ if (taskId === SetupTaskId.IngestFirstEvent && currentTeam?.ingested_event) {+ return true}+ return false+ }- const completed =- isAutoCompleted || savedOnboardingTasks[task.id] === ActivationTaskStatus.COMPLETED- const skipped = savedOnboardingTasks[task.id] === ActivationTaskStatus.SKIPPED+ // Resolve completion for any task id, including a dependency that this product's list does not+ // show, so the checkmark and the dependency gate read one completion rule.+ const isCompleted = (taskId: SetupTaskId): boolean =>+ isAutoCompleted(taskId) || savedOnboardingTasks[taskId] === ActivationTaskStatus.COMPLETED+ // Completion wins over a stale skip: a task the user skipped but later actually finished is+ // genuinely done, so it counts once instead of as both completed and skipped.+ const isSkipped = (taskId: SetupTaskId): boolean =>+ !isCompleted(taskId) && savedOnboardingTasks[taskId] === ActivationTaskStatus.SKIPPED- // Check dependencies+ return allTasks.map((task) => {+ // A dependency is satisfied when it is completed or skipped, even when the dependency is not+ // itself one of this product's tasks. This matches the checkmark rule.let lockedReason: string | undefinedif (task.dependsOn) {for (const depId of task.dependsOn) {- if (savedOnboardingTasks[depId] !== ActivationTaskStatus.COMPLETED) {+ if (!isCompleted(depId) && !isSkipped(depId)) {const depTask = allTasks.find((t) => t.id === depId)lockedReason = depTask? `Complete "${depTask.title}" first`@@ -286,8 +298,8 @@ export const productSetupLogic = kea<productSetupLogicType>([return {...task,- completed,- skipped,+ completed: isCompleted(task.id),+ skipped: isSkipped(task.id),lockedReason,}})