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): recover server directory after channel access changes (#1133)
Generdf43d6a5ba8a
diff --git a/src/web/src/hooks/community/use-servers.dom.test.ts b/src/web/src/hooks/community/use-servers.dom.test.tsindex c4415961f..5419789e2 100644--- a/src/web/src/hooks/community/use-servers.dom.test.ts+++ b/src/web/src/hooks/community/use-servers.dom.test.ts@@ -6,7 +6,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"import { act, renderHook, waitFor } from "@/test/react-dom-harness"import { createCommunityDbRegistry, registerCommunityDbRegistry, type CommunityDbRegistry } from "@/lib/community-db/collections"import { CommunityDbProvider } from "@/lib/community-db/projections"-import { captureCommunityLiveSnapshotToken, publishAccountAttentionSnapshot, publishCommunityLiveSnapshot, projectCommunityWsEventToDb, publishCommunityChannelDirectory } from "@/lib/community-db/sync"+import { captureCommunityLiveSnapshotToken, publishAccountAttentionSnapshot, publishCommunityLiveSnapshot, projectCommunityWsEventToDb, publishCommunityChannelDirectory, retireCommunityChannelReading } from "@/lib/community-db/sync"import { communityKeys } from "@/lib/query-keys"import { ApiError } from "@/lib/errors"import { forumConversationEntryFixture, seedConversationEntry } from "@/test/conversation-entry-fixtures"@@ -205,6 +205,34 @@ describe("useServers / serversQueryFn", () => {})describe("useServer / projected canonical detail", () => {+ it.each(["denial", "membership"] as const)("restarts a directory read superseded by channel %s without losing the server", async change => {+ seedList()+ let release!: () => void+ const response = new Promise<void>(resolve => { release = resolve })+ let initial = true+ apiFetchMock.mockImplementation(async (url: string) => {+ if (initial) await response+ return url.endsWith("/channels")+ ? { channels: [channelResourceFixture({ id: "all", name: "all", serverId: identity.id, categoryId: "cat_1" })] }+ : detailApi(url)+ })+ const view = renderHook(() => useServer(identity.id), { wrapper: Owner })+ await waitFor(() => expect(apiFetchMock.mock.calls.filter(([url]) => String(url).endsWith("/channels"))).toHaveLength(1))+ const accessEpoch = registry.runtime.ws.get().accessEpoch+ await act(async () => {+ if (change === "denial") retireCommunityChannelReading(registry, "room", { reason: "read-denied", serverId: identity.id, denialCode: "not_allowed" })+ else registry.runtime.ws.actions.beginChannelMembershipChange(identity.id, "room")+ initial = false+ release()+ })+ expect(registry.runtime.ws.get().accessEpoch).toBe(accessEpoch)+ await waitFor(() => expect({ error: view.result.current.error?.message ?? null, channels: view.result.current.server?.categories[0]?.channels.map(channel => channel.id) }).toEqual({ error: null, channels: ["all"] }))+ expect(view.result.current.isError).toBe(false)+ expect(registry.collections.channels.has("room")).toBe(false)+ expect(registry.runtime.ws.actions.isChannelAccessRevoked("room", identity.id)).toBe(change === "denial")+ expect(apiFetchMock.mock.calls.filter(([url]) => String(url).endsWith("/channels"))).toHaveLength(2)+ })+it.each(["account", "owner"])("rechecks %s ownership after structural retirement rejects and before the hook restarts", async retirement => {seedList()let release!: () => voiddiff --git a/src/web/src/hooks/community/use-servers.ts b/src/web/src/hooks/community/use-servers.tsindex 139a5e9a7..c21e1f427 100644--- a/src/web/src/hooks/community/use-servers.ts+++ b/src/web/src/hooks/community/use-servers.ts@@ -257,9 +257,10 @@ function serverDetailReadSuperseded(queryClient: QueryClient, serverId: string,if (!registry || registry !== token.registry) return falseconst state = registry.runtime.ws.get()const lifecycle = registry.runtime.lifecycle.get()+ const channelScopesChanged = [...state.channelAccessScopes].some(([id, scope]) => scope.generation !== (token.channelScopes.get(id)?.generation ?? 0))return !signal?.aborted && lifecycle.active && lifecycle.generation === token.ownerGeneration&& state.profileViewerId === token.viewerId && state.profileAccountEpoch === token.accountEpoch- && state.accessEpoch !== token.accessEpoch && !state.revokedServerIds.has(serverId)+ && (state.accessEpoch !== token.accessEpoch || channelScopesChanged) && !state.revokedServerIds.has(serverId)}class SupersededServerDetailRead extends DOMException {