⚡ 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(integrations): preserve rapid legitimate edits
Tin4f5a7d410dd6
diff --git a/apps/api/src/plugins/gitea/events/task-description-changed.ts b/apps/api/src/plugins/gitea/events/task-description-changed.tsindex 8eb8b148c..0e87d3c80 100644--- a/apps/api/src/plugins/gitea/events/task-description-changed.ts+++ b/apps/api/src/plugins/gitea/events/task-description-changed.ts@@ -71,19 +71,6 @@ export async function handleTaskDescriptionChanged(console.log("Skipping description sync - already synced from Gitea");return;}-- const timeSinceLastSync =- Date.now() - new Date(lastDescSync.timestamp).getTime();- if (- timeSinceLastSync < 2000 &&- lastDescSync.source === "gitea" &&- newDescNormalized === lastDescSync.value- ) {- console.log(- `Skipping description sync - recent sync detected (${timeSinceLastSync}ms ago)`,- );- return;- }}const client = createGiteaClient(config);diff --git a/apps/api/src/plugins/gitea/events/task-title-changed.ts b/apps/api/src/plugins/gitea/events/task-title-changed.tsindex f5be824f1..cdde38c92 100644--- a/apps/api/src/plugins/gitea/events/task-title-changed.ts+++ b/apps/api/src/plugins/gitea/events/task-title-changed.ts@@ -68,15 +68,6 @@ export async function handleTaskTitleChanged(console.log("Skipping title sync - already synced from Gitea");return;}-- const timeSinceLastSync =- Date.now() - new Date(lastTitleSync.timestamp).getTime();- if (lastTitleSync.source === "gitea" && timeSinceLastSync < 2000) {- console.log(- `Skipping title sync - recent sync detected (${timeSinceLastSync}ms ago)`,- );- return;- }}const client = createGiteaClient(config);diff --git a/apps/api/src/plugins/gitea/webhooks/issue-closed.ts b/apps/api/src/plugins/gitea/webhooks/issue-closed.tsindex e64a41a8c..139924670 100644--- a/apps/api/src/plugins/gitea/webhooks/issue-closed.ts+++ b/apps/api/src/plugins/gitea/webhooks/issue-closed.ts@@ -103,7 +103,8 @@ export async function handleGiteaIssueClosed(const lastOutbound = existingMetadata.lastOutboundStateSyncAt;if (typeof lastOutbound === "number" &&- Number.isFinite(lastOutbound)+ Number.isFinite(lastOutbound) &&+ existingMetadata.state === "closed") {const eventMs = parseIssueUpdatedAtMs(issue);if (diff --git a/apps/api/src/plugins/gitea/webhooks/issue-edited.ts b/apps/api/src/plugins/gitea/webhooks/issue-edited.tsindex 7709dade2..2bb2ea69c 100644--- a/apps/api/src/plugins/gitea/webhooks/issue-edited.ts+++ b/apps/api/src/plugins/gitea/webhooks/issue-edited.ts@@ -97,11 +97,6 @@ export async function handleGiteaIssueEdited() {shouldUpdateTitle = false;}- const timeSinceLastSync =- Date.now() - new Date(lastTitleSync.timestamp).getTime();- if (timeSinceLastSync < 2000 && shouldUpdateTitle) {- shouldUpdateTitle = false;- }}if (shouldUpdateTitle) {@@ -127,11 +122,6 @@ export async function handleGiteaIssueEdited() {shouldUpdateDescription = false;}- const timeSinceLastSync =- Date.now() - new Date(lastDescSync.timestamp).getTime();- if (timeSinceLastSync < 2000 && shouldUpdateDescription) {- shouldUpdateDescription = false;- }}if (shouldUpdateDescription) {diff --git a/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts b/apps/api/src/plugins/gitea/webhooks/issue-reopened.tsindex 9ee96f25b..7acb40128 100644--- a/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts+++ b/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts@@ -104,7 +104,8 @@ export async function handleGiteaIssueReopened(const lastOutbound = existingMetadata.lastOutboundStateSyncAt;if (typeof lastOutbound === "number" &&- Number.isFinite(lastOutbound)+ Number.isFinite(lastOutbound) &&+ existingMetadata.state === "open") {const eventMs = parseIssueUpdatedAtMs(issue);if (diff --git a/apps/api/src/plugins/github/events/task-description-changed.ts b/apps/api/src/plugins/github/events/task-description-changed.tsindex efe559293..f8d2f1ace 100644--- a/apps/api/src/plugins/github/events/task-description-changed.ts+++ b/apps/api/src/plugins/github/events/task-description-changed.ts@@ -52,14 +52,6 @@ export async function handleTaskDescriptionChanged(}// Skip if recent sync (within 2 seconds) to prevent rapid loops- const timeSinceLastSync =- Date.now() - new Date(lastDescSync.timestamp).getTime();- if (timeSinceLastSync < 2000) {- console.log(- `Skipping description sync - recent sync detected (${timeSinceLastSync}ms ago)`,- );- return;- }}const octokit = await getVerifiedInstallationOctokit(config);diff --git a/apps/api/src/plugins/github/events/task-title-changed.ts b/apps/api/src/plugins/github/events/task-title-changed.tsindex d0e18c8df..4a1174055 100644--- a/apps/api/src/plugins/github/events/task-title-changed.ts+++ b/apps/api/src/plugins/github/events/task-title-changed.ts@@ -49,14 +49,6 @@ export async function handleTaskTitleChanged(}// Skip if recent sync (within 2 seconds) to prevent rapid loops- const timeSinceLastSync =- Date.now() - new Date(lastTitleSync.timestamp).getTime();- if (timeSinceLastSync < 2000) {- console.log(- `Skipping title sync - recent sync detected (${timeSinceLastSync}ms ago)`,- );- return;- }}const octokit = await getVerifiedInstallationOctokit(config);diff --git a/apps/api/src/plugins/github/webhooks/issue-edited.ts b/apps/api/src/plugins/github/webhooks/issue-edited.tsindex 7a91fd900..3fce6512b 100644--- a/apps/api/src/plugins/github/webhooks/issue-edited.ts+++ b/apps/api/src/plugins/github/webhooks/issue-edited.ts@@ -109,14 +109,6 @@ export async function handleIssueEdited(payload: IssueEditedPayload) {console.log("Skipping title update - already synced from Kaneo");shouldUpdateTitle = false;}- const timeSinceLastSync =- Date.now() - new Date(lastTitleSync.timestamp ?? 0).getTime();- if (timeSinceLastSync < 2000 && shouldUpdateTitle) {- console.log(- `Skipping title update - recent sync detected (${timeSinceLastSync}ms ago)`,- );- shouldUpdateTitle = false;- }}if (shouldUpdateTitle) {@@ -151,14 +143,6 @@ export async function handleIssueEdited(payload: IssueEditedPayload) {);shouldUpdateDescription = false;}- const timeSinceLastSync =- Date.now() - new Date(lastDescSync.timestamp ?? 0).getTime();- if (timeSinceLastSync < 2000 && shouldUpdateDescription) {- console.log(- `Skipping description update - recent sync detected (${timeSinceLastSync}ms ago)`,- );- shouldUpdateDescription = false;- }}if (shouldUpdateDescription) {diff --git a/tests/api/plugins/gitea/rapid-text-sync.test.ts b/tests/api/plugins/gitea/rapid-text-sync.test.tsnew file mode 100644index 000000000..443c47cfe--- /dev/null+++ b/tests/api/plugins/gitea/rapid-text-sync.test.ts@@ -0,0 +1,104 @@+import { beforeEach, describe, expect, it, vi } from "vite-plus/test";+import { handleGiteaIssueEdited } from "../../../../apps/api/src/plugins/gitea/webhooks/issue-edited";+const m = vi.hoisted(() => ({+ metadata: "",+ writes: vi.fn(),+ linkWrites: vi.fn(),+}));+vi.mock("../../../../apps/api/src/database", () => ({+ default: {+ query: {+ taskTable: {+ findFirst: async () => ({ id: "task", projectId: "project" }),+ },+ },+ update: () => ({+ set: m.writes.mockReturnValue({ where: async () => undefined }),+ }),+ },+}));+vi.mock(+ "../../../../apps/api/src/plugins/github/services/integration-task-scope",+ async (original) => ({+ ...(await original<+ typeof import("../../../../apps/api/src/plugins/github/services/integration-task-scope")+ >()),+ withIntegrationTask: async (+ _id: string,+ _scope: unknown,+ apply: (database: unknown) => Promise<unknown>,+ ) => apply((await import("../../../../apps/api/src/database")).default),+ }),+);+vi.mock(+ "../../../../apps/api/src/plugins/github/services/link-manager",+ () => ({+ findExternalLink: async () => ({+ id: "link",+ taskId: "task",+ metadata: m.metadata,+ }),+ updateExternalLink: m.linkWrites,+ }),+);+vi.mock(+ "../../../../apps/api/src/plugins/gitea/services/integration-lookup",+ () => ({+ findAllIntegrationsByGiteaRepo: async () => [+ { id: "integration", projectId: "project" },+ ],+ repoOwnerLogin: () => "owner",+ }),+);+const payload = {+ action: "edited",+ repository: {+ owner: { login: "owner" },+ name: "repo",+ html_url: "https://gitea.example/owner/repo",+ },+ issue: {+ number: 1,+ title: "Remote correction",+ body: "Remote description",+ html_url: "https://gitea.example/owner/repo/issues/1",+ },+ changes: { title: { from: "Old" }, body: { from: "Old body" } },+};+beforeEach(() => {+ vi.clearAllMocks();+ m.metadata = JSON.stringify({+ lastSync: {+ title: {+ source: "kaneo",+ value: "Local title",+ timestamp: new Date().toISOString(),+ },+ description: {+ source: "kaneo",+ value: "Local description",+ timestamp: new Date().toISOString(),+ },+ },+ });+});+describe("rapid gitea text edits", () => {+ it("applies a different title and description immediately after an outbound sync", async () => {+ await handleGiteaIssueEdited(payload);+ expect(m.writes).toHaveBeenCalledWith({+ title: "Remote correction",+ description: "Remote description",+ });+ });+ it("still ignores exact title and description echoes", async () => {+ await handleGiteaIssueEdited({+ ...payload,+ issue: {+ ...payload.issue,+ title: "Local title",+ body: "Local description",+ },+ });+ expect(m.writes).not.toHaveBeenCalled();+ });+});diff --git a/tests/api/plugins/github/rapid-text-sync.test.ts b/tests/api/plugins/github/rapid-text-sync.test.tsnew file mode 100644index 000000000..6c1ea2ef5--- /dev/null+++ b/tests/api/plugins/github/rapid-text-sync.test.ts@@ -0,0 +1,116 @@+import { beforeEach, describe, expect, it, vi } from "vite-plus/test";++const m = vi.hoisted(() => ({+ links: vi.fn(),+ update: vi.fn(),+ save: vi.fn(),+}));+vi.mock(+ "../../../../apps/api/src/plugins/github/services/link-manager",+ () => ({ findExternalLinksByTask: m.links, updateExternalLink: m.save }),+);+vi.mock("../../../../apps/api/src/plugins/github/utils/github-app", () => ({+ getGithubApp: () => ({}),+ getVerifiedInstallationOctokit: async () => ({+ rest: { issues: { update: m.update } },+ }),+}));+const { handleTaskTitleChanged } =+ await import("../../../../apps/api/src/plugins/github/events/task-title-changed");+const { handleTaskDescriptionChanged } =+ await import("../../../../apps/api/src/plugins/github/events/task-description-changed");+const context = {+ integrationId: "integration",+ projectId: "project",+ config: {+ repositoryOwner: "owner",+ repositoryName: "repo",+ installationId: 1,+ repositoryId: 2,+ verifiedGithubAccountId: "3",+ verifiedByUserId: "user",+ },+};+beforeEach(() => vi.clearAllMocks());+function link(field: string, source: string, value: string) {+ return {+ id: "link",+ integrationId: "integration",+ taskId: "task",+ resourceType: "issue",+ externalId: "1",+ metadata: JSON.stringify({+ lastSync: {+ [field]: { source, value, timestamp: new Date().toISOString() },+ },+ }),+ };+}+describe("rapid github text edits", () => {+ it("sends a second local title even immediately after the first sync", async () => {+ m.links.mockResolvedValue([link("title", "kaneo", "First title")]);+ await handleTaskTitleChanged(+ {+ taskId: "task",+ projectId: "project",+ userId: "user",+ oldTitle: "First title",+ newTitle: "Second title",+ },+ context,+ );+ expect(m.update).toHaveBeenCalledWith(+ expect.objectContaining({ title: "Second title" }),+ );+ });+ it("sends a different title immediately after an incoming github title", async () => {+ m.links.mockResolvedValue([link("title", "github", "Remote title")]);+ await handleTaskTitleChanged(+ {+ taskId: "task",+ projectId: "project",+ userId: "user",+ oldTitle: "Remote title",+ newTitle: "Local correction",+ },+ context,+ );+ expect(m.update).toHaveBeenCalledWith(+ expect.objectContaining({ title: "Local correction" }),+ );+ });+ it("keeps suppressing an exact incoming echo", async () => {+ m.links.mockResolvedValue([link("title", "github", "Remote title")]);+ await handleTaskTitleChanged(+ {+ taskId: "task",+ projectId: "project",+ userId: "user",+ oldTitle: "Old",+ newTitle: "Remote title",+ },+ context,+ );+ expect(m.update).not.toHaveBeenCalled();+ });+ it("sends a second local description immediately after the first sync", async () => {+ m.links.mockResolvedValue([+ link("description", "kaneo", "First description"),+ ]);+ await handleTaskDescriptionChanged(+ {+ taskId: "task",+ projectId: "project",+ userId: "user",+ oldDescription: "First description",+ newDescription: "Second description",+ },+ context,+ );+ expect(m.update).toHaveBeenCalledWith(+ expect.objectContaining({+ body: expect.stringContaining("Second description"),+ }),+ );+ });+});