test(adapters): give the consolidation unit tests the profile lock

The write transaction now takes the per-user profile lock, so the mocked
client answers the lock query, and the first case checks the lock is taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u
This commit is contained in:
Claude 2026-10-02 23:26:49 +00:00
parent 84a95f0a3b
commit 5112d0e516
No known key found for this signature in database

View File

@ -178,6 +178,8 @@ function fakePrisma(
createMany: vi.fn(async () => ({ count: 1 })), createMany: vi.fn(async () => ({ count: 1 })),
updateMany: vi.fn(async () => ({ count: 1 })), updateMany: vi.fn(async () => ({ count: 1 })),
}, },
// The per-user profile lock taken inside the write transaction.
$queryRaw: vi.fn(async () => []),
$transaction: vi.fn(), $transaction: vi.fn(),
}; };
prisma.$transaction.mockImplementation(async (work: (tx: typeof prisma) => unknown) => prisma.$transaction.mockImplementation(async (work: (tx: typeof prisma) => unknown) =>
@ -334,6 +336,8 @@ describe("consolidateProfile", () => {
expect(request.prompt).not.toContain("asthma"); expect(request.prompt).not.toContain("asthma");
expect(request.prompt.match(/<conversation>/g)).toHaveLength(2); expect(request.prompt.match(/<conversation>/g)).toHaveLength(2);
// Facts are written under the same per-user lock as every other profile writer.
expect(prisma.$queryRaw).toHaveBeenCalledTimes(1);
expect(prisma.userProfile.updateMany).toHaveBeenCalledWith({ expect(prisma.userProfile.updateMany).toHaveBeenCalledWith({
where: { userId: "user-1", consolidatedAt: null, summary: "Runs." }, where: { userId: "user-1", consolidatedAt: null, summary: "Runs." },
data: { consolidatedAt: expect.any(Date), summary: "Nurse in Berlin who runs." }, data: { consolidatedAt: expect.any(Date), summary: "Nurse in Berlin who runs." },