Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(web): hydrate canonical self profile name (#573)
Gustavo Ye11b0e6e45c11
diff --git a/src/web/src/app/api/community/users/me/profile/route.test.ts b/src/web/src/app/api/community/users/me/profile/route.test.tsindex c9a33fec2..e94098001 100644--- a/src/web/src/app/api/community/users/me/profile/route.test.ts+++ b/src/web/src/app/api/community/users/me/profile/route.test.ts@@ -83,7 +83,12 @@ describe("GET /api/community/users/me/profile", () => {beforeEach(() => {vi.clearAllMocks()actorKind = "human"- getUser.mockResolvedValue({ id: "u1", discriminator: "4242", image: "/api/community/users/u1/avatar" })+ getUser.mockResolvedValue({+ id: "u1",+ name: "Jane Roe",+ discriminator: "4242",+ image: "/api/community/users/u1/avatar",+ })})it("returns defaults when no profile row exists", async () => {@@ -95,12 +100,13 @@ describe("GET /api/community/users/me/profile", () => {avatar: "/api/community/users/u1/avatar",bannerColor: null,discriminator: "4242",+ name: "Jane Roe",statusEmoji: null,statusText: "",})})- it("returns the stored profile fields when they exist", async () => {+ it("returns the canonical user name and stored profile fields when they exist", async () => {getProfile.mockResolvedValue({ aboutMe: "hi", bannerColor: "#aabbcc", statusEmoji: "π§", statusText: "Vibing" })const res = await GET(new NextRequest("http://localhost/api/community/users/me/profile"), {} as never)expect(await res.json()).toEqual({@@ -108,6 +114,7 @@ describe("GET /api/community/users/me/profile", () => {avatar: "/api/community/users/u1/avatar",bannerColor: "#aabbcc",discriminator: "4242",+ name: "Jane Roe",statusEmoji: "π§",statusText: "Vibing",})@@ -122,6 +129,7 @@ describe("GET /api/community/users/me/profile", () => {avatar: "",bannerColor: null,discriminator: "0000",+ name: "",statusEmoji: null,statusText: "",})diff --git a/src/web/src/app/api/community/users/me/profile/route.ts b/src/web/src/app/api/community/users/me/profile/route.tsindex 9a5ca6779..bdb65c6a7 100644--- a/src/web/src/app/api/community/users/me/profile/route.ts+++ b/src/web/src/app/api/community/users/me/profile/route.ts@@ -33,6 +33,7 @@ export const GET = withCommunityActor(async (_req, ctx) => {avatar: viewer?.image ?? "",bannerColor: profile?.bannerColor ?? null,discriminator: viewer?.discriminator ?? "0000",+ name: viewer?.name ?? "",statusEmoji: profile?.statusEmoji ?? null,statusText: profile?.statusText ?? "",})diff --git a/src/web/src/app/c/community-shell.identity.test.ts b/src/web/src/app/c/community-shell.identity.test.tsindex 8b6d9d8cf..1a45cae37 100644--- a/src/web/src/app/c/community-shell.identity.test.ts+++ b/src/web/src/app/c/community-shell.identity.test.ts@@ -2,9 +2,35 @@ import { beforeEach, describe, expect, it, vi } from "vitest"import React, { useState } from "react"import TestRenderer, { act } from "react-test-renderer"-let activeUser = { id: "user-a", name: "A", email: "[email protected]", avatar: "A" }+type TestUser = {+ id: string+ name: string+ email: string+ avatar: string+ aboutMe?: string+ discriminator?: string+ statusEmoji?: string | null+ statusText?: string | null+}++type ProfileResponse = {+ aboutMe: string+ avatar: string+ discriminator: string+ name: string+ statusEmoji: string | null+ statusText: string+}++let activeUser: TestUser = { id: "user-a", name: "A", email: "[email protected]", avatar: "A" }let providerInstance = 0const renderedProviders: Array<{ userId: string | null; instance: number }> = []+const { apiFetch } = vi.hoisted(() => ({+ apiFetch: vi.fn<() => Promise<ProfileResponse>>(),+}))+const setCurrentUser = vi.fn((updater: (user: TestUser) => TestUser) => {+ activeUser = updater(activeUser)+})vi.mock("./QueryProvider", () => ({QueryProvider: ({ children, userId }: { children: React.ReactNode; userId: string | null }) => {@@ -19,10 +45,10 @@ vi.mock("./QueryProvider", () => ({vi.mock("@/contexts/community/current-user", () => ({CurrentUserProvider: ({ children }: { children: React.ReactNode }) => children,useCurrentUser: () => activeUser,- useSetCurrentUser: () => vi.fn(),+ useSetCurrentUser: () => setCurrentUser,}))vi.mock("@/hooks/community/use-community-ws", () => ({ useCommunityWs: vi.fn() }))-vi.mock("@/lib/api/client", () => ({ apiFetch: vi.fn(() => new Promise(() => undefined)) }))+vi.mock("@/lib/api/client", () => ({ apiFetch }))vi.mock("@/components/perf/perf-trace-bootstrap", () => ({ PerfTraceBootstrap: () => null }))vi.mock("@/components/community/onboarding/community-onboarding-guide", () => ({CommunityOnboardingGuide: () => null,@@ -34,6 +60,9 @@ beforeEach(() => {activeUser = { id: "user-a", name: "A", email: "[email protected]", avatar: "A" }providerInstance = 0renderedProviders.length = 0+ apiFetch.mockReset()+ apiFetch.mockImplementation(() => new Promise(() => undefined))+ setCurrentUser.mockClear()})describe("CommunityShell identity boundary", () => {@@ -61,4 +90,70 @@ describe("CommunityShell identity boundary", () => {expect(userAInstance).toBe(1)renderer.unmount()})++ it("hydrates a stale session name from the canonical self profile", async () => {+ activeUser = { id: "user-a", name: "Alice", email: "[email protected]", avatar: "old-avatar" }+ apiFetch.mockResolvedValueOnce({+ aboutMe: "hello",+ avatar: "new-avatar",+ discriminator: "4242",+ name: "Jane Roe",+ statusEmoji: "π±",+ statusText: "Growing",+ })++ let renderer!: TestRenderer.ReactTestRenderer+ await act(async () => {+ renderer = TestRenderer.create(React.createElement(+ CommunityShell,+ { currentUser: activeUser },+ React.createElement("span", null, "content"),+ ))+ await Promise.resolve()+ })++ expect(apiFetch).toHaveBeenCalledWith("/api/community/users/me/profile")+ expect(setCurrentUser).toHaveBeenCalledOnce()+ expect(activeUser).toMatchObject({+ name: "Jane Roe",+ aboutMe: "hello",+ avatar: "new-avatar",+ discriminator: "4242",+ statusEmoji: "π±",+ statusText: "Growing",+ })+ renderer.unmount()+ })++ it("preserves the session name when the self profile has no canonical name", async () => {+ activeUser = { id: "user-a", name: "Alice", email: "[email protected]", avatar: "old-avatar" }+ apiFetch.mockResolvedValueOnce({+ aboutMe: "hello",+ avatar: "",+ discriminator: "4242",+ name: "",+ statusEmoji: null,+ statusText: "",+ })++ let renderer!: TestRenderer.ReactTestRenderer+ await act(async () => {+ renderer = TestRenderer.create(React.createElement(+ CommunityShell,+ { currentUser: activeUser },+ React.createElement("span", null, "content"),+ ))+ await Promise.resolve()+ })++ expect(activeUser).toMatchObject({+ name: "Alice",+ aboutMe: "hello",+ avatar: "old-avatar",+ discriminator: "4242",+ statusEmoji: null,+ statusText: "",+ })+ renderer.unmount()+ })})diff --git a/src/web/src/app/c/community-shell.tsx b/src/web/src/app/c/community-shell.tsxindex 675eeef25..6413cf4d7 100644--- a/src/web/src/app/c/community-shell.tsx+++ b/src/web/src/app/c/community-shell.tsx@@ -64,7 +64,7 @@ function CommunityBootstrap({ children }: { children: ReactNode }) {// row alongside the community profile fields.const currentUserId = currentUser.iduseEffect(() => {- apiFetch<{ aboutMe: string; avatar: string; discriminator: string; statusEmoji: string | null; statusText: string }>(+ apiFetch<{ aboutMe: string; avatar: string; discriminator: string; name: string; statusEmoji: string | null; statusText: string }>("/api/community/users/me/profile",).then((data) => {@@ -73,6 +73,7 @@ function CommunityBootstrap({ children }: { children: ReactNode }) {aboutMe: data.aboutMe,avatar: data.avatar || u.avatar,discriminator: data.discriminator,+ name: data.name || u.name,statusEmoji: data.statusEmoji,statusText: data.statusText,}))