From 8daa66573d3237ad428a5f7cfbb203686fef2992 Mon Sep 17 00:00:00 2001 From: paula-alves Date: Thu, 19 Nov 2026 13:28:47 +0000 Subject: [PATCH] test(sports): cover P1017 from person.findUnique in linkSquadPerson (BIT-32481) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error loop reported P1017 ("Server has closed the connection.") from linkSquadPerson → person.findUnique (the organizationId_sportsPlayerId lookup). The fix is already in main: retryOnConnectionClosed (BIT-32460) retries once on a fresh client, and isPrismaConnectionClosed (BIT-32475) downgrades the exhausted retry to info instead of paging the error loop. This adds a regression test for the findUnique path (the existing BIT-32475 test covers findFirst). Paperclip-Issue: BIT-32481 Paperclip-Cluster: 9a675e2734df --- apps/api/src/sports/service.test.ts | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/apps/api/src/sports/service.test.ts b/apps/api/src/sports/service.test.ts index 8236b40..d04e273 100644 --- a/apps/api/src/sports/service.test.ts +++ b/apps/api/src/sports/service.test.ts @@ -39,6 +39,9 @@ const p57p01 = () => const p1017 = () => Object.assign(new Error("Invalid `prisma.person.findFirst()` invocation:\n\nServer has closed the connection."), { code: "P1017" }); +const p1017findUnique = () => + Object.assign(new Error("Invalid `prisma.person.findUnique()` invocation:\n\nServer has closed the connection."), { code: "P1017" }); + const ligaTeam = (id: string, externalId: string) => ({ id, provider: "LIGA", @@ -232,6 +235,42 @@ describe("syncEventSquads downgrades a P1017 server-closed connection that exhau }); }); +describe("syncEventSquads downgrades a P1017 from person.findUnique in linkSquadPerson (BIT-32481)", () => { + it("logs at info and returns zeros when the first person.findUnique is P1017 on both attempts", async () => { + // The error loop reported P1017 ("Server has closed the connection.") from linkSquadPerson → + // person.findUnique (the organizationId_sportsPlayerId lookup, the first DB call in the method). This is the + // same catch path as BIT-32475 (retryOnConnectionClosed retries once, then isPrismaConnectionClosed downgrades + // to info), but from the findUnique call rather than findFirst. This test proves that coverage. + const fpaTeam = { + id: "t-fpa", + provider: "FPA", + externalId: "fpa-1", + name: "Team FPA", + abbreviation: "FPA", + logoUrl: null, + }; + const db = { + event: { findUnique: async () => makeEvent({ homeTeam: fpaTeam, awayTeam: null }) }, + sportsPlayer: { + findFirst: async () => ({ season: "2026" }), + findMany: async () => [{ id: "pl-1", name: "Player 1", externalId: "lic-1", number: "1", photoUrl: null, season: "2026" }], + findUnique: async () => null, + }, + person: { + // Throws on every call, so the retryOnConnectionClosed retry also fails with P1017. + findUnique: async () => { throw p1017findUnique(); }, + findFirst: async () => null, + }, + }; + const service = new SportsService(makeDeps(db)); + const out = await service.syncEventSquads("evt-1"); + expect(out).toEqual({ created: 0, updated: 0, headshots: 0 }); + const log = (service as unknown as { deps: { log: { calls: LogCall[] } } }).deps.log; + expect(log.calls.some((c) => c.level === "info" && /database connection closed/.test(c.msg))).toBe(true); + expect(log.calls.some((c) => c.level === "warn")).toBe(false); + }); +}); + describe("linkStoredSquads downgrades a 57P01 admin-terminated connection (BIT-32471)", () => { it("logs at info and returns 0 when the raw query is terminated mid-flight (57P01)", async () => { const db = { -- 2.47.3