Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(api): finish initialization when dispatch skips an archived task

Tin1b5c996a917a
diff --git a/apps/api/src/plugins/github/services/sync-latest-task-value.ts b/apps/api/src/plugins/github/services/sync-latest-task-value.ts
index d7ca90a65..40f8f6680 100644
--- a/apps/api/src/plugins/github/services/sync-latest-task-value.ts
+++ b/apps/api/src/plugins/github/services/sync-latest-task-value.ts
@@ -71,17 +71,20 @@ export async function syncLatestTaskValue(
return;
return binding;
};
+ // Archived tasks send no state, even for retried initialization or repairs.
+ // Skipping counts as synchronized so callers such as initialization finish.
+ const statePaused = async () => {
+ if (field !== "state") return false;
+ const task = await db.query.taskTable.findFirst({
+ where: linkedTaskScope(taskId, projectId),
+ columns: { status: true },
+ });
+ return !!task && isStateSyncPaused(task.status);
+ };
for (;;) {
const binding = await currentBinding();
if (!binding) return;
- // Archived tasks send no state, even for retried initialization or repairs.
- if (field === "state") {
- const task = await db.query.taskTable.findFirst({
- where: linkedTaskScope(taskId, projectId),
- columns: { status: true },
- });
- if (task && isStateSyncPaused(task.status)) return true;
- }
+ if (await statePaused()) return true;
identity ??= binding.integration
? { type: binding.integration.type, config: binding.integration.config }
: undefined;
@@ -124,7 +127,8 @@ export async function syncLatestTaskValue(
uncertain: false,
},
});
- return;
+ // Dispatch also skips a task archived after the check above.
+ return (await statePaused()) || undefined;
}
updatedAt = dispatched.value;
attempts++;
diff --git a/tests/api-integration/integration-sync-providers.test.ts b/tests/api-integration/integration-sync-providers.test.ts
index d173c9a93..d68e2b897 100644
--- a/tests/api-integration/integration-sync-providers.test.ts
+++ b/tests/api-integration/integration-sync-providers.test.ts
@@ -701,6 +701,75 @@ describe.each(["github", "gitea", "gitlab"] as const)(
});
});
+ it("completes initialization when the task is archived before the state write", async () => {
+ const f = await setup(type);
+ await f.assign();
+ await db
+ .update(schema.integrationTable)
+ .set({
+ config: JSON.stringify({
+ ...f.config,
+ commentTaskLinkOnGitHubIssue: true,
+ commentTaskLinkOnGiteaIssue: true,
+ commentTaskLinkOnGitlabIssue: true,
+ }),
+ })
+ .where(eq(schema.integrationTable.id, f.integration.id));
+ await db
+ .update(schema.taskTable)
+ .set({ status: f.columns.done.slug, columnId: f.columns.done.id })
+ .where(eq(schema.taskTable.id, f.task.id));
+ const canSyncTask = eligibility.canSyncTask;
+ let archived = false;
+ // Archive once the state intent is pending, before its dispatch.
+ const guard = vi
+ .spyOn(eligibility, "canSyncTask")
+ .mockImplementation(async (...args) => {
+ const link = await db.query.externalLinkTable.findFirst();
+ if (
+ !archived &&
+ args[2] === undefined &&
+ JSON.parse(
+ link?.metadata ?? "{}",
+ ).lastSync?.state?.outbound?.some(
+ (entry: { pending?: boolean }) => entry.pending,
+ )
+ ) {
+ archived = true;
+ await db
+ .update(schema.taskTable)
+ .set({ status: "archived", columnId: null })
+ .where(eq(schema.taskTable.id, f.task.id));
+ }
+ return canSyncTask(...args);
+ });
+
+ await reconcileTaskSync(f.project.id, f.task.id);
+ guard.mockRestore();
+
+ expect(archived).toBe(true);
+ for (const call of mocks.update.mock.calls)
+ expect(call.at(-1)).not.toMatchObject(closed);
+ expect(mocks.labels).toHaveBeenCalled();
+ // Only GitHub initialization posts a task-link comment.
+ if (type === "github") expect(mocks.comment).toHaveBeenCalled();
+ expect(
+ JSON.parse((await db.query.externalLinkTable.findFirst())!.metadata!),
+ ).toMatchObject({
+ syncInitializedState: true,
+ syncInitializedLabels: true,
+ ...(type === "github" ? { syncInitializedComment: true } : {}),
+ syncInitializationPending: false,
+ });
+ expect(
+ (
+ await db.query.taskTable.findFirst({
+ where: eq(schema.taskTable.id, f.task.id),
+ })
+ )?.status,
+ ).toBe("archived");
+ });
+
it.runIf(type === "gitlab")(
"ignores live close and reopen webhooks for an archived task",
async () => {