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): open mobile notifications directly in chat (#810)
Gustavo Yea3ab605c9ded
diff --git a/scripts/ci/e2e-shards.mjs b/scripts/ci/e2e-shards.mjsindex 36087d4b5..460ce58de 100644--- a/scripts/ci/e2e-shards.mjs+++ b/scripts/ci/e2e-shards.mjs@@ -83,6 +83,7 @@ export const SPEC_SECONDS = {"58-system-notifications.spec.ts": 46.600,"59-message-pagination-anchor.spec.ts": 45.600,"60-desktop-default-user-bar-width.spec.ts": 83.700,+ "63-mobile-notification-chat-route.spec.ts": DEFAULT_SPEC_SECONDS,}function walk(directory) {diff --git a/scripts/ci/e2e-shards.test.ts b/scripts/ci/e2e-shards.test.tsindex 680a47147..e76d72183 100644--- a/scripts/ci/e2e-shards.test.ts+++ b/scripts/ci/e2e-shards.test.ts@@ -75,16 +75,16 @@ describe("planE2eShards", () => {expect(first).toEqual(second)expect(Object.keys(SPEC_SECONDS).sort()).toEqual(specs)- expect(first).toHaveLength(11)+ expect(first).toHaveLength(12)expect([...assigned].sort()).toEqual(specs)expect(new Set(assigned).size).toBe(specs.length)expect(SPEC_SECONDS["55-message-scroll-characterization.spec.ts"]).toBe(109.548)expect(specSeconds).toEqual([- 153.053, 151.656, 152.753, 153.443, 151.8, 154.215,+ 165, 153.053, 151.656, 152.753, 153.443, 151.8, 154.215,154.336, 153.99, 151.817, 154.381, 151.885,])expect(predictedSeconds).toEqual([- 228.053, 226.656, 227.753, 228.443, 226.8, 229.215,+ 240, 228.053, 226.656, 227.753, 228.443, 226.8, 229.215,229.336, 228.99, 226.817, 229.381, 226.885,])expect(first.every((shard) => (diff --git a/src/web/src/lib/community/mobile-system-notification.test.ts b/src/web/src/lib/community/mobile-system-notification.test.tsindex 9822e19c1..4bc9cebe5 100644--- a/src/web/src/lib/community/mobile-system-notification.test.ts+++ b/src/web/src/lib/community/mobile-system-notification.test.ts@@ -258,7 +258,7 @@ describe("mobile notification HTTP adapter", () => {notificationId,messageId: "message_1",targetId: "channel_1",- })).resolves.toEqual({ href: "/c/me/channel_1?seq=9" })+ })).resolves.toEqual({ href: "/c/me/channel_1" })expect(fetchImpl.mock.calls.map(([url]) => url)).toEqual(["/api/community/notifications/devices",@@ -482,28 +482,28 @@ describe("mobile notification registration controller", () => {describe("mobile notification activation", () => {const activation = { notificationId, messageId: "message_1", targetId: "channel_1" }- it("navigates only after exact DM and server revalidation", async () => {+ it.each([["channel", "text"], ["forum", "forum"], ["thread", "thread"]] as const)("opens chat pages after exact DM and %s revalidation", async (surfaceKind, type) => {const dmFetch = vi.fn().mockResolvedValueOnce(new Response(JSON.stringify({messages: [{ id: "message_1", seq: 9 }],surfaceReceipt: { channelId: "channel_1", surfaceKind: "dm" },})))await expect(revalidateMobileSystemNotificationActivation(activation, dmFetch)).resolves.toEqual({- href: "/c/me/channel_1?seq=9",+ href: "/c/me/channel_1",})const serverFetch = vi.fn().mockResolvedValueOnce(new Response(JSON.stringify({messages: [{ id: "message_1", seq: 9 }],- surfaceReceipt: { channelId: "channel_1", surfaceKind: "thread" },+ surfaceReceipt: { channelId: "channel_1", surfaceKind },}))).mockResolvedValueOnce(new Response(JSON.stringify({id: "channel_1",serverId: "server_1",- type: "thread",+ type,})))await expect(revalidateMobileSystemNotificationActivation(activation, serverFetch)).resolves.toEqual({- href: "/c/channels/server_1/channel_1?msg=message_1",+ href: "/c/channels/server_1/channel_1",})expect(serverFetch.mock.calls.map(([url]) => url)).toEqual(["/api/community/channels/channel_1/messages?anchor=message_1&limit=1",@@ -511,6 +511,41 @@ describe("mobile notification activation", () => {])})+ it.each([+ ["cold", "dm"], ["resume", "dm"],+ ["cold", "channel"], ["resume", "channel"],+ ] as const)("navigates %s %s activation without selecting a message", async (lifecycle, kind) => {+ const fetchImpl = vi.fn()+ .mockResolvedValueOnce(new Response(JSON.stringify({+ messages: [{ id: activation.messageId, seq: 9 }],+ surfaceReceipt: { channelId: activation.targetId, surfaceKind: kind },+ })))+ .mockResolvedValueOnce(new Response(JSON.stringify({+ id: activation.targetId, serverId: "server_1", type: "text",+ })))+ const take = vi.fn()+ if (lifecycle === "resume") take.mockResolvedValueOnce(null)+ take.mockResolvedValueOnce(activation)+ const navigate = vi.fn()+ const openInbox = vi.fn()+ const controller = createMobileSystemNotificationActivationController({+ take,+ revalidate: (value) => revalidateMobileSystemNotificationActivation(value, fetchImpl),+ navigate,+ openInbox,+ })+ if (lifecycle === "resume") {+ await controller.drain()+ expect(navigate).not.toHaveBeenCalled()+ }+ await controller.drain()+ const href = kind === "dm" ? "/c/me/channel_1" : "/c/channels/server_1/channel_1"+ expect(navigate).toHaveBeenCalledExactlyOnceWith(href)+ expect(new URL(href, "https://example.test").search).toBe("")+ expect(openInbox).not.toHaveBeenCalled()+ controller.dispose()+ })+it.each([["deleted", new Response(null, { status: 404 })],["revoked", new Response(null, { status: 403 })],diff --git a/src/web/src/lib/community/mobile-system-notification.ts b/src/web/src/lib/community/mobile-system-notification.tsindex 91035c382..768d99908 100644--- a/src/web/src/lib/community/mobile-system-notification.ts+++ b/src/web/src/lib/community/mobile-system-notification.ts@@ -427,7 +427,7 @@ export async function revalidateMobileSystemNotificationActivation(if (receipt.surfaceKind === "dm") {return {- href: `/c/me/${encodeURIComponent(activation.targetId)}?seq=${message.seq}`,+ href: `/c/me/${encodeURIComponent(activation.targetId)}`,}}@@ -446,7 +446,7 @@ export async function revalidateMobileSystemNotificationActivation(const expectedType = receipt.surfaceKind === "channel" ? "text" : receipt.surfaceKindif (channel.type !== expectedType) return nullreturn {- href: `/c/channels/${encodeURIComponent(channel.serverId)}/${encodeURIComponent(activation.targetId)}?msg=${encodeURIComponent(activation.messageId)}`,+ href: `/c/channels/${encodeURIComponent(channel.serverId)}/${encodeURIComponent(activation.targetId)}`,}} catch {return nulldiff --git a/src/web/src/test/e2e-ui/63-mobile-notification-chat-route.spec.ts b/src/web/src/test/e2e-ui/63-mobile-notification-chat-route.spec.tsnew file mode 100644index 000000000..b98413b0c--- /dev/null+++ b/src/web/src/test/e2e-ui/63-mobile-notification-chat-route.spec.ts@@ -0,0 +1,203 @@+import { devices, type Page } from "@playwright/test"+import { expect, test, sessionCookie, userId } from "./_fixtures/community-fixture"+import { composerEditable } from "./_fixtures/actions"+import { seedCategory, seedChannel, seedChannelMember, seedDm, seedDmMessage, seedFriendship, seedJoinServer, seedMessage, seedServer } from "./_fixtures/seed"+import { tid } from "./_fixtures/testids"+import { WEB_URL } from "./_setup/paths"++type Activation = { notificationId: string; messageId: string; targetId: string }+type Bridge = { pending: Activation | null; listener: unknown; takes: number; visibility: DocumentVisibilityState }++async function installMobileBridge(page: Page, activation: Activation | null) {+ await page.addInitScript((initial) => {+ const key = `qa-mobile-consumed:${initial?.notificationId}`+ const state: Bridge = {+ pending: initial && !sessionStorage.getItem(key) ? initial : null,+ listener: null,+ takes: 0,+ visibility: "visible",+ }+ Object.defineProperty(document, "visibilityState", { configurable: true, get: () => state.visibility })+ Object.defineProperty(window, "__mobileNotificationQa", { configurable: true, value: state })+ class Channel { onmessage?: (value: unknown) => void }+ Object.defineProperty(window, "__TAURI__", {+ configurable: true,+ value: { core: { Channel, invoke: async (command: string, args?: Record<string, unknown>) => {+ if (command === "mobile_system_notification_listen") { state.listener = args?.channel; return 1 }+ if (command === "mobile_system_notification_take_activation") {+ state.takes += 1+ const value = state.pending+ state.pending = null+ if (value) sessionStorage.setItem(key, "1")+ return value+ }+ if (command === "mobile_system_notification_check_permission" || command === "mobile_system_notification_request_permission") return { permissionState: "prompt" }+ return undefined+ } } },+ })+ }, activation)+}++async function resumeActivation(page: Page, activation: Activation) {+ await expect.poll(() => page.evaluate(() => (window as typeof window & { __mobileNotificationQa: Bridge }).__mobileNotificationQa.takes)).toBeGreaterThan(0)+ await page.evaluate((value) => {+ const state = (window as typeof window & { __mobileNotificationQa: Bridge }).__mobileNotificationQa+ state.visibility = "hidden"+ document.dispatchEvent(new Event("visibilitychange"))+ state.pending = value+ state.visibility = "visible"+ document.dispatchEvent(new Event("visibilitychange"))+ }, activation)+}++type MessageDoorEvidence = {+ status: number+ payload: { surfaceReceipt?: unknown; messages?: unknown }+}++async function captureMessageDoor(page: Page, targetId: string, messageId: string) {+ let capture!: (evidence: MessageDoorEvidence) => void+ let fail!: (error: unknown) => void+ const result = new Promise<MessageDoorEvidence>((resolve, reject) => {+ capture = resolve+ fail = reject+ })+ await page.route((url) => url.pathname === `/api/community/channels/${targetId}/messages`+ && url.searchParams.get("anchor") === messageId && url.searchParams.get("limit") === "1", async (route) => {+ try {+ const response = await route.fetch()+ const payload = await response.json()+ const evidence = { status: response.status(), payload }+ await route.fulfill({ response })+ capture(evidence)+ } catch (error) {+ fail(error)+ await route.abort()+ }+ })+ return { result }+}++async function deleteAsAlice(path: string) {+ const response = await fetch(`${WEB_URL}${path}`, { method: "DELETE", headers: { Cookie: sessionCookie("alice"), Origin: WEB_URL } })+ expect(response.ok, `${path}: ${response.status}`).toBeTruthy()+}++let serverId: string+let channelId: string+let channelMessageId: string+let dmId: string+let dmMessageId: string+let dmSeq: number+let channelSeq: number++test.describe("mobile notification chat routes (native bridge simulation)", () => {+ test.beforeAll(async () => {+ test.setTimeout(120_000)+ serverId = await seedServer("alice", `mobile-route-${Date.now()}`)+ channelId = await seedChannel("alice", serverId, "notification-chat")+ await seedJoinServer("alice", "bob", serverId)+ channelMessageId = await seedMessage("alice", channelId, "Channel notification route evidence")+ await seedFriendship("alice", "bob", userId("bob"))+ dmId = await seedDm("alice", userId("bob"))+ dmMessageId = await seedDmMessage("alice", dmId, "DM notification route evidence")+ const seqs = await Promise.all([[dmId, dmMessageId], [channelId, channelMessageId]].map(async ([targetId, messageId]) => {+ const response = await fetch(`${WEB_URL}/api/community/channels/${targetId}/messages?anchor=${messageId}&limit=1`, { headers: { Cookie: sessionCookie("bob") } })+ expect(response.status).toBe(200)+ const payload = await response.json() as { messages: Array<{ id: string; seq: number }> }+ return payload.messages.find((message) => message.id === messageId)!.seq+ }))+ ;[dmSeq, channelSeq] = seqs+ })++ for (const mode of ["cold", "resume"] as const) {+ for (const surface of ["dm", "channel"] as const) {+ test(`${mode} ${surface} opens chat without a context sheet`, async ({ asUser }, testInfo) => {+ const { page } = await asUser("bob", devices["iPhone 13"])+ const targetId = surface === "dm" ? dmId : channelId+ const messageId = surface === "dm" ? dmMessageId : channelMessageId+ const activation = { notificationId: crypto.randomUUID(), targetId, messageId }+ await installMobileBridge(page, mode === "cold" ? activation : null)+ const door = await captureMessageDoor(page, targetId, messageId)+ await page.goto("/c/me/friends")+ if (mode === "resume") await resumeActivation(page, activation)+ const { status, payload } = await door.result+ expect(status).toBe(200)+ expect(payload.surfaceReceipt).toEqual({ channelId: targetId, surfaceKind: surface })+ expect(payload.messages).toEqual(expect.arrayContaining([expect.objectContaining({ id: messageId })]))+ const path = surface === "dm" ? `/c/me/${targetId}` : `/c/channels/${serverId}/${targetId}`+ await expect(page).toHaveURL(`${WEB_URL}${path}`)+ await expect(composerEditable(page)).toBeVisible({ timeout: 30_000 })+ await expect(page.getByTestId(tid.message(messageId))).toBeVisible()+ await expect(page.locator('[data-slot="sheet-content"]')).toHaveCount(0)+ await testInfo.attach("message-door-evidence", { body: JSON.stringify({ simulation: "iPhone UA + Tauri command shim + browser visibility events", status, surfaceReceipt: payload.surfaceReceipt, messageId, url: page.url() }), contentType: "application/json" })+ await testInfo.attach("chat", { body: await page.screenshot(), contentType: "image/png" })+ })+ }+ }++ for (const kind of ["deleted", "revoked"] as const) {+ test(`${kind} target opens Inbox without unauthorized navigation`, async ({ asUser }, testInfo) => {+ const categoryId = kind === "revoked" ? await seedCategory("alice", serverId, `private-${Date.now()}`, { private: true }) : undefined+ const targetId = await seedChannel("alice", serverId, `${kind}-${Date.now()}`, "text", categoryId)+ if (kind === "revoked") await seedChannelMember("alice", targetId, userId("bob"))+ const messageId = await seedMessage("alice", targetId, `${kind} target evidence`)+ await deleteAsAlice(kind === "deleted" ? `/api/community/channels/${targetId}` : `/api/community/channels/${targetId}/members/${userId("bob")}`)+ const { page } = await asUser("bob", devices["iPhone 13"])+ await installMobileBridge(page, null)+ const door = await captureMessageDoor(page, targetId, messageId)+ const route = `/c/channels/${serverId}`+ await page.goto(route)+ await expect(page.getByTestId(tid.inboxTrigger)).toBeVisible({ timeout: 30_000 })+ await resumeActivation(page, { notificationId: crypto.randomUUID(), targetId, messageId })+ const { status } = await door.result+ expect([403, 404]).toContain(status)+ await expect(page.getByTestId(tid.inboxTrigger)).toHaveAttribute("aria-expanded", "true")+ await expect(page).toHaveURL(`${WEB_URL}${route}`)+ await testInfo.attach("fallback-evidence", { body: JSON.stringify({ kind, status, url: page.url() }), contentType: "application/json" })+ })+ }++ for (const surface of ["dm", "channel"] as const) {+ test(`ordinary ${surface} seq permalink retains message context`, async ({ asUser }, testInfo) => {+ const { page } = await asUser("bob", devices["iPhone 13"])+ const targetId = surface === "dm" ? dmId : channelId+ const messageId = surface === "dm" ? dmMessageId : channelMessageId+ const route = surface === "dm" ? `/c/me/${targetId}` : `/c/channels/${serverId}/${targetId}`+ const responsePromise = page.waitForResponse((response) => {+ const url = new URL(response.url())+ return url.pathname === `/api/community/channels/${targetId}/messages`+ && url.searchParams.get("anchor") === messageId && response.ok()+ })+ await page.goto(`${route}?seq=${surface === "dm" ? dmSeq : channelSeq}`)+ const response = await responsePromise+ const payload = await response.json()+ const content = surface === "dm" ? "DM notification route evidence" : "Channel notification route evidence"+ expect(payload.messages).toEqual(expect.arrayContaining([expect.objectContaining({ id: messageId, content })]))+ const sheet = page.locator('[data-slot="sheet-content"]')+ await expect(sheet).toBeVisible()+ await expect(sheet.locator('[data-anchor-row="1"]').getByText(+ content, { exact: true },+ )).toBeVisible()+ await testInfo.attach("permalink-context", { body: JSON.stringify({ status: response.status(), messageId, url: page.url() }), contentType: "application/json" })+ await testInfo.attach("context", { body: await page.screenshot(), contentType: "image/png" })+ })+ }++ test("ordinary channel msg permalink retains its message anchor", async ({ asUser }, testInfo) => {+ const { page } = await asUser("bob", devices["iPhone 13"])+ const responsePromise = page.waitForResponse((response) => {+ const url = new URL(response.url())+ return url.pathname === `/api/community/channels/${channelId}/messages` && url.searchParams.get("anchor") === channelMessageId && response.ok()+ })+ await page.goto(`/c/channels/${serverId}/${channelId}?msg=${channelMessageId}`)+ const response = await responsePromise+ const payload = await response.json()+ expect(payload.surfaceReceipt).toEqual({ channelId, surfaceKind: "channel" })+ expect(payload.messages).toEqual(expect.arrayContaining([expect.objectContaining({ id: channelMessageId })]))+ await expect(page.getByTestId(tid.message(channelMessageId))).toBeVisible()+ await expect(composerEditable(page)).toBeVisible({ timeout: 30_000 })+ await testInfo.attach("msg-anchor-evidence", { body: JSON.stringify({ status: response.status(), surfaceReceipt: payload.surfaceReceipt, anchorId: channelMessageId, url: page.url() }), contentType: "application/json" })+ })++})