← back to Tk11438 Postgres Migration

verification/tk11517-domain/browser-check.cjs

29 lines

const fs=require('fs'),assert=require('assert/strict');
const {chromium}=require('/Users/macstudio3/.agents/skills/hero-readability-auditor/node_modules/playwright');
const src=fs.readFileSync('/Users/macstudio3/Projects/all-designerwallcoverings/server.js','utf8');
const auth=src.match(/['"](admin:[^'"]+)['"]/)[1];
const hosts=new Set(['all.designerwallcoverings.com','gracie-internal.designerwallcoverings.com']);
const profile='/tmp/tk11517-browser-profile',out='/tmp/tk11517-browser-proof.json';
fs.mkdirSync(profile,{recursive:true,mode:0o700});fs.chmodSync(profile,0o700);
(async()=>{
 const browser=await chromium.launchPersistentContext(profile,{channel:'chrome',headless:false,viewport:{width:1440,height:1000}});
 const proof={ticket:'TK-11517',at:new Date().toISOString(),checks:[],application_mutations:0,email_sends:0},errors=[];
 try{
  await browser.route('**/*',async route=>{const request=route.request(),headers={...request.headers()};if(hosts.has(new URL(request.url()).hostname))headers.authorization='Basic '+Buffer.from(auth).toString('base64');else delete headers.authorization;await route.continue({headers});});
  const page=await browser.newPage();page.on('pageerror',e=>errors.push(e.message));
  const response=await page.goto('https://all.designerwallcoverings.com/microsites.html',{waitUntil:'domcontentloaded',timeout:30000});assert.equal(response.status(),200);
  // The grid renders batches. Search before waiting for a card beyond the first batch.
  await page.locator('#q').waitFor({state:'visible'});await page.locator('#fFeeds').click();
  await page.locator('#q').fill('gracie');
  const card=page.locator('a.card[href="https://gracie-internal.designerwallcoverings.com/"]');await card.waitFor({state:'visible',timeout:30000});assert.equal(await card.count(),1);
  proof.checks.push({name:'Gracie visible under With Catalogs after search',pass:true});
  const text=await card.innerText();assert(text.includes('150'));proof.checks.push({name:'Search Gracie yields unique internal card with150products',pass:true,text});
  await page.screenshot({path:'/tmp/tk11517-all-gracie.png',fullPage:false});
  const [popup]=await Promise.all([page.waitForEvent('popup'),card.click()]);await popup.waitForURL('https://gracie-internal.designerwallcoverings.com/**',{waitUntil:'domcontentloaded',timeout:30000});assert.equal(new URL(popup.url()).hostname,'gracie-internal.designerwallcoverings.com');await popup.waitForFunction(()=>document.body.innerText.includes('Gracie'),null,{timeout:15000});
  const api=await popup.evaluate(async()=>{const r=await fetch('/api/products');const d=await r.json();return{status:r.status,count:d.count};});assert.equal(api.status,200);assert.equal(api.count,150);
  proof.checks.push({name:'Actual directory click opens authenticated Gracie with150products',pass:true,url:popup.url(),title:await popup.title(),api});
  await popup.screenshot({path:'/tmp/tk11517-gracie-live.png',fullPage:false});proof.page_errors=errors;assert.equal(errors.length,0);
  proof.verdict='PASS';proof.screenshots=['/tmp/tk11517-all-gracie.png','/tmp/tk11517-gracie-live.png'];
 }catch(e){proof.verdict='FAIL';proof.error=e.message;const p=browser.pages().at(-1);if(p){proof.page={url:p.url(),text:(await p.locator('body').innerText()).slice(0,1800)};await p.screenshot({path:'/tmp/tk11517-browser-failure.png'}).catch(()=>{});}process.exitCode=1;}finally{fs.writeFileSync(out,JSON.stringify(proof,null,2)+'\n');await browser.close();console.log(JSON.stringify(proof,null,2));}
})().catch(e=>{console.error(e.message);process.exitCode=1;});