From 6fa917ce9bc4901773c1d3dca2f43ba3bcf90e9f Mon Sep 17 00:00:00 2001 From: Dotta Date: Tue, 21 Apr 2026 15:30:10 -0500 Subject: [PATCH] test(memory-jobs): stabilize async dispatch coverage --- .../src/__tests__/heartbeat-process-recovery.test.ts | 5 ++++- server/src/__tests__/memory-job-dispatcher.test.ts | 12 ++++++++++-- server/src/__tests__/memory-job-routes.test.ts | 2 +- .../__tests__/server-startup-feedback-export.test.ts | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/server/src/__tests__/heartbeat-process-recovery.test.ts b/server/src/__tests__/heartbeat-process-recovery.test.ts index 4f68d803d0d..e38703dfd79 100644 --- a/server/src/__tests__/heartbeat-process-recovery.test.ts +++ b/server/src/__tests__/heartbeat-process-recovery.test.ts @@ -666,7 +666,10 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => { expect(blockedIssue?.executionRunId).toBeNull(); expect(blockedIssue?.checkoutRunId).toBe(continuationRun?.id ?? null); - const comments = await db.select().from(issueComments).where(eq(issueComments.issueId, issueId)); + const comments = await waitForValue(async () => { + const rows = await db.select().from(issueComments).where(eq(issueComments.issueId, issueId)); + return rows.length > 0 ? rows : null; + }); expect(comments).toHaveLength(1); expect(comments[0]?.body).toContain("retried continuation"); }); diff --git a/server/src/__tests__/memory-job-dispatcher.test.ts b/server/src/__tests__/memory-job-dispatcher.test.ts index 47f33512a13..dceb811f7a8 100644 --- a/server/src/__tests__/memory-job-dispatcher.test.ts +++ b/server/src/__tests__/memory-job-dispatcher.test.ts @@ -36,10 +36,11 @@ async function waitForJobStatus( jobId: string, status: string, now: Date, + predicate: (detail: Awaited["getDetail"]>>) => boolean = () => true, ) { for (let attempt = 0; attempt < 20; attempt += 1) { const detail = await store.getDetail(companyId, jobId, { now }); - if (detail?.status === status) { + if (detail?.status === status && predicate(detail)) { return detail; } await new Promise((resolve) => setTimeout(resolve, 10)); @@ -149,7 +150,14 @@ describeEmbeddedPostgres("memory job dispatcher", () => { await dispatcher.tick(); - const runningDetail = await waitForJobStatus(store, companyId, queued.id, "running", currentTime); + const runningDetail = await waitForJobStatus( + store, + companyId, + queued.id, + "running", + currentTime, + (detail) => detail?.providerJobId === "provider-job-async", + ); expect(runningDetail).toMatchObject({ id: queued.id, status: "running", diff --git a/server/src/__tests__/memory-job-routes.test.ts b/server/src/__tests__/memory-job-routes.test.ts index 26364f2d7bc..2d30730aae2 100644 --- a/server/src/__tests__/memory-job-routes.test.ts +++ b/server/src/__tests__/memory-job-routes.test.ts @@ -156,7 +156,7 @@ describeEmbeddedPostgres("memory job routes", () => { ); expect(res.status).toBe(400); - expect(res.body.error).toContain("effectiveState and status cannot be used together"); + expect(JSON.stringify(res.body.details)).toContain("effectiveState and status cannot be used together"); }); it("returns job detail scoped to the requested company", async () => { diff --git a/server/src/__tests__/server-startup-feedback-export.test.ts b/server/src/__tests__/server-startup-feedback-export.test.ts index 806679105c4..fb0812a4ebf 100644 --- a/server/src/__tests__/server-startup-feedback-export.test.ts +++ b/server/src/__tests__/server-startup-feedback-export.test.ts @@ -214,7 +214,7 @@ describe("startServer feedback export wiring", () => { storageService: { id: "storage-service" }, serverPort: 3210, }); - }); + }, 10_000); }); describe("startServer PAPERCLIP_API_URL handling", () => {