⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(web): share task reads for sync title updates
Tineaff9fed1a5f
diff --git a/apps/web/src/hooks/use-project-websocket-cache.test.tsx b/apps/web/src/hooks/use-project-websocket-cache.test.tsxindex ee1aa175c..a0d488b38 100644--- a/apps/web/src/hooks/use-project-websocket-cache.test.tsx+++ b/apps/web/src/hooks/use-project-websocket-cache.test.tsx@@ -627,3 +627,25 @@ it("keeps cached names unchanged when the task API denies the title read", asyncawait Promise.resolve();expect(mocks.client.setQueriesData).not.toHaveBeenCalled();});++it("shares one authorized task read between the board and sync samples", async () => {+ mocks.getTask.mockReset().mockResolvedValue({+ id: "a",+ projectId: "p",+ title: "Current",+ status: "todo",+ position: 0,+ });+ mocks.client.getQueriesData.mockReturnValue([+ [[], { matchingTasks: [{ id: "a" }], pausedTasks: [] }],+ ]);+ renderHook(() => useProjectWebSocket("p"));+ Socket.current.message("TASK_UPDATED", {+ taskId: "a",+ taskTitleChanged: true,+ });+ await vi.waitFor(() =>+ expect(mocks.client.setQueriesData).toHaveBeenCalled(),+ );+ expect(mocks.getTask).toHaveBeenCalledOnce();+});diff --git a/apps/web/src/hooks/use-project-websocket.ts b/apps/web/src/hooks/use-project-websocket.tsindex 48140eb7e..3833b5f16 100644--- a/apps/web/src/hooks/use-project-websocket.ts+++ b/apps/web/src/hooks/use-project-websocket.ts@@ -186,6 +186,7 @@ export function useProjectWebSocket(projectId: string) {if (disposed || activeSocket !== ws) return;try {const message = JSON.parse(event.data);+ let titleTaskRequest: ReturnType<typeof getTask> | undefined;if (message.taskId &&message.taskTitleChanged &&@@ -195,7 +196,8 @@ export function useProjectWebSocket(projectId: string) {const version = (titleVersions.get(taskId) ?? 0) + 1;titleVersions.set(taskId, version);// Read titles through the task API, which enforces task-read permission.- void getTask(taskId, "board")+ titleTaskRequest = getTask(taskId, "board");+ void titleTaskRequest.then((task) => {if (!disposed &&@@ -380,7 +382,7 @@ export function useProjectWebSocket(projectId: string) {} else {refreshingTasks.add(taskId);void Promise.all([- getTask(taskId, "board"),+ titleTaskRequest ?? getTask(taskId, "board"),getLabelsByTask({ taskId }),getExternalLinks(taskId),])diff --git a/tests/api-integration/integration-sync-field-labels.test.ts b/tests/api-integration/integration-sync-field-labels.test.tsindex 43cc8c3a3..b91cb9db4 100644--- a/tests/api-integration/integration-sync-field-labels.test.ts+++ b/tests/api-integration/integration-sync-field-labels.test.ts@@ -10,7 +10,11 @@ import {createWorkspaceMember,} from "./helpers/fixtures";-const mocks = vi.hoisted(() => ({ labels: new Set<string>(), write: vi.fn() }));+const mocks = vi.hoisted(() => ({+ labels: new Set<string>(),+ read: vi.fn(),+ write: vi.fn(),+}));const names = ["status:planned","status:in-progress",@@ -33,7 +37,7 @@ vi.mock("../../apps/api/src/plugins/github/utils/github-app", () => ({getVerifiedInstallationOctokit: async () => ({rest: {issues: {- get: async () => ({ data: issue() }),+ get: async () => ({ data: await mocks.read() }),getLabel: async () => ({}),removeLabel: async ({ name }: { name: string }) => {mocks.labels.delete(name);@@ -48,7 +52,7 @@ vi.mock("../../apps/api/src/plugins/github/utils/github-app", () => ({}));vi.mock("../../apps/api/src/plugins/gitea/utils/gitea-api", () => ({createGiteaClient: () => ({- getIssue: async () => issue(),+ getIssue: async () => mocks.read(),listLabels: async () => available(),removeLabelFromIssue: async (_owner: string,@@ -71,7 +75,7 @@ vi.mock("../../apps/api/src/plugins/gitea/utils/gitea-api", () => ({}));vi.mock("../../apps/api/src/plugins/gitlab/utils/gitlab-api", () => ({createGitlabClient: () => ({- getIssue: async () => issue(),+ getIssue: async () => mocks.read(),listLabels: async () => available(),updateIssue: async (_project: string,@@ -90,15 +94,17 @@ vi.mock("../../apps/api/src/plugins/gitlab/utils/gitlab-api", () => ({beforeEach(async () => {await resetTestDatabase();mocks.write.mockReset().mockResolvedValue(undefined);+ mocks.read.mockReset().mockImplementation(() => issue());mocks.labels = new Set(["status:planned", "priority:low", "keep"]);});it.each((["github", "gitea", "gitlab"] as const).flatMap((provider) =>(["status", "priority"] as const).flatMap((field) =>- (field === "priority" ? [false, true, "clear"] : [false, true]).map(- (overlap) => ({ provider, field, overlap }),- ),+ (field === "priority"+ ? [false, true, "clear", "read-error"]+ : [false, true]+ ).map((overlap) => ({ provider, field, overlap })),),),)(@@ -204,6 +210,33 @@ it.each(started();await gate;});+ if (overlap === "read-error") {+ const errors = vi.spyOn(console, "error").mockImplementation(() => {});+ const privateError = Object.assign(+ new Error("fake-private-provider-body"),+ {+ request: {+ headers: { authorization: "fake-private-provider-token" },+ },+ },+ );+ mocks.read.mockRejectedValueOnce(privateError);+ try {+ await sync(field === "status" ? "to-do" : "urgent", first);+ const output = errors.mock.calls+ .flatMap((args) =>+ args.map((value) => String(value) + JSON.stringify(value)),+ )+ .join("\n");+ expect(output).not.toContain("fake-private-provider");+ expect(output).toContain(integration.id);+ expect(output).toContain(link.id);+ expect(mocks.write).not.toHaveBeenCalled();+ return;+ } finally {+ errors.mockRestore();+ }+ }const initial = sync(field === "status" ? "to-do" : "urgent", first);if (overlapping) {await writing;