Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend): gate onboarding SubscriptionStep behind ENABLE_PLATFORM_PAYMENT (#12943)

Ubbec6d31f8252be
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/page.test.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/page.test.tsx
new file mode 100644
index 0000000000..1f46b967d4
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/page.test.tsx
@@ -0,0 +1,131 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { cleanup, render, screen } from "@/tests/integrations/test-utils";
+import OnboardingPage from "../page";
+import { useOnboardingWizardStore } from "../store";
+
+vi.mock("../steps/WelcomeStep", () => ({
+ WelcomeStep: () => <div data-testid="step-welcome" />,
+}));
+vi.mock("../steps/RoleStep", () => ({
+ RoleStep: () => <div data-testid="step-role" />,
+}));
+vi.mock("../steps/PainPointsStep", () => ({
+ PainPointsStep: () => <div data-testid="step-painpoints" />,
+}));
+vi.mock("../steps/SubscriptionStep/SubscriptionStep", () => ({
+ SubscriptionStep: () => <div data-testid="step-subscription" />,
+}));
+vi.mock("../steps/PreparingStep", () => ({
+ PreparingStep: ({ onComplete: _onComplete }: { onComplete: () => void }) => (
+ <div data-testid="step-preparing" />
+ ),
+}));
+
+let currentSearchParams = new URLSearchParams();
+const routerReplace = vi.fn();
+vi.mock("next/navigation", () => ({
+ useRouter: () => ({
+ replace: routerReplace,
+ push: vi.fn(),
+ refresh: vi.fn(),
+ }),
+ useSearchParams: () => currentSearchParams,
+ usePathname: () => "/onboarding",
+}));
+
+vi.mock("@/lib/supabase/hooks/useSupabase", () => ({
+ useSupabase: () => ({ isLoggedIn: true, isUserLoading: false, user: null }),
+}));
+
+vi.mock("@/app/api/__generated__/endpoints/onboarding/onboarding", () => ({
+ getV1OnboardingState: () =>
+ Promise.resolve({ status: 200, data: { completedSteps: [] } }),
+ getV1CheckIfOnboardingIsCompleted: () =>
+ Promise.resolve({ status: 200, data: false }),
+ patchV1UpdateOnboardingState: () => Promise.resolve({ status: 200 }),
+ postV1CompleteOnboardingStep: () => Promise.resolve({ status: 200 }),
+ postV1SubmitOnboardingProfile: () => Promise.resolve({ status: 200 }),
+}));
+
+vi.mock("@/app/api/helpers", () => ({
+ resolveResponse: (p: Promise<{ data: unknown }>) => p.then((r) => r.data),
+}));
+
+let mockFlagValue = false;
+vi.mock("@/services/feature-flags/use-get-flag", () => ({
+ Flag: { ENABLE_PLATFORM_PAYMENT: "ENABLE_PLATFORM_PAYMENT" },
+ useGetFlag: () => mockFlagValue,
+}));
+
+vi.mock("launchdarkly-react-client-sdk", () => ({
+ useLDClient: () => ({
+ waitForInitialization: () => Promise.resolve(),
+ }),
+}));
+
+beforeEach(() => {
+ currentSearchParams = new URLSearchParams();
+ mockFlagValue = false;
+ routerReplace.mockClear();
+ useOnboardingWizardStore.getState().reset();
+});
+
+afterEach(() => {
+ cleanup();
+});
+
+describe("OnboardingPage — flag-gated SubscriptionStep", () => {
+ it("renders Welcome at step 1 by default in flag-off mode", async () => {
+ mockFlagValue = false;
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-welcome")).toBeDefined();
+ expect(screen.queryByTestId("step-subscription")).toBeNull();
+ });
+
+ it("clamps ?step=5 to step 1 when payments are gated off", async () => {
+ mockFlagValue = false;
+ currentSearchParams = new URLSearchParams("step=5");
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-welcome")).toBeDefined();
+ expect(screen.queryByTestId("step-preparing")).toBeNull();
+ });
+
+ it("treats step 4 as Preparing when payments are gated off", async () => {
+ mockFlagValue = false;
+ currentSearchParams = new URLSearchParams("step=4");
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-preparing")).toBeDefined();
+ expect(screen.queryByTestId("step-subscription")).toBeNull();
+ });
+
+ it("renders SubscriptionStep at step 4 when payments are enabled", async () => {
+ mockFlagValue = true;
+ currentSearchParams = new URLSearchParams("step=4");
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-subscription")).toBeDefined();
+ expect(screen.queryByTestId("step-preparing")).toBeNull();
+ });
+
+ it("treats step 5 as Preparing when payments are enabled", async () => {
+ mockFlagValue = true;
+ currentSearchParams = new URLSearchParams("step=5");
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-preparing")).toBeDefined();
+ expect(screen.queryByTestId("step-subscription")).toBeNull();
+ });
+
+ it("rejects decimal step values and falls back to step 1", async () => {
+ mockFlagValue = true;
+ currentSearchParams = new URLSearchParams("step=2.5");
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-welcome")).toBeDefined();
+ expect(screen.queryByTestId("step-role")).toBeNull();
+ });
+
+ it("rejects non-numeric step values and falls back to step 1", async () => {
+ mockFlagValue = true;
+ currentSearchParams = new URLSearchParams("step=foo");
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-welcome")).toBeDefined();
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/page.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/page.tsx
index d13f2ca2be..6509470f8f 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/page.tsx
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/page.tsx
@@ -12,15 +12,20 @@ import { useOnboardingWizardStore } from "./store";
import { useOnboardingPage } from "./useOnboardingPage";
export default function OnboardingPage() {
- const { currentStep, isLoading, handlePreparingComplete } =
- useOnboardingPage();
+ const {
+ currentStep,
+ isLoading,
+ handlePreparingComplete,
+ isPaymentEnabled,
+ preparingStep,
+ totalSteps,
+ } = useOnboardingPage();
const prevStep = useOnboardingWizardStore((s) => s.prevStep);
if (isLoading) return null;
- // ProgressBar + StepIndicator track only the user-interactive steps (1-4).
- // Step 5 (PreparingStep) is a transition view that hides both indicators.
- const totalSteps = 4;
+ // ProgressBar + StepIndicator track only the user-interactive steps.
+ // PreparingStep is a transition view that hides both indicators.
const showDots = currentStep <= totalSteps;
const showBack = currentStep > 1 && currentStep <= totalSteps;
const showProgressBar = currentStep <= totalSteps;
@@ -46,8 +51,8 @@ export default function OnboardingPage() {
{currentStep === 1 && <WelcomeStep />}
{currentStep === 2 && <RoleStep />}
{currentStep === 3 && <PainPointsStep />}
- {currentStep === 4 && <SubscriptionStep />}
- {currentStep === 5 && (
+ {isPaymentEnabled && currentStep === 4 && <SubscriptionStep />}
+ {currentStep === preparingStep && (
<PreparingStep onComplete={handlePreparingComplete} />
)}
</div>
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts
index 41930d6126..f02b86ac3f 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts
@@ -5,13 +5,18 @@ import {
} from "@/app/api/__generated__/endpoints/onboarding/onboarding";
import { resolveResponse } from "@/app/api/helpers";
import { useSupabase } from "@/lib/supabase/hooks/useSupabase";
+import { environment } from "@/services/environment";
+import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
+import { useLDClient } from "launchdarkly-react-client-sdk";
import { useRouter, useSearchParams } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { Step, useOnboardingWizardStore } from "./store";
-function parseStep(value: string | null): Step {
+const LD_INIT_TIMEOUT_SECONDS = 5;
+
+function parseStep(value: string | null, maxStep: number): Step {
const n = Number(value);
- if (n >= 1 && n <= 5) return n as Step;
+ if (Number.isInteger(n) && n >= 1 && n <= maxStep) return n as Step;
return 1;
}
@@ -22,26 +27,66 @@ export function useOnboardingPage() {
const currentStep = useOnboardingWizardStore((s) => s.currentStep);
const goToStep = useOnboardingWizardStore((s) => s.goToStep);
const reset = useOnboardingWizardStore((s) => s.reset);
- const [isLoading, setIsLoading] = useState(true);
+
+ // Wait for LaunchDarkly before initialising the wizard from the URL.
+ // Without this, the init effect runs against the default flag value
+ // (false) on first render and clamps e.g. ?step=5 down to step 1; once
+ // the flag resolves to true, the hasInitialized guard blocks re-init
+ // and the user is stuck on step 1.
+ const ldClient = useLDClient();
+ const ldEnabled = environment.areFeatureFlagsEnabled();
+ const [areFlagsReady, setAreFlagsReady] = useState(!ldEnabled);
+ useEffect(() => {
+ if (!ldEnabled || !ldClient || areFlagsReady) return;
+ let cancelled = false;
+ // Use the same 5s timeout as LDProvider so the wizard never hangs
+ // when LaunchDarkly is unreachable; on timeout we fall back to the
+ // default flag values that useGetFlag already returns.
+ ldClient
+ .waitForInitialization(LD_INIT_TIMEOUT_SECONDS)
+ .catch(() => undefined)
+ .finally(() => {
+ if (!cancelled) setAreFlagsReady(true);
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [ldClient, ldEnabled, areFlagsReady]);
+
+ // Snapshot the flag once LaunchDarkly resolves so an admin toggling
+ // ENABLE_PLATFORM_PAYMENT mid-session can't shuffle steps under a user
+ // who is already inside the wizard.
+ const livePaymentEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
+ const paymentEnabledSnapshot = useRef<boolean | null>(null);
+ if (paymentEnabledSnapshot.current === null && areFlagsReady) {
+ paymentEnabledSnapshot.current = livePaymentEnabled;
+ }
+ const isPaymentEnabled = paymentEnabledSnapshot.current ?? false;
+ const preparingStep: Step = isPaymentEnabled ? 5 : 4;
+ const totalSteps = isPaymentEnabled ? 4 : 3;
+
+ const [isOnboardingStateLoading, setIsOnboardingStateLoading] =
+ useState(true);
const hasSubmitted = useRef(false);
const hasInitialized = useRef(false);
// Initialise store from URL on mount, reset form data
useEffect(() => {
- if (hasInitialized.current) return;
+ if (!areFlagsReady || hasInitialized.current) return;
hasInitialized.current = true;
- const urlStep = parseStep(searchParams.get("step"));
+ const urlStep = parseStep(searchParams.get("step"), preparingStep);
reset();
goToStep(urlStep);
- }, [searchParams, reset, goToStep]);
+ }, [areFlagsReady, searchParams, reset, goToStep, preparingStep]);
// Sync store → URL when step changes
useEffect(() => {
- const urlStep = parseStep(searchParams.get("step"));
+ if (!areFlagsReady) return;
+ const urlStep = parseStep(searchParams.get("step"), preparingStep);
if (currentStep !== urlStep) {
router.replace(`/onboarding?step=${currentStep}`, { scroll: false });
}
- }, [currentStep, router, searchParams]);
+ }, [areFlagsReady, currentStep, router, searchParams, preparingStep]);
// Check if onboarding already completed
useEffect(() => {
@@ -57,15 +102,15 @@ export function useOnboardingPage() {
} catch {
// If we can't check, show onboarding anyway
}
- setIsLoading(false);
+ setIsOnboardingStateLoading(false);
}
checkCompletion();
}, [isLoggedIn, router]);
- // Submit profile when entering step 5 (Preparing)
+ // Submit profile when entering the Preparing step
useEffect(() => {
- if (currentStep !== 5 || hasSubmitted.current) return;
+ if (currentStep !== preparingStep || hasSubmitted.current) return;
hasSubmitted.current = true;
const { name, role, otherRole, painPoints, otherPainPoint } =
@@ -86,7 +131,7 @@ export function useOnboardingPage() {
}).catch(() => {
// Best effort — profile data is non-critical for accessing copilot
});
- }, [currentStep]);
+ }, [currentStep, preparingStep]);
async function handlePreparingComplete() {
for (let attempt = 0; attempt < 3; attempt++) {
@@ -103,7 +148,10 @@ export function useOnboardingPage() {
return {
currentStep,
- isLoading,
+ isLoading: isOnboardingStateLoading || !areFlagsReady,
handlePreparingComplete,
+ isPaymentEnabled,
+ preparingStep,
+ totalSteps,
};
}
diff --git a/autogpt_platform/frontend/src/playwright/utils/onboarding.ts b/autogpt_platform/frontend/src/playwright/utils/onboarding.ts
index 1d2ff27808..85fdd04b56 100644
--- a/autogpt_platform/frontend/src/playwright/utils/onboarding.ts
+++ b/autogpt_platform/frontend/src/playwright/utils/onboarding.ts
@@ -45,7 +45,8 @@ export async function skipOnboardingIfPresent(
}
/**
- * Walk through the full 5-step onboarding wizard in the browser.
+ * Walk through the onboarding wizard in the browser. The Subscription step
+ * is gated behind ENABLE_PLATFORM_PAYMENT and only walked when present.
* Returns the data that was entered so tests can verify it was submitted.
*/
export async function completeOnboardingWizard(
@@ -84,19 +85,32 @@ export async function completeOnboardingWizard(
}
await page.getByRole("button", { name: "Continue" }).click();
- // Step 4: Subscription — pick a plan to advance.
- // (The "Team" CTA opens an external intake form and does not advance.)
- await expect(page.getByText(/choose the plan that.s right/i)).toBeVisible({
- timeout: 5000,
+ // Subscription step (only when ENABLE_PLATFORM_PAYMENT is on) — pick a
+ // plan to advance. The "Team" CTA opens an external intake form and does
+ // not advance, so we don't exercise it here. Race the Subscription header
+ // against the Preparing header so the helper works in both flag states
+ // without a fixed timeout that flakes under slow renders.
+ const subscriptionHeader = page.getByText(/choose the plan that.s right/i);
+ const preparingHeader = page.getByText("Preparing your workspace...", {
+ exact: false,
});
- const planCta = plan === "max" ? "Upgrade to Max" : "Get Pro";
- await page.getByRole("button", { name: planCta }).click();
+ const nextState = await Promise.race([
+ subscriptionHeader
+ .waitFor({ state: "visible", timeout: 10000 })
+ .then(() => "subscription" as const),
+ preparingHeader
+ .waitFor({ state: "visible", timeout: 10000 })
+ .then(() => "preparing" as const),
+ ]);
+
+ if (nextState === "subscription") {
+ const planCta = plan === "max" ? "Upgrade to Max" : "Get Pro";
+ await page.getByRole("button", { name: planCta }).click();
+ }
- // Step 5: Preparing — require the real transition state to appear first,
+ // Final step: Preparing — require the real transition state to appear first,
// then wait for the app shell on /copilot rather than racing the redirect.
- await expect(
- page.getByText("Preparing your workspace...", { exact: false }),
- ).toBeVisible({ timeout: 10000 });
+ await expect(preparingHeader).toBeVisible({ timeout: 10000 });
await page.waitForURL(/\/copilot/, { timeout: 30000 });
await expect(page.getByTestId("profile-popout-menu-trigger")).toBeVisible({
timeout: 15000,