From 0add0e7b64841ee3b02814a2d3da82e786dfd7a0 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Wed, 29 Apr 2026 14:14:00 +0100 Subject: [PATCH] feat(ai-chat reference): db:reset:chats helper for clean smoke-test slates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reference's Chat / ChatSession Postgres tables are shared between local and test cloud targets. A row created with one webapp's PAT and lastEventId is poison if you switch the .env to the other target and reuse the same chatId — the transport gets a 401 or resumes from a sequence that doesn't exist on the other backend. Adds: - prisma/reset-chats.sql: TRUNCATE Chat, ChatSession (User survives — it's upserted by onPreload/onChatStart anyway). - package.json db:reset:chats script wrapping prisma db execute --file. Run `pnpm run db:reset:chats` between target switches and at the top of every smoke test. Codified in the ai-chat-e2e skill as a required prereq. --- references/ai-chat/package.json | 1 + references/ai-chat/prisma/reset-chats.sql | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 references/ai-chat/prisma/reset-chats.sql diff --git a/references/ai-chat/package.json b/references/ai-chat/package.json index 737b71b0b..45071838a 100644 --- a/references/ai-chat/package.json +++ b/references/ai-chat/package.json @@ -10,6 +10,7 @@ "db:migrate": "prisma migrate dev", "db:push": "prisma db push", "db:generate": "prisma generate", + "db:reset:chats": "prisma db execute --file prisma/reset-chats.sql", "test": "vitest" }, "dependencies": { diff --git a/references/ai-chat/prisma/reset-chats.sql b/references/ai-chat/prisma/reset-chats.sql new file mode 100644 index 000000000..06363e733 --- /dev/null +++ b/references/ai-chat/prisma/reset-chats.sql @@ -0,0 +1,7 @@ +-- Wipe customer-side chat state for a fresh smoke-test slate. +-- Run via `pnpm run db:reset:chats`. +-- Leaves User rows intact (they're upserted by onPreload/onChatStart), +-- but clears every Chat + ChatSession so a chatId from one target +-- (test cloud / local) can't carry stale session/PAT/lastEventId state +-- into the other. +TRUNCATE "Chat", "ChatSession";