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): stop a long Other role from losing the onboarding profile (#15252)
Nicholas Tindled1700acd88d8
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.tsxindex b253540d9f..a5c3b18491 100644--- 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@@ -522,6 +522,31 @@ describe("OnboardingPage — flag-gated SubscriptionStep", () => {});});+ it("cuts a restored Other role to the 100 code points the profile accepts", async () => {+ mockFlagValue = false;+ mockUser = {+ id: "u1",+ email: "[email protected]",+ user_metadata: { name: "Reinier Bot" },+ };+ window.sessionStorage.setItem(STEP_STORAGE_KEY, "3");+ useOnboardingWizardStore.setState({+ role: "Other",+ otherRole: "🙂".repeat(150),+ painPoints: ["slow builds"],+ });+ currentSearchParams = new URLSearchParams("step=3");+ render(<OnboardingPage />);+ expect(await screen.findByTestId("step-preparing")).toBeDefined();+ await waitFor(() => {+ expect(submitOnboardingProfile).toHaveBeenCalledWith({+ user_name: "Reinier",+ user_role: "🙂".repeat(100),+ pain_points: ["slow builds"],+ });+ });+ });+it("does not submit a profile when no role was chosen", async () => {mockFlagValue = false;mockUser = { id: "u1", email: "[email protected]", user_metadata: {} };diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/helpers.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/helpers.tsindex 7cb2930ae6..56b3057d32 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/helpers.ts+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/helpers.ts@@ -3,6 +3,10 @@ import type { User } from "@/lib/auth/types";// Resolution of the wizard's "Other" / "Something else" sentinels into real// values for the Preparing-step profile submit.+// The profile submit rejects a longer role (the API counts code points), and+// the whole profile is then lost.+export const OTHER_ROLE_MAX_LENGTH = 100;+interface ProfileSource {role: string;otherRole: string;@@ -28,7 +32,10 @@ export function accountDisplayName(user: User | null | undefined): string {export function normalizeOnboardingProfile(state: ProfileSource,): NormalizedProfile {- const resolvedRole = state.role === "Other" ? state.otherRole : state.role;+ const resolvedRole =+ state.role === "Other"+ ? Array.from(state.otherRole).slice(0, OTHER_ROLE_MAX_LENGTH).join("")+ : state.role;const resolvedPainPoints = state.painPoints.filter((p) => p !== "Something else").concat(diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/RoleStep.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/RoleStep.tsxindex eb5fd18272..dfc15f9f73 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/RoleStep.tsx+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/RoleStep.tsx@@ -8,6 +8,7 @@ import { AutopilotAvatar } from "@/components/molecules/AutopilotAvatar/Autopiloimport { FadeIn } from "@/components/atoms/FadeIn/FadeIn";import { AnimatePresence, motion, useReducedMotion } from "framer-motion";import { SelectableCard } from "../components/SelectableCard";+import { OTHER_ROLE_MAX_LENGTH } from "../helpers";import { useOnboardingWizardStore } from "../store";import { Icon } from "@/components/atoms/Icon/Icon";import {@@ -123,6 +124,7 @@ export function RoleStep() {placeholder="Describe your role..."value={otherRole}onChange={(e) => setOtherRole(e.target.value)}+ maxLength={OTHER_ROLE_MAX_LENGTH}autoFocus/></div>diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/__tests__/RoleStep.test.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/__tests__/RoleStep.test.tsxindex 15b9207205..e3adbd6dbf 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/__tests__/RoleStep.test.tsx+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/__tests__/RoleStep.test.tsx@@ -4,6 +4,7 @@ import {fireEvent,cleanup,} from "@/tests/integrations/test-utils";+import userEvent from "@testing-library/user-event";import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";import { useOnboardingWizardStore } from "../../store";import { RoleStep } from "../RoleStep";@@ -98,6 +99,18 @@ describe("RoleStep", () => {expect(useOnboardingWizardStore.getState().currentStep).toBe(2);});+ test("the Other role stops at the 100 characters the profile accepts", async () => {+ vi.useRealTimers();+ const user = userEvent.setup();+ render(<RoleStep />);++ fireEvent.click(screen.getByRole("button", { name: /\bother\b/i }));+ await user.click(screen.getByPlaceholderText(/describe your role/i));+ await user.paste("a".repeat(150));++ expect(useOnboardingWizardStore.getState().otherRole).toHaveLength(100);+ });+test("switching from Other to a regular role hides the input and keeps the step", () => {render(<RoleStep />);