From 17fa6fe0fe2c850f6cd22a270b3c032f6f02f371 Mon Sep 17 00:00:00 2001 From: Dotta Date: Wed, 3 Jun 2026 17:33:47 +0000 Subject: [PATCH] Add deleted comment regression coverage --- .../document-annotations-service.test.ts | 50 +++++++++++++++++++ ui/src/components/IssueChatThread.test.tsx | 44 ++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/server/src/__tests__/document-annotations-service.test.ts b/server/src/__tests__/document-annotations-service.test.ts index ff6a23d7..ff616b65 100644 --- a/server/src/__tests__/document-annotations-service.test.ts +++ b/server/src/__tests__/document-annotations-service.test.ts @@ -9,6 +9,7 @@ import { documentAnnotationThreads, documentRevisions, documents, + issueComments, issueDocuments, issues, } from "@paperclipai/db"; @@ -58,6 +59,7 @@ describeEmbeddedPostgres("documentAnnotationService", () => { await db.delete(documentRevisions); await db.delete(issueDocuments); await db.delete(documents); + await db.delete(issueComments); await db.delete(issues); await db.delete(companies); }); @@ -180,4 +182,52 @@ describeEmbeddedPostgres("documentAnnotationService", () => { const threads = await db.select().from(documentAnnotationThreads); expect(threads).toHaveLength(0); }); + + it("removes linked annotation comments and resolves empty threads when an issue comment is deleted", async () => { + const { companyId, issueId, document } = await createIssueWithDocument(); + const [issueComment] = await db + .insert(issueComments) + .values({ + companyId, + issueId, + authorType: "user", + authorUserId: "board-user", + body: "Delete this linked comment", + }) + .returning(); + + const thread = await annotations.createThread( + issueId, + "plan", + { + baseRevisionId: document.latestRevisionId!, + baseRevisionNumber: document.latestRevisionNumber, + selector: { + quote: { exact: "selected text", prefix: "Alpha ", suffix: " omega" }, + position: { normalizedStart: 6, normalizedEnd: 19, markdownStart: 6, markdownEnd: 19 }, + }, + body: "Linked annotation body", + issueCommentId: issueComment.id, + }, + { actorType: "user", actorId: "board-user", userId: "board-user" }, + ); + + const cleanup = await annotations.cleanupForIssueCommentDeletion( + issueId, + issueComment.id, + { actorType: "user", actorId: "board-user", userId: "board-user" }, + ); + + expect(cleanup.deletedCommentIds).toEqual([thread.comments[0]!.id]); + expect(cleanup.resolvedThreadIds).toEqual([thread.id]); + await expect( + db.select().from(documentAnnotationComments).where(eq(documentAnnotationComments.id, thread.comments[0]!.id)), + ).resolves.toHaveLength(0); + const [updatedThread] = await db + .select() + .from(documentAnnotationThreads) + .where(eq(documentAnnotationThreads.id, thread.id)); + expect(updatedThread?.status).toBe("resolved"); + expect(updatedThread?.resolvedByUserId).toBe("board-user"); + }); }); diff --git a/ui/src/components/IssueChatThread.test.tsx b/ui/src/components/IssueChatThread.test.tsx index 37a114c8..6e1172e5 100644 --- a/ui/src/components/IssueChatThread.test.tsx +++ b/ui/src/components/IssueChatThread.test.tsx @@ -1370,6 +1370,50 @@ describe("IssueChatThread", () => { }); }); + it("clears a deleted comment deep-link hash instead of highlighting it", () => { + const root = createRoot(container); + const replaceStateSpy = vi.spyOn(window.history, "replaceState").mockImplementation(() => {}); + + act(() => { + root.render( + + {}} + showComposer={false} + enableLiveTranscriptPolling={false} + /> + , + ); + }); + + expect(replaceStateSpy).toHaveBeenCalledWith(null, "", "/issues/PAP-1"); + + replaceStateSpy.mockRestore(); + act(() => { + root.unmount(); + }); + }); + it("shows explicit follow-up badges and event copy", () => { const root = createRoot(container);