diff --git a/server/src/__tests__/chat-channels.integration.test.ts b/server/src/__tests__/chat-channels.integration.test.ts index e877cbe2e8..c94734cf22 100644 --- a/server/src/__tests__/chat-channels.integration.test.ts +++ b/server/src/__tests__/chat-channels.integration.test.ts @@ -59573,7 +59573,7 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => { expect( deliveries.every((delivery) => delivery.state === "processed"), ).toBe(true); - }); + }, { timeout: 5_000 }); const [conversation] = await db .select() @@ -59601,7 +59601,7 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => { ).resolves.toMatchObject({ ok: true }); expect(deferred).toHaveLength(1); await drainDeferred(); - await vi.waitFor(() => expect(deferred).toHaveLength(1)); + await vi.waitFor(() => expect(deferred).toHaveLength(1), { timeout: 5_000 }); await drainDeferred(); await vi.waitFor(async () => { await expect( @@ -59627,7 +59627,7 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => { state: "filtered", }, ]); - }); + }, { timeout: 5_000 }); await expect( db .select({ body: issueComments.body }) diff --git a/server/src/__tests__/documents-service.test.ts b/server/src/__tests__/documents-service.test.ts index 92dd1f3217..1115d0251f 100644 --- a/server/src/__tests__/documents-service.test.ts +++ b/server/src/__tests__/documents-service.test.ts @@ -1,5 +1,5 @@ import { randomUUID } from "node:crypto"; -import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest"; +import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest"; import { companies, createDb, @@ -86,6 +86,37 @@ describeEmbeddedPostgres("documentService system issue documents", () => { return { issueId }; } + it.each([ + "issue_documents_company_issue_key_uq", + "issue_documents_document_uq", + "document_revisions_document_revision_uq", + ])("only translates document-key conflicts for %s", async (constraintName) => { + const { issueId } = await createIssueWithDocuments(); + const failure = new Error("Failed query", { + cause: { code: "23505", constraint_name: constraintName }, + }); + const transaction = vi.spyOn(db, "transaction").mockRejectedValueOnce(failure); + try { + const result = svc.upsertIssueDocument({ + issueId, + key: "plan", + format: "markdown", + body: "Updated plan", + }); + if (constraintName === "issue_documents_company_issue_key_uq") { + await expect(result).rejects.toMatchObject({ + status: 409, + message: "Document key already exists on this issue", + details: { key: "plan" }, + }); + } else { + await expect(result).rejects.toBe(failure); + } + } finally { + transaction.mockRestore(); + } + }); + it("filters continuation summaries from default document lists and issue payload summaries", async () => { const { issueId } = await createIssueWithDocuments(); diff --git a/server/src/services/documents.ts b/server/src/services/documents.ts index 35cc8e3a7e..1ee5dcc2f2 100644 --- a/server/src/services/documents.ts +++ b/server/src/services/documents.ts @@ -499,7 +499,7 @@ export function documentService(db: Db) { }; }); } catch (error) { - if (isUniqueViolation(error)) { + if (isUniqueViolation(error, "issue_documents_company_issue_key_uq")) { if (input.lockedDocumentStrategy === "create_new_document" && attempt < maxAttempts - 1) { continue; }