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.
fix(frontend): redirect legacy /profile links to new settings on both layouts (#14000)
Abhimanyu Yadavdba630955310
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/__tests__/useNewSettingsRedirect.test.tsx b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/__tests__/useNewSettingsRedirect.test.tsxindex 08742e1e08..e7a5649a0d 100644--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/__tests__/useNewSettingsRedirect.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/__tests__/useNewSettingsRedirect.test.tsx@@ -1,13 +1,10 @@import { renderHook } from "@testing-library/react";import { beforeEach, describe, expect, it, vi } from "vitest";-const { usePathnameMock, usePlatformChromeMock, replaceMock } = vi.hoisted(- () => ({- usePathnameMock: vi.fn(() => "/profile"),- usePlatformChromeMock: vi.fn(() => ({ isNewLayoutActive: true })),- replaceMock: vi.fn(),- }),-);+const { usePathnameMock, replaceMock } = vi.hoisted(() => ({+ usePathnameMock: vi.fn(() => "/profile"),+ replaceMock: vi.fn(),+}));vi.mock("next/navigation", () => ({useRouter: () => ({@@ -23,16 +20,16 @@ vi.mock("next/navigation", () => ({useParams: () => ({}),}));-vi.mock("@/app/(platform)/PlatformChrome/usePlatformChrome", () => ({- usePlatformChrome: usePlatformChromeMock,-}));-import { useNewSettingsRedirect } from "../useNewSettingsRedirect";+function setLocation(url: string) {+ window.history.replaceState({}, "", url);+}+describe("useNewSettingsRedirect", () => {beforeEach(() => {replaceMock.mockClear();- usePlatformChromeMock.mockReturnValue({ isNewLayoutActive: true });+ setLocation("/");});const mappings: [string, string][] = [@@ -40,9 +37,7 @@ describe("useNewSettingsRedirect", () => {["/profile/dashboard", "/settings/creator-dashboard"],["/profile/credits", "/settings/billing"],["/profile/integrations", "/settings/integrations"],- ["/profile/settings", "/settings/account"],["/profile/api-keys", "/settings/api-keys"],- ["/profile/oauth-apps", "/settings/oauth-apps"],];it.each(mappings)("redirects %s to %s", (from, to) => {@@ -63,9 +58,54 @@ describe("useNewSettingsRedirect", () => {expect(replaceMock).toHaveBeenCalledWith("/settings/profile");});- it("does not redirect while the classic layout is active", () => {- usePlatformChromeMock.mockReturnValue({ isNewLayoutActive: false });- usePathnameMock.mockReturnValue("/profile");+ it("keeps the hash so anchored deep links survive the hop", () => {+ usePathnameMock.mockReturnValue("/profile/dashboard");+ setLocation("/profile/dashboard#submissions");++ renderHook(() => useNewSettingsRedirect());++ expect(replaceMock).toHaveBeenCalledWith(+ "/settings/creator-dashboard#submissions",+ );+ });++ it("keeps the query string so Stripe return params survive the hop", () => {+ usePathnameMock.mockReturnValue("/profile/credits");+ setLocation("/profile/credits?subscription=success");++ renderHook(() => useNewSettingsRedirect());++ expect(replaceMock).toHaveBeenCalledWith(+ "/settings/billing?subscription=success",+ );+ });++ const keptOnLegacy = ["/profile/oauth-apps", "/profile/settings"];++ it.each(keptOnLegacy)(+ "keeps %s on the legacy page while the new one lacks its features",+ (pathname) => {+ usePathnameMock.mockReturnValue(pathname);++ const { result } = renderHook(() => useNewSettingsRedirect());++ expect(result.current.isRedirecting).toBe(false);+ expect(replaceMock).not.toHaveBeenCalled();+ },+ );++ it("keeps the #notifications anchor reachable on the legacy settings page", () => {+ usePathnameMock.mockReturnValue("/profile/settings");+ setLocation("/profile/settings#notifications");++ const { result } = renderHook(() => useNewSettingsRedirect());++ expect(result.current.isRedirecting).toBe(false);+ expect(replaceMock).not.toHaveBeenCalled();+ });++ it("does not redirect paths outside /profile", () => {+ usePathnameMock.mockReturnValue("/marketplace");const { result } = renderHook(() => useNewSettingsRedirect());diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/layout.tsx b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/layout.tsxindex 9afa3f9688..8537fc6e35 100644--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/layout.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/layout.tsx@@ -65,8 +65,8 @@ export default function Layout({ children }: { children: React.ReactNode }) {},];- // Under the new layout these legacy pages redirect to /settings — render- // nothing while the replace() is in flight so the old shell never flashes.+ // These legacy pages redirect to /settings — render nothing while the+ // replace() is in flight so the old shell never flashes.if (isRedirecting) return null;return (diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/useNewSettingsRedirect.ts b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/useNewSettingsRedirect.tsindex cfa0c16b79..3336ec1e2e 100644--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/useNewSettingsRedirect.ts+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/useNewSettingsRedirect.ts@@ -1,32 +1,50 @@"use client";-import { usePlatformChrome } from "@/app/(platform)/PlatformChrome/usePlatformChrome";import { usePathname, useRouter } from "next/navigation";import { useEffect } from "react";-// The old /profile pages are superseded by /settings under the new layout.-// Each legacy page maps to its closest new-settings equivalent.+// The old /profile pages are superseded by /settings. Each legacy page maps to+// its closest new-settings equivalent. The new pages render under both the+// classic and the new layout, so this is deliberately not flag-gated — links+// in the wild (emails, bookmarks, the old sidebar) must land on the new+// surface regardless of which shell the user is on.const LEGACY_TO_NEW_SETTINGS: Record<string, string> = {"/profile": "/settings/profile","/profile/dashboard": "/settings/creator-dashboard","/profile/credits": "/settings/billing","/profile/integrations": "/settings/integrations",- "/profile/settings": "/settings/account","/profile/api-keys": "/settings/api-keys",- "/profile/oauth-apps": "/settings/oauth-apps",};+// Legacy pages whose /settings replacement isn't ready to receive them yet —+// redirecting would take working functionality away. Each is a one-line+// removal once the new surface catches up.+// /profile/oauth-apps → /settings/oauth-apps is a "Coming soon" placeholder.+// /profile/settings → /settings/account only shows notification+// preferences behind the ``settings-notifications`` flag (AGPT staff while+// the design is reworked), and this is exactly where every notification+// email — plus the List-Unsubscribe header — deep-links with+// #notifications. Drop this once the flag is on for everyone.+const KEEP_ON_LEGACY = new Set(["/profile/oauth-apps", "/profile/settings"]);+export function useNewSettingsRedirect() {- const { isNewLayoutActive } = usePlatformChrome();const pathname = usePathname();const router = useRouter();- const redirectTo = isNewLayoutActive+ const shouldRedirect =+ Boolean(pathname?.startsWith("/profile")) &&+ !KEEP_ON_LEGACY.has(pathname ?? "");++ const redirectTo = shouldRedirect? (LEGACY_TO_NEW_SETTINGS[pathname ?? ""] ?? "/settings/profile"): null;useEffect(() => {- if (redirectTo) router.replace(redirectTo);+ if (!redirectTo) return;+ // Carry the query string and hash across so deep links keep working —+ // e.g. Stripe's ?subscription=success still reaches /settings/billing.+ const { search, hash } = window.location;+ router.replace(`${redirectTo}${search}${hash}`);}, [redirectTo, router]);return { isRedirecting: Boolean(redirectTo) };diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/account/__tests__/main.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/account/__tests__/main.test.tsxindex aad375cccd..ec91f12471 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/account/__tests__/main.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/account/__tests__/main.test.tsx@@ -19,6 +19,7 @@ import {import SettingsPreferencesPage from "../page";const mockUseAuth = vi.hoisted(() => vi.fn());+const mockUseGetFlag = vi.hoisted(() => vi.fn());vi.mock("@/providers/onboarding/onboarding-provider", () => ({default: ({ children }: { children: ReactNode }) => <>{children}</>,@@ -28,6 +29,17 @@ vi.mock("@/lib/auth/hooks/useAuth", () => ({useAuth: mockUseAuth,}));+vi.mock("@/services/feature-flags/use-get-flag", async (importOriginal) => {+ const actual =+ await importOriginal<+ typeof import("@/services/feature-flags/use-get-flag")+ >();+ return {+ ...actual,+ useGetFlag: mockUseGetFlag,+ };+});+const testUser = {id: "user-1",email: "[email protected]",@@ -89,6 +101,10 @@ describe("SettingsPreferencesPage", () => {isLoggedIn: true,isUserLoading: false,});+ // Notifications are behind settings-notifications; default the suite to+ // "on" so the notification cases exercise the card, and flip it off in+ // the case that asserts it stays hidden.+ mockUseGetFlag.mockReturnValue(true);});test("renders Account card with current email and reset password link", async () => {@@ -153,7 +169,7 @@ describe("SettingsPreferencesPage", () => {expect((discardButton as HTMLButtonElement).disabled).toBe(true);});- test.skip("toggling a notification enables Save and persists on click", async () => {+ test("toggling a notification enables Save and persists on click", async () => {let submittedPreferences:| { email: string; preferences: Record<string, boolean> }| undefined;@@ -367,7 +383,7 @@ describe("SettingsPreferencesPage", () => {vi.unstubAllGlobals();});- test.skip("Discard reverts unsaved notification toggles", async () => {+ test("Discard reverts unsaved notification toggles", async () => {setupBaseHandlers();render(<SettingsPreferencesPage />);@@ -395,4 +411,15 @@ describe("SettingsPreferencesPage", () => {expect(targetSwitch.getAttribute("aria-checked")).toBe(initialChecked);});});++ test("hides the notifications card when settings-notifications is off", async () => {+ mockUseGetFlag.mockReturnValue(false);+ setupBaseHandlers();++ render(<SettingsPreferencesPage />);++ expect(await screen.findByText("Time zone")).toBeDefined();+ expect(screen.queryByText("Notifications")).toBeNull();+ expect(screen.queryAllByRole("switch")).toHaveLength(0);+ });});diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/account/page.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/account/page.tsxindex 8a0f857716..bb1872ca81 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/account/page.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/account/page.tsx@@ -3,8 +3,10 @@import { useEffect } from "react";import { ErrorCard } from "@/components/molecules/ErrorCard/ErrorCard";+import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";import { AccountCard } from "./components/AccountCard/AccountCard";+import { NotificationsCard } from "./components/NotificationsCard/NotificationsCard";import { PreferencesHeader } from "./components/PreferencesHeader/PreferencesHeader";import { PreferencesSkeleton } from "./components/PreferencesSkeleton/PreferencesSkeleton";import { SaveBar } from "./components/SaveBar/SaveBar";@@ -26,10 +28,13 @@ export default function SettingsPreferencesPage() {dirty,isSaving,setTimezone,+ toggleNotification,discardChanges,savePreferences,} = usePreferencesPage();+ const showNotifications = useGetFlag(Flag.SETTINGS_NOTIFICATIONS);+if (isError) {return (<ErrorCard@@ -60,6 +65,14 @@ export default function SettingsPreferencesPage() {index={1}/>+ {showNotifications ? (+ <NotificationsCard+ values={formState.notifications}+ onToggle={toggleNotification}+ index={2}+ />+ ) : null}+<SaveBarvisible={dirty}saving={isSaving}diff --git a/autogpt_platform/frontend/src/playwright/api-keys-happy-path.spec.ts b/autogpt_platform/frontend/src/playwright/api-keys-happy-path.spec.tsindex 9d0cbf8afc..408f3a4333 100644--- a/autogpt_platform/frontend/src/playwright/api-keys-happy-path.spec.ts+++ b/autogpt_platform/frontend/src/playwright/api-keys-happy-path.spec.ts@@ -14,18 +14,25 @@ test("api keys happy path: user can create, copy, and revoke an API key", asyncconst keyName = `E2E CLI Key ${randomUUID().slice(0, 8)}`;- await page.goto("/profile/api-keys");- await expect(page).toHaveURL(/\/profile\/api-keys/);+ await page.goto("/settings/api-keys");+ await expect(page).toHaveURL(/\/settings\/api-keys/);await expect(page.getByText(- "Manage your AutoGPT Platform API keys for programmatic access",+ "Manage API keys that let external tools access your AutoGPT account.",),).toBeVisible();- await page.getByRole("button", { name: "Create Key" }).click();- await page.getByLabel("Name").fill(keyName);- const executeGraphCheckbox = page.getByRole("checkbox", {- name: /EXECUTE_GRAPH/i,+ // The header renders a compact and a full-size "Create Key" button and hides+ // one per breakpoint, so match on the one actually rendered.+ await page+ .getByRole("button", { name: "Create Key" })+ .filter({ visible: true })+ .click();++ const createDialog = page.getByRole("dialog", { name: "Create API key" });+ await createDialog.getByLabel("Name", { exact: true }).fill(keyName);+ const executeGraphCheckbox = createDialog.getByRole("checkbox", {+ name: "Execute Graph",});const executeGraphChecked =(await executeGraphCheckbox.getAttribute("aria-checked")) === "true";@@ -34,11 +41,9 @@ test("api keys happy path: user can create, copy, and revoke an API key", async}await expect(executeGraphCheckbox).toHaveAttribute("aria-checked", "true");- await page.getByRole("button", { name: "Create" }).click();+ await createDialog.getByRole("button", { name: "Create Key" }).click();- const secretDialog = page.getByRole("dialog", {- name: "AutoGPT Platform API Key Created",- });+ const secretDialog = page.getByRole("dialog", { name: "Your new API key" });await expect.poll(async () => {@@ -47,7 +52,7 @@ test("api keys happy path: user can create, copy, and revoke an API key", async}const creationFailed = await page- .getByText("Failed to create AutoGPT Platform API key")+ .getByText("Failed to create API key").isVisible().catch(() => false);if (creationFailed) {@@ -70,8 +75,8 @@ test("api keys happy path: user can create, copy, and revoke an API key", async).trim();expect(createdSecret.length).toBeGreaterThan(0);- await secretDialog.getByRole("button").first().click();- await expect(page.getByText("Copied", { exact: true })).toBeVisible({+ await secretDialog.getByRole("button", { name: "Copy" }).click();+ await expect(page.getByText("Copied to clipboard")).toBeVisible({timeout: 15000,});await expect@@ -80,21 +85,21 @@ test("api keys happy path: user can create, copy, and revoke an API key", async}).toBe(createdSecret);+ // Both the header "X" and the footer button are labelled "Close"; either one+ // closes the dialog and resets the form.await secretDialog.getByRole("button", { name: "Close" }).first().click();- const createdKeyRow = page- .getByTestId("api-key-row")- .filter({ hasText: keyName })- .first();- await expect(createdKeyRow).toBeVisible({ timeout: 15000 });+ const deleteCreatedKeyButton = page.getByRole("button", {+ name: `Delete ${keyName}`,+ });+ await expect(deleteCreatedKeyButton).toBeVisible({ timeout: 15000 });- await createdKeyRow.getByTestId("api-key-actions").click();- await page.getByRole("menuitem", { name: "Revoke" }).click();+ await deleteCreatedKeyButton.click();+ const revokeDialog = page.getByRole("dialog", { name: "Revoke API key?" });+ await revokeDialog.getByRole("button", { name: "Revoke key" }).click();- await expect(- page.getByText("AutoGPT Platform API key revoked successfully"),- ).toBeVisible({ timeout: 15000 });- await expect(- page.getByTestId("api-key-row").filter({ hasText: keyName }),- ).toHaveCount(0);+ await expect(page.getByText("API key revoked")).toBeVisible({+ timeout: 15000,+ });+ await expect(deleteCreatedKeyButton).toHaveCount(0);});diff --git a/autogpt_platform/frontend/src/playwright/pages/profile-form.page.ts b/autogpt_platform/frontend/src/playwright/pages/profile-form.page.tsindex 0eccd59764..9639585970 100644--- a/autogpt_platform/frontend/src/playwright/pages/profile-form.page.ts+++ b/autogpt_platform/frontend/src/playwright/pages/profile-form.page.ts@@ -1,4 +1,4 @@-import { Locator, Page } from "@playwright/test";+import { expect, Locator, Page } from "@playwright/test";import { BasePage } from "./base.page";import { getSelectors } from "../utils/selectors";@@ -7,9 +7,9 @@ export class ProfileFormPage extends BasePage {super(page);}- private getId(id: string | RegExp): Locator {- const { getId } = getSelectors(this.page);- return getId(id);+ async open(): Promise<void> {+ await this.page.goto("/settings/profile");+ await expect(this.page).toHaveURL(/\/settings\/profile/);}private async hideFloatingWidgets(): Promise<void> {@@ -22,7 +22,8 @@ export class ProfileFormPage extends BasePage {// Locatorstitle(): Locator {- return this.getId("profile-info-form-title");+ const { getRole } = getSelectors(this.page);+ return getRole("heading", "Profile");}displayNameField(): Locator {@@ -46,9 +47,9 @@ export class ProfileFormPage extends BasePage {return getField(`Link ${index}`);}- cancelButton(): Locator {+ discardButton(): Locator {const { getButton } = getSelectors(this.page);- return getButton("Cancel");+ return getButton("Discard");}saveButton(): Locator {@@ -111,8 +112,8 @@ export class ProfileFormPage extends BasePage {}}- async clickCancel(): Promise<void> {- await this.cancelButton().click();+ async clickDiscard(): Promise<void> {+ await this.discardButton().click();}async clickSave(): Promise<void> {@@ -126,13 +127,7 @@ export class ProfileFormPage extends BasePage {}async waitForSaveComplete(timeoutMs: number = 15_000): Promise<void> {- const { getButton } = getSelectors(this.page);- await getButton("Save changes").waitFor({- state: "attached",- timeout: timeoutMs,- });- await getButton("Save changes").waitFor({- state: "visible",+ await expect(this.page.getByText("Profile saved")).toBeVisible({timeout: timeoutMs,});}diff --git a/autogpt_platform/frontend/src/playwright/settings-happy-path.spec.ts b/autogpt_platform/frontend/src/playwright/settings-happy-path.spec.tsindex 29dcd5187d..9bfdc9bceb 100644--- a/autogpt_platform/frontend/src/playwright/settings-happy-path.spec.ts+++ b/autogpt_platform/frontend/src/playwright/settings-happy-path.spec.ts@@ -57,7 +57,7 @@ test("settings happy path: user can edit display name and keep it after refresh"const updatedDisplayName = `E2E Display ${Date.now()}`;await loginPage.loginAsSeededUser("smokeSettings");- await page.goto("/profile");+ await profileFormPage.open();await expect(await profileFormPage.isLoaded()).toBe(true);await profileFormPage.setDisplayName(updatedDisplayName);diff --git a/autogpt_platform/frontend/src/services/feature-flags/use-get-flag.ts b/autogpt_platform/frontend/src/services/feature-flags/use-get-flag.tsindex 9d7475f3d4..528799f589 100644--- a/autogpt_platform/frontend/src/services/feature-flags/use-get-flag.ts+++ b/autogpt_platform/frontend/src/services/feature-flags/use-get-flag.ts@@ -22,6 +22,12 @@ export enum Flag {CHAT_PINNING = "chat-pinning",TASK_PROGRESS_BAR = "task-progress-bar",HIRE_EXPERTS = "hire-experts",+ // Reveals the notification-preferences card on /settings/account. The card+ // is built but its design is still being reworked, so it ships dark and is+ // targeted at AGPT staff in LaunchDarkly. Until this is on for everyone,+ // /profile/settings stays un-redirected (``useNewSettingsRedirect``) so the+ // toggles remain reachable for everyone else — flip both together.+ SETTINGS_NOTIFICATIONS = "settings-notifications",// Replaces the onboarding pillbox step with the voice brain dump.// Mirror of the backend ``Flag`` enum — the endpoints 404 when off, so// both sides must agree. Off renders the pillbox flow untouched.@@ -65,6 +71,9 @@ const defaultFlags = {[Flag.CHAT_PINNING]: false,[Flag.TASK_PROGRESS_BAR]: false,[Flag.HIRE_EXPERTS]: false,+ // Off by default so a LaunchDarkly outage or a missing key hides the card+ // rather than exposing the in-progress design to everyone.+ [Flag.SETTINGS_NOTIFICATIONS]: false,// Off by default: with no LaunchDarkly key (local dev, CI, Playwright)// the wizard falls back to this map, and a ``true`` here renders the// brain dump for everyone — which is what the backend 404s are meant to@@ -131,6 +140,8 @@ function readEnvOverride(flag: Flag): string | undefined {return process.env.NEXT_PUBLIC_FORCE_FLAG_TASK_PROGRESS_BAR;case Flag.HIRE_EXPERTS:return process.env.NEXT_PUBLIC_FORCE_FLAG_HIRE_EXPERTS;+ case Flag.SETTINGS_NOTIFICATIONS:+ return process.env.NEXT_PUBLIC_FORCE_FLAG_SETTINGS_NOTIFICATIONS;case Flag.ONBOARDING_BRAIN_DUMP:return process.env.NEXT_PUBLIC_FORCE_FLAG_ONBOARDING_BRAIN_DUMP;case Flag.GRAPHITI_MEMORY: