From a38bee9af2d831726d45f2c19503ef935fcf8461 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Sun, 12 Apr 2026 22:57:07 +0200 Subject: [PATCH] test: implement gatekeeper resilience standards for e2e forms --- scripts/check-forms.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/scripts/check-forms.ts b/scripts/check-forms.ts index 83237ba3..a28ee20f 100644 --- a/scripts/check-forms.ts +++ b/scripts/check-forms.ts @@ -5,9 +5,16 @@ import * as cheerio from 'cheerio'; const targetUrl = process.argv[2] || process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000'; const gatekeeperPassword = process.env.GATEKEEPER_PASSWORD || 'klz2026'; +// Utility for hardcoded delays +const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); + async function main() { console.log(`\nšŸš€ Starting E2E Form Submission Check for: ${targetUrl}`); + // 0. Settlement Delay: Wait for deployment to settle (sync containers/Varnish) + console.log(`ā³ Waiting 5s for deployment settlement...`); + await delay(5000); + // 1. Fetch Sitemap to discover the contact page and a product page const sitemapUrl = `${targetUrl.replace(/\/$/, '')}/sitemap.xml`; let urls: string[] = []; @@ -60,8 +67,15 @@ async function main() { console.log(`\nšŸ•·ļø Launching Puppeteer Headless Engine...`); const browser = await puppeteer.launch({ headless: true, - executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || process.env.CHROME_PATH || undefined, - args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'], + args: [ + '--no-sandbox', + '--disable-setuid-sandbox', + '--disable-dev-shm-usage', + '--disable-gpu', + '--ignore-certificate-errors', + '--disable-web-security', + '--disable-features=IsolateOrigins,site-per-process', + ], }); const page = await browser.newPage(); @@ -73,19 +87,28 @@ async function main() { }); // 3. Authenticate through Gatekeeper login form - console.log(`\nšŸ›”ļø Authenticating through Gatekeeper...`); try { // Navigate to a protected page so Gatekeeper redirects us to the login screen - await page.goto(contactUrl, { waitUntil: 'networkidle0', timeout: 30000 }); + // RELAXED NAVIGATION: Use domcontentloaded to handle rapid redirects + await page.goto(contactUrl, { waitUntil: 'domcontentloaded', timeout: 60000 }); + + // BOUNCE BUFFER: Wait for potential Gatekeeper redirect chain to settle + console.log(` Waiting for potential Gatekeeper redirect bounce...`); + await delay(3000); // Check if we landed on the Gatekeeper login page const isGatekeeperPage = await page.$('input[name="password"]'); if (isGatekeeperPage) { + console.log(` Gatekeeper gate detected. Logging in...`); await page.type('input[name="password"]', gatekeeperPassword); await Promise.all([ - page.waitForNavigation({ waitUntil: 'networkidle0', timeout: 30000 }), + page.waitForNavigation({ waitUntil: 'domcontentloaded' }), page.click('button[type="submit"]'), ]); + + // LOGIN SYNC BUFFER: Let the authenticated session settle + console.log(` Authenticating session...`); + await delay(3000); console.log(`āœ… Gatekeeper authentication successful!`); } else { console.log(`āœ… Already authenticated (no Gatekeeper gate detected).`);