fix: narrow document conflicts and finish deferred fixture waits

This commit is contained in:
Michel Tomas 2026-09-13 10:22:08 +02:00
parent 1ff19d26b7
commit fb1a6439c3
No known key found for this signature in database
GPG Key ID: 0878846631FFD1E0
3 changed files with 36 additions and 5 deletions

View File

@ -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 })

View File

@ -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();

View File

@ -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;
}