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(integrations): keep sync state and mutation effects current

Tinb9e5b4a263d7
diff --git a/apps/api/src/integration-sync/controllers/resume-sync.ts b/apps/api/src/integration-sync/controllers/resume-sync.ts
index 5ed89eff2..7c94f5165 100644
--- a/apps/api/src/integration-sync/controllers/resume-sync.ts
+++ b/apps/api/src/integration-sync/controllers/resume-sync.ts
@@ -14,7 +14,11 @@ import { formatIssueBody } from "../../plugins/github/utils/format";
import { reviewSyncResume } from "./review-resume";
import { lockResumeScope } from "./lock-resume-scope";
import { withSyncLease } from "../../plugins/sync/lease";
-import type { TaskStatusChangedEvent } from "../../plugins/types";
+import {
+ publishTaskMutation,
+ recordTaskMutation,
+ type TaskBefore,
+} from "../../task/controllers/task-mutation-effects";
export async function resumeSync(
projectId: string,
@@ -36,8 +40,8 @@ async function resumeWithLease(
source: "kaneo" | "provider",
) {
let providerWritten = false;
- let statusChange:
- | (TaskStatusChangedEvent & { assigneeId: string | null })
+ let adoption:
+ | { before: TaskBefore; after: TaskBefore; integrationId: string }
| undefined;
let taskId: string | undefined;
try {
@@ -78,7 +82,7 @@ async function resumeWithLease(
throw new HTTPException(409, {
message: "A matching open or completed column is required",
});
- await tx
+ const [after] = await tx
.update(taskTable)
.set({
title: review.remote.title,
@@ -86,18 +90,14 @@ async function resumeWithLease(
status: target.slug,
columnId: target.id,
})
- .where(eq(taskTable.id, task.id));
- if (task.status !== target.slug)
- statusChange = {
- sourceIntegrationId: review.integration.id,
- taskId: task.id,
- projectId,
- userId: null,
- assigneeId: task.userId,
- oldStatus: task.status,
- newStatus: target.slug,
- title: review.remote.title,
- };
+ .where(eq(taskTable.id, task.id))
+ .returning();
+ await recordTaskMutation(tx, task, after!);
+ adoption = {
+ before: task,
+ after: after!,
+ integrationId: review.integration.id,
+ };
}
const job = parseDeferredIssueEdit(
JSON.parse(link.metadata ?? "{}").deferredIssueEdit,
@@ -178,10 +178,10 @@ async function resumeWithLease(
}
throw error;
}
- if (statusChange)
- await publishEvent("task.status_changed", {
- ...statusChange,
- type: "status_changed",
+ if (adoption)
+ await publishTaskMutation(adoption.before, adoption.after, undefined, {
+ fields: ["title", "description", "status"],
+ sourceIntegrationId: adoption.integrationId,
});
await publishEvent("task.updated", { projectId, taskId });
await publishEvent("project.updated", { projectId });
diff --git a/apps/api/src/plugins/gitea/events/task-created.ts b/apps/api/src/plugins/gitea/events/task-created.ts
index 32c697185..ade9e8778 100644
--- a/apps/api/src/plugins/gitea/events/task-created.ts
+++ b/apps/api/src/plugins/gitea/events/task-created.ts
@@ -1,3 +1,4 @@
+import { canSyncTask } from "../../sync/eligibility";
import { taskIssueLabels } from "../../sync/issue-labels";
import { withTaskSyncCreation } from "../../sync/create-task-issue";
import {
@@ -35,6 +36,16 @@ async function createTaskIssue(
try {
const client = createGiteaClient(config);
+ if (
+ !(await canSyncTask(
+ event.taskId,
+ context.integrationId,
+ undefined,
+ JSON.stringify(context.config),
+ ))
+ )
+ return;
+
const createdIssue = await client.createIssue(
repositoryOwner,
repositoryName,
@@ -58,6 +69,20 @@ async function createTaskIssue(
},
});
+ if (
+ !(await canSyncTask(
+ event.taskId,
+ context.integrationId,
+ undefined,
+ JSON.stringify(context.config),
+ ))
+ ) {
+ await updateExternalLink(createdLink.id, {
+ metadata: { syncFilterPaused: true },
+ });
+ return;
+ }
+
if (
await isTaskInFinalState({
projectId: event.projectId,
diff --git a/apps/api/src/plugins/github/events/task-created.ts b/apps/api/src/plugins/github/events/task-created.ts
index 3486ee3a2..b0f989b22 100644
--- a/apps/api/src/plugins/github/events/task-created.ts
+++ b/apps/api/src/plugins/github/events/task-created.ts
@@ -1,3 +1,4 @@
+import { canSyncTask } from "../../sync/eligibility";
import { taskIssueLabels } from "../../sync/issue-labels";
import { withTaskSyncCreation } from "../../sync/create-task-issue";
import { eq } from "drizzle-orm";
@@ -44,6 +45,16 @@ async function createTaskIssue(
try {
const octokit = await getVerifiedInstallationOctokit(config);
+ if (
+ !(await canSyncTask(
+ event.taskId,
+ context.integrationId,
+ undefined,
+ JSON.stringify(context.config),
+ ))
+ )
+ return;
+
const createdIssue = await octokit.rest.issues.create({
owner: repositoryOwner,
repo: repositoryName,
@@ -64,6 +75,20 @@ async function createTaskIssue(
},
});
+ if (
+ !(await canSyncTask(
+ event.taskId,
+ context.integrationId,
+ undefined,
+ JSON.stringify(context.config),
+ ))
+ ) {
+ await updateExternalLink(createdLink.id, {
+ metadata: { syncFilterPaused: true },
+ });
+ return;
+ }
+
if (
await isTaskInFinalState({
projectId: event.projectId,
diff --git a/apps/api/src/plugins/gitlab/events/task-created.ts b/apps/api/src/plugins/gitlab/events/task-created.ts
index 2898afb0a..6474e6aa5 100644
--- a/apps/api/src/plugins/gitlab/events/task-created.ts
+++ b/apps/api/src/plugins/gitlab/events/task-created.ts
@@ -1,3 +1,4 @@
+import { canSyncTask } from "../../sync/eligibility";
import { taskIssueLabels } from "../../sync/issue-labels";
import { withTaskSyncCreation } from "../../sync/create-task-issue";
import {
@@ -33,6 +34,16 @@ async function createTaskIssue(
try {
const client = createGitlabClient(config);
+ if (
+ !(await canSyncTask(
+ event.taskId,
+ context.integrationId,
+ undefined,
+ JSON.stringify(context.config),
+ ))
+ )
+ return;
+
const createdIssue = await client.createIssue(config.projectPath, {
title: formatIssueTitle(event.title),
description: formatIssueBody(event.description, event.taskId),
@@ -52,6 +63,20 @@ async function createTaskIssue(
},
});
+ if (
+ !(await canSyncTask(
+ event.taskId,
+ context.integrationId,
+ undefined,
+ JSON.stringify(context.config),
+ ))
+ ) {
+ await updateExternalLink(createdLink.id, {
+ metadata: { syncFilterPaused: true },
+ });
+ return;
+ }
+
if (
await isTaskInFinalState({
projectId: event.projectId,
diff --git a/apps/api/src/plugins/registry.ts b/apps/api/src/plugins/registry.ts
index 1a139f529..8aef030ac 100644
--- a/apps/api/src/plugins/registry.ts
+++ b/apps/api/src/plugins/registry.ts
@@ -95,37 +95,33 @@ export function initializeEventSubscriptions(): void {
});
});
- subscribeToEvent<{
- taskId: string;
- userId: string | null;
- oldTitle: string;
- newTitle: string;
- projectId: string;
- }>("task.title_changed", async (data) => {
- await broadcastTaskTitleChanged({
- taskId: data.taskId,
- projectId: data.projectId,
- userId: data.userId,
- oldTitle: data.oldTitle,
- newTitle: data.newTitle,
- });
- });
+ subscribeToEvent<TaskTitleChangedEvent>(
+ "task.title_changed",
+ async (data) => {
+ await broadcastTaskTitleChanged({
+ sourceIntegrationId: data.sourceIntegrationId,
+ taskId: data.taskId,
+ projectId: data.projectId,
+ userId: data.userId,
+ oldTitle: data.oldTitle,
+ newTitle: data.newTitle,
+ });
+ },
+ );
- subscribeToEvent<{
- taskId: string;
- userId: string | null;
- oldDescription: string | null;
- newDescription: string | null;
- projectId: string;
- }>("task.description_changed", async (data) => {
- await broadcastTaskDescriptionChanged({
- taskId: data.taskId,
- projectId: data.projectId,
- userId: data.userId,
- oldDescription: data.oldDescription,
- newDescription: data.newDescription,
- });
- });
+ subscribeToEvent<TaskDescriptionChangedEvent>(
+ "task.description_changed",
+ async (data) => {
+ await broadcastTaskDescriptionChanged({
+ sourceIntegrationId: data.sourceIntegrationId,
+ taskId: data.taskId,
+ projectId: data.projectId,
+ userId: data.userId,
+ oldDescription: data.oldDescription,
+ newDescription: data.newDescription,
+ });
+ },
+ );
subscribeToEvent<{
taskId: string;
@@ -319,6 +315,7 @@ export async function broadcastTaskStatusChanged(
const integrations = await getActiveIntegrations(event.projectId);
for (const integration of integrations) {
+ if (integration.id === event.sourceIntegrationId) continue;
const plugin = getPlugin(integration.type);
if (!plugin?.onTaskStatusChanged) continue;
@@ -363,6 +360,7 @@ export async function broadcastTaskTitleChanged(
const integrations = await getActiveIntegrations(event.projectId);
for (const integration of integrations) {
+ if (integration.id === event.sourceIntegrationId) continue;
const plugin = getPlugin(integration.type);
if (!plugin?.onTaskTitleChanged) continue;
@@ -385,6 +383,7 @@ export async function broadcastTaskDescriptionChanged(
const integrations = await getActiveIntegrations(event.projectId);
for (const integration of integrations) {
+ if (integration.id === event.sourceIntegrationId) continue;
const plugin = getPlugin(integration.type);
if (!plugin?.onTaskDescriptionChanged) continue;
diff --git a/apps/api/src/plugins/types.ts b/apps/api/src/plugins/types.ts
index 1f9269597..db048e9f8 100644
--- a/apps/api/src/plugins/types.ts
+++ b/apps/api/src/plugins/types.ts
@@ -35,6 +35,7 @@ export type TaskPriorityChangedEvent = {
};
export type TaskTitleChangedEvent = {
+ sourceIntegrationId?: string;
taskId: string;
projectId: string;
userId: string | null;
@@ -43,6 +44,7 @@ export type TaskTitleChangedEvent = {
};
export type TaskDescriptionChangedEvent = {
+ sourceIntegrationId?: string;
taskId: string;
projectId: string;
userId: string | null;
diff --git a/apps/api/src/task/controllers/task-mutation-effects.ts b/apps/api/src/task/controllers/task-mutation-effects.ts
index 3d2241d29..2a21fcc27 100644
--- a/apps/api/src/task/controllers/task-mutation-effects.ts
+++ b/apps/api/src/task/controllers/task-mutation-effects.ts
@@ -59,6 +59,7 @@ export async function publishTaskMutation(
skipRelationRefresh?: boolean;
fields?: Array<keyof Changes>;
assigneeName?: string | null;
+ sourceIntegrationId?: string;
} = {},
) {
const changed = (field: keyof Changes) =>
@@ -69,6 +70,9 @@ export async function publishTaskMutation(
projectId: after.projectId,
userId,
title: after.title,
+ ...(options.sourceIntegrationId
+ ? { sourceIntegrationId: options.sourceIntegrationId }
+ : {}),
};
if (changed("status")) {
await publishEvent("task.status_changed", {
diff --git a/apps/docs/core/integrations/index.mdx b/apps/docs/core/integrations/index.mdx
index e9b8546e1..e6212882f 100644
--- a/apps/docs/core/integrations/index.mdx
+++ b/apps/docs/core/integrations/index.mdx
@@ -30,6 +30,8 @@ Enable **Advanced settings** in **Account → Preferences** or **Workspace → G
When a linked task loses its qualifying labels, synchronization pauses in both directions. Both records and their link remain. Reapplying the label does not overwrite either side: choose **Review and resume**, compare the current title, description, and open/closed state, then keep the Kaneo or repository values. Historical comments are not replayed. Missing or deleted workspace labels keep the filter closed until you repair the rule.
+An issue creation request already sent to a repository may finish after its task stops matching. Kaneo keeps the returned issue link paused and stops further updates. Local edits remain available while the repository responds.
+
Newly matching tasks without an issue link are exported in the background when rules or task labels change. Use **Export matching tasks** to retry tasks that still have no issue link after a failed export. An inactive integration does not export or resume tasks. Existing installations retain unrestricted sync until a rule is saved.
## Team notifications
diff --git a/apps/web/src/components/project/sync-rules/label-rule-editor.tsx b/apps/web/src/components/project/sync-rules/label-rule-editor.tsx
index 789178554..545d2f239 100644
--- a/apps/web/src/components/project/sync-rules/label-rule-editor.tsx
+++ b/apps/web/src/components/project/sync-rules/label-rule-editor.tsx
@@ -125,6 +125,10 @@ export function LabelRuleEditor({
>
<Checkbox
checked={rule.labels.includes(label.id)}
+ disabled={
+ rule.labels.length >= 50 &&
+ !rule.labels.includes(label.id)
+ }
onCheckedChange={(checked) =>
onChange({
...rule,
diff --git a/apps/web/src/components/project/sync-rules/sync-rules-section.tsx b/apps/web/src/components/project/sync-rules/sync-rules-section.tsx
index 4873d1f96..1f0d18108 100644
--- a/apps/web/src/components/project/sync-rules/sync-rules-section.tsx
+++ b/apps/web/src/components/project/sync-rules/sync-rules-section.tsx
@@ -27,7 +27,7 @@ export function SyncRulesSection({ projectId, provider }: SyncParams) {
{t("settings:syncRules.loading")}
</p>
);
- if (!data)
+ if (query.isError || !data)
return (
<div
role="alert"
diff --git a/apps/web/src/components/project/sync-rules/sync-rules.test.tsx b/apps/web/src/components/project/sync-rules/sync-rules.test.tsx
index a74ba0321..77010245e 100644
--- a/apps/web/src/components/project/sync-rules/sync-rules.test.tsx
+++ b/apps/web/src/components/project/sync-rules/sync-rules.test.tsx
@@ -98,12 +98,84 @@ function mount(node = <SyncRulesSection {...param} />) {
const client = new QueryClient({
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
});
- return render(
- <QueryClientProvider client={client}>{node}</QueryClientProvider>,
- );
+ return {
+ client,
+ ...render(
+ <QueryClientProvider client={client}>{node}</QueryClientProvider>,
+ ),
+ };
}
describe("advanced sync settings", () => {
+ it("refreshes cached issue metadata after saving rules", async () => {
+ useUserPreferencesStore.setState({ advancedSettings: true });
+ mocks.get.mockResolvedValue({ ...saved, willCreate: 1 });
+ const { client } = mount();
+ client.setQueryData(["external-links", "task-1"], [{ metadata: "{}" }]);
+ const apply = await screen.findByRole("button", {
+ name: "settings:syncRules.exportPending",
+ });
+ await waitFor(() => expect(apply).toBeEnabled());
+ fireEvent.click(apply);
+ await waitFor(() =>
+ expect(
+ client.getQueryState(["external-links", "task-1"])?.isInvalidated,
+ ).toBe(true),
+ );
+ });
+
+ it("shows a retry after a failed refresh even when rules were cached", async () => {
+ const { client } = mount();
+ await screen.findByText("settings:syncRules.anySummary");
+ mocks.get.mockRejectedValueOnce(new Error("Unavailable"));
+ await act(async () => {
+ await client.invalidateQueries({ queryKey: ["integration-sync"] });
+ });
+ expect(await screen.findByRole("alert")).toHaveTextContent(
+ "settings:syncRules.loadError",
+ );
+ expect(screen.queryByText("settings:syncRules.anySummary")).toBeNull();
+ fireEvent.click(
+ screen.getByRole("button", { name: "common:error.tryAgain" }),
+ );
+ expect(
+ await screen.findByText("settings:syncRules.anySummary"),
+ ).toBeVisible();
+ });
+
+ it("stops at 50 labels while allowing a selected label to be removed", async () => {
+ useUserPreferencesStore.setState({ advancedSettings: true });
+ const labels = Array.from({ length: 51 }, (_, i) => ({
+ id: `label-${i + 1}`,
+ name: `Label ${i + 1}`,
+ color: "#123456",
+ }));
+ mocks.get.mockResolvedValue({
+ ...saved,
+ labels,
+ rules: {
+ ...saved.rules,
+ outgoing: {
+ mode: "labels",
+ match: "any",
+ labels: labels.slice(0, 50).map((label) => label.id),
+ },
+ },
+ });
+ mount();
+ const extra = await screen.findByRole("checkbox", { name: "Label 51" });
+ expect(extra).toHaveAttribute("aria-disabled", "true");
+ fireEvent.click(extra);
+ expect(extra).not.toBeChecked();
+ const selected = screen.getByRole("checkbox", { name: "Label 1" });
+ expect(selected).not.toHaveAttribute("aria-disabled", "true");
+ fireEvent.click(selected);
+ expect(extra).not.toHaveAttribute("aria-disabled", "true");
+ fireEvent.click(extra);
+ expect(selected).toHaveAttribute("aria-disabled", "true");
+ expect(extra).toBeChecked();
+ });
+
it("offers an explicit retry for eligible tasks without an issue link", async () => {
useUserPreferencesStore.setState({ advancedSettings: true });
mocks.get.mockResolvedValue({ ...saved, willCreate: 1 });
diff --git a/apps/web/src/hooks/mutations/integration-sync/use-save-sync-rules.ts b/apps/web/src/hooks/mutations/integration-sync/use-save-sync-rules.ts
index 56da8567a..44f1b1f62 100644
--- a/apps/web/src/hooks/mutations/integration-sync/use-save-sync-rules.ts
+++ b/apps/web/src/hooks/mutations/integration-sync/use-save-sync-rules.ts
@@ -19,6 +19,7 @@ export function useSaveSyncRules(param: SyncParams) {
await client.invalidateQueries({
queryKey: ["integration-sync-preview", param.projectId],
});
+ await client.invalidateQueries({ queryKey: ["external-links"] });
},
});
}
diff --git a/apps/web/src/hooks/use-project-websocket-cache.test.tsx b/apps/web/src/hooks/use-project-websocket-cache.test.tsx
index 56618dd97..aaf3578ad 100644
--- a/apps/web/src/hooks/use-project-websocket-cache.test.tsx
+++ b/apps/web/src/hooks/use-project-websocket-cache.test.tsx
@@ -477,11 +477,14 @@ it("drains queued detail events after retries fall back to polling", async () =>
it("refreshes workspace label filters when a remote project event changes labels", async () => {
renderHook(() => useProjectWebSocket("p"));
Socket.current.message("PROJECT_UPDATED", {});
- await vi.waitFor(() =>
+ await vi.waitFor(() => {
expect(mocks.client.invalidateQueries).toHaveBeenCalledWith({
queryKey: ["labels"],
- }),
- );
+ });
+ expect(mocks.client.invalidateQueries).toHaveBeenCalledWith({
+ queryKey: ["external-links"],
+ });
+ });
});
it.each([
diff --git a/apps/web/src/hooks/use-project-websocket.ts b/apps/web/src/hooks/use-project-websocket.ts
index bbeec1291..503918ec0 100644
--- a/apps/web/src/hooks/use-project-websocket.ts
+++ b/apps/web/src/hooks/use-project-websocket.ts
@@ -90,6 +90,7 @@ export function useProjectWebSocket(projectId: string) {
if (message.type === "PROJECT_UPDATED") {
queryClient.invalidateQueries({ queryKey: ["projects"] });
queryClient.invalidateQueries({ queryKey: ["labels"] });
+ queryClient.invalidateQueries({ queryKey: ["external-links"] });
return;
}
diff --git a/tests/api-integration/integration-sync-providers.test.ts b/tests/api-integration/integration-sync-providers.test.ts
index 56a0c8c68..d89502c5e 100644
--- a/tests/api-integration/integration-sync-providers.test.ts
+++ b/tests/api-integration/integration-sync-providers.test.ts
@@ -248,6 +248,77 @@ describe.each(["github", "gitea", "gitlab"] as const)(
expect(JSON.parse(link!.metadata!)).toMatchObject({ state: "closed" });
});
+ it.each(["labels", "rules", "deactivation"])(
+ "pauses a dispatched creation after %s change without follow-up writes",
+ async (change) => {
+ const f = await setup(type);
+ await f.assign();
+ await db
+ .update(schema.taskTable)
+ .set({ status: f.columns.done.slug, columnId: f.columns.done.id })
+ .where(eq(schema.taskTable.id, f.task.id));
+ let release!: () => void;
+ const gate = new Promise<void>((resolve) => {
+ release = resolve;
+ });
+ create.mockImplementationOnce(async () => {
+ await gate;
+ const issue = {
+ number: 12,
+ iid: 12,
+ title: "Export task",
+ state: type === "gitlab" ? "opened" : "open",
+ html_url: "https://git.example/issues/12",
+ web_url: "https://git.example/issues/12",
+ };
+ return type === "github" ? { data: issue } : issue;
+ });
+ const exportTask = reconcileTaskSync(f.project.id, f.task.id);
+ try {
+ await vi.waitFor(() => expect(create).toHaveBeenCalledOnce());
+ if (change === "labels")
+ await db
+ .delete(schema.labelTable)
+ .where(eq(schema.labelTable.taskId, f.task.id));
+ else if (change === "deactivation")
+ await db
+ .update(schema.integrationTable)
+ .set({ isActive: false })
+ .where(eq(schema.integrationTable.id, f.integration.id));
+ else
+ await db
+ .update(schema.integrationTable)
+ .set({
+ config: JSON.stringify({
+ ...f.config,
+ syncRules: {
+ ...f.config.syncRules,
+ outgoing: {
+ mode: "labels",
+ match: "any",
+ labels: ["missing-label"],
+ },
+ },
+ }),
+ })
+ .where(eq(schema.integrationTable.id, f.integration.id));
+ } finally {
+ release();
+ await exportTask;
+ }
+ const link = await db.query.externalLinkTable.findFirst({
+ where: eq(schema.externalLinkTable.taskId, f.task.id),
+ });
+ expect(JSON.parse(link!.metadata!)).toMatchObject({
+ syncFilterPaused: true,
+ });
+ expect(mocks.update).not.toHaveBeenCalled();
+ expect(mocks.labels).not.toHaveBeenCalled();
+ expect(mocks.comment).not.toHaveBeenCalled();
+ expect(create).toHaveBeenCalledOnce();
+ },
+ );
+
it("imports a closed issue gaining a label into a completed column", async () => {
const f = await setup(type);
if (type === "github") {
diff --git a/tests/api-integration/integration-sync-rules.test.ts b/tests/api-integration/integration-sync-rules.test.ts
index 87a13dfd7..3ec8d842d 100644
--- a/tests/api-integration/integration-sync-rules.test.ts
+++ b/tests/api-integration/integration-sync-rules.test.ts
@@ -1,6 +1,7 @@
import { and, eq, sql } from "drizzle-orm";
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
import * as events from "../../apps/api/src/events";
+import * as assets from "../../apps/api/src/storage/cleanup-assets";
import db, { schema } from "../../apps/api/src/database";
import { createApp } from "../../apps/api/src/index";
import { getSyncIntegration } from "../../apps/api/src/integration-sync/controllers/get-integration";
@@ -566,6 +567,31 @@ describe("reviewed sync resume", () => {
columnId: f.columns.done.id,
});
expect(provider.write).not.toHaveBeenCalled();
+ expect(
+ await db.query.activityTable.findFirst({
+ where: and(
+ eq(schema.activityTable.taskId, f.task.id),
+ eq(schema.activityTable.type, "title_changed"),
+ ),
+ }),
+ ).toMatchObject({
+ eventData: { oldTitle: "Kaneo title", newTitle: "Repository title" },
+ });
+ expect(publish).toHaveBeenCalledWith(
+ "task.title_changed",
+ expect.objectContaining({
+ sourceIntegrationId: f.integration.id,
+ oldTitle: "Kaneo title",
+ newTitle: "Repository title",
+ }),
+ );
+ expect(publish).toHaveBeenCalledWith(
+ "task.description_changed",
+ expect.objectContaining({
+ sourceIntegrationId: f.integration.id,
+ newDescription: "Repository body",
+ }),
+ );
expect(publish).toHaveBeenCalledWith(
"task.status_changed",
expect.objectContaining({
@@ -595,6 +621,40 @@ describe("reviewed sync resume", () => {
});
expect(await canSyncTask(f.task.id, f.integration.id)).toBe(true);
});
+ it("runs mention notifications and asset cleanup when adopting repository text", async () => {
+ vi.spyOn(events, "publishEvent").mockResolvedValue(undefined);
+ const cleanup = vi
+ .spyOn(assets, "deleteOrphanedAssets")
+ .mockResolvedValue(undefined);
+ const f = await paused();
+ provider.read.mockResolvedValue({
+ title: "Repository title",
+ description: `<kaneo-mention id="${f.user.id}">Team member</kaneo-mention>`,
+ state: "closed",
+ updatedAt: "2026-01-01T00:00:00Z",
+ });
+ const review = await reviewSyncResume(f.project.id, "gitea", f.link.id);
+ await resumeSync(
+ f.project.id,
+ "gitea",
+ f.link.id,
+ review.token,
+ "provider",
+ );
+ expect(cleanup).toHaveBeenCalledWith(
+ "Kaneo body",
+ review.remote.description,
+ { taskId: f.task.id },
+ );
+ expect(
+ await db.query.notificationTable.findFirst({
+ where: and(
+ eq(schema.notificationTable.resourceId, f.task.id),
+ eq(schema.notificationTable.type, "task_mention"),
+ ),
+ }),
+ ).toMatchObject({ userId: f.user.id });
+ });
it("requires a fresh comparison after either side changes", async () => {
const f = await paused();
const review = await reviewSyncResume(f.project.id, "gitea", f.link.id);