feat(ai-chat reference): db:reset:chats helper for clean smoke-test slates

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.
This commit is contained in:
Eric Allam
2026-04-29 14:14:00 +01:00
parent 27e3c93f5d
commit 0add0e7b64
2 changed files with 8 additions and 0 deletions
+1
View File
@@ -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": {
@@ -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";