From c18cf294527a567008df802d2395e17237dab934 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Sat, 25 Apr 2026 21:49:33 -0700 Subject: [PATCH] fix: add database safety check to Cucumber hooks - Prevents tests from running against production database - Uses same logic as Playwright global setup - Ensures test data isolation --- e2e/cucumber/support/hooks.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/e2e/cucumber/support/hooks.ts b/e2e/cucumber/support/hooks.ts index 3c10f1d..6fb4f14 100644 --- a/e2e/cucumber/support/hooks.ts +++ b/e2e/cucumber/support/hooks.ts @@ -23,6 +23,31 @@ if (fs.existsSync(envDevPath)) { require('dotenv').config({ path: envDevPath, override: true }); } +// Database safety check - prevent tests from running against production +function isProductionDatabase(): boolean { + const dbUrl = process.env.DATABASE_URL || ''; + return dbUrl.includes('euchre_camp') && !dbUrl.includes('_dev') && !dbUrl.includes('test'); +} + +if (isProductionDatabase()) { + console.error(''); + console.error('='.repeat(80)); + console.error('CRITICAL ERROR: Cucumber tests are attempting to run against PRODUCTION database!'); + console.error('='.repeat(80)); + console.error(''); + console.error('Current DATABASE_URL:', process.env.DATABASE_URL); + console.error(''); + console.error('Tests MUST run against a development/test database.'); + console.error(''); + console.error('To fix this:'); + console.error(' 1. Set DATABASE_URL to a dev/test database'); + console.error(' 2. Or run: npm run test:acceptance (which uses Playwright tests)'); + console.error(''); + console.error('Aborting test execution to prevent data corruption.'); + console.error(''); + process.exit(1); +} + /** * Before all scenarios: Launch browser */