Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(issues): update test mocks and workspace switch ordering
Naiyuan Qing632ff1f8ae86
diff --git a/apps/web/app/(dashboard)/issues/[id]/page.test.tsx b/apps/web/app/(dashboard)/issues/[id]/page.test.tsxindex 86847a3019..b6b6b15113 100644--- a/apps/web/app/(dashboard)/issues/[id]/page.test.tsx+++ b/apps/web/app/(dashboard)/issues/[id]/page.test.tsx@@ -61,6 +61,35 @@ vi.mock("@/features/workspace", () => ({}),}));+// Mock issue store — supply a stable full issue object so storeIssue+// doesn't create a new reference each render (avoids infinite effect loop)+// and has all required fields for rendering.+const stableStoreIssues = vi.hoisted(() => [+ {+ id: "issue-1",+ workspace_id: "ws-1",+ number: 1,+ identifier: "TES-1",+ title: "Implement authentication",+ description: "Add JWT auth to the backend",+ status: "in_progress",+ priority: "high",+ assignee_type: "member",+ assignee_id: "user-1",+ creator_type: "member",+ creator_id: "user-1",+ parent_issue_id: null,+ position: 0,+ due_date: "2026-06-01T00:00:00Z",+ created_at: "2026-01-15T00:00:00Z",+ updated_at: "2026-01-20T00:00:00Z",+ },+]);+vi.mock("@/features/issues", () => ({+ useIssueStore: (selector: (s: any) => any) =>+ selector({ issues: stableStoreIssues }),+}));+// Mock ws-contextvi.mock("@/features/realtime", () => ({useWSEvent: () => {},@@ -246,7 +275,7 @@ describe("IssueDetailPage", () => {await renderPage("nonexistent-id");await waitFor(() => {- expect(screen.getByText("Issue not found")).toBeInTheDocument();+ expect(screen.getByText("This issue does not exist or has been deleted in this workspace.")).toBeInTheDocument();});});diff --git a/apps/web/features/workspace/store.ts b/apps/web/features/workspace/store.tsindex 5b3cbee603..75fe7fef56 100644--- a/apps/web/features/workspace/store.ts+++ b/apps/web/features/workspace/store.ts@@ -4,6 +4,7 @@ import { create } from "zustand";import type { Workspace, MemberWithUser, Agent, Skill } from "@/shared/types";import { useIssueStore } from "@/features/issues";import { useInboxStore } from "@/features/inbox";+import { useRuntimeStore } from "@/features/runtimes";import { api } from "@/shared/api";import { createLogger } from "@/shared/logger";@@ -93,10 +94,18 @@ export const useWorkspaceStore = create<WorkspaceStore>((set, get) => ({const ws = workspaces.find((item) => item.id === workspaceId);if (!ws) return;- // Clear stale data from other stores before switching+ // Switch identity FIRST — api client, localStorage, and the+ // workspace object in this store — so that any in-flight refetch+ // (e.g. triggered by a WS event during the async gap) already+ // targets the new workspace.+ api.setWorkspaceId(ws.id);+ localStorage.setItem("multica_workspace_id", ws.id);++ // Clear ALL stale data across every store before hydrating.useIssueStore.getState().setIssues([]);useInboxStore.getState().setItems([]);- set({ members: [], agents: [], skills: [] });+ useRuntimeStore.getState().setRuntimes([]);+ set({ workspace: ws, members: [], agents: [], skills: [] });await hydrateWorkspace(workspaces, ws.id);},