← back to Dw Theme Boost Fix
verify/interceptor-race-test.mjs
50 lines
// Pre-deploy verification of the Boost endpoint interceptor (read-only).
// Loads the LIVE collection page twice — control (no patch) and patched
// (interceptor injected via addInitScript, exactly the <head> position it
// will occupy in the theme) — and records every request to Boost hosts.
// PASS = patched run makes ZERO requests to staging.bc-solutions.net and
// gets 200s from services.mybcapps.com; facets render.
import { chromium } from 'playwright';
import { readFileSync } from 'fs';
const INTERCEPTOR = readFileSync(new URL('./interceptor.js', import.meta.url), 'utf8');
const PAGE_URL = 'https://www.designerwallcoverings.com/collections/grasscloth-wallpaper-collection';
async function run(label, inject) {
const browser = await chromium.launch();
const page = await browser.newPage({ userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126 Safari/537.36' });
const hits = [];
page.on('response', r => {
const u = r.url();
if (u.includes('bc-solutions.net') || u.includes('mybcapps.com')) {
hits.push({ url: u.split('?')[0], status: r.status() });
}
});
if (inject) await page.addInitScript(INTERCEPTOR);
await page.goto(PAGE_URL, { waitUntil: 'load', timeout: 60000 });
await page.waitForTimeout(12000); // let Boost boot + fire filter calls
// poke the page like a user: scroll to trigger the grid
await page.mouse.wheel(0, 4000);
await page.waitForTimeout(6000);
const facetCount = await page.locator('.boost-sd__filter-option-item, .boost-sd__filter-option, [class*="boost-sd__filter"] li').count().catch(() => 0);
const cfg = await page.evaluate(() => {
const c = window.boostSDAppConfig; return c && c.api ? c.api.filterUrl : null;
});
await browser.close();
const staging = hits.filter(h => h.url.includes('staging.bc-solutions.net'));
const prod200 = hits.filter(h => h.url.includes('mybcapps.com') && h.status === 200);
console.log(`\n== ${label} ==`);
console.log('runtime filterUrl:', cfg);
console.log(`staging requests: ${staging.length}`, staging.slice(0, 4));
console.log(`prod mybcapps 200s: ${prod200.length}`, prod200.slice(0, 4).map(h => h.url));
console.log('rendered facet elements:', facetCount);
return { staging: staging.length, prod200: prod200.length, facetCount, cfg };
}
const control = await run('CONTROL (live page, no patch)', false);
const patched = await run('PATCHED (interceptor injected)', true);
const pass = patched.staging === 0 && patched.prod200 > 0;
console.log(`\nVERDICT: ${pass ? 'PASS — interceptor wins the race' : 'FAIL — staging still called or no prod 200s'}`);
process.exit(pass ? 0 : 1);