Commit 76109e6f authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: ui-audit tears down its guest accounts even when the browser crashes

The audit signs in as a guest per device, which creates a real account. A single
long-lived browser was crashing partway through the third device, and the crash
took the teardown with it — leaving throwaway accounts in production.

Now: one browser per device, and teardown in a finally block so it runs whichever
way the run ends.
Co-Authored-By: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
parent 13cbc287
...@@ -207,7 +207,8 @@ async function goToScene(page, scene) { ...@@ -207,7 +207,8 @@ async function goToScene(page, scene) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
fs.mkdirSync(OUT, { recursive: true }); fs.mkdirSync(OUT, { recursive: true });
const browser = await puppeteer.launch({
const launch = () => puppeteer.launch({
executablePath: CHROME, headless: 'new', executablePath: CHROME, headless: 'new',
args: ['--no-sandbox', '--disable-dev-shm-usage', '--font-render-hinting=none'], args: ['--no-sandbox', '--disable-dev-shm-usage', '--font-render-hinting=none'],
}); });
...@@ -215,7 +216,12 @@ const browser = await puppeteer.launch({ ...@@ -215,7 +216,12 @@ const browser = await puppeteer.launch({
const report = { base: BASE, when: new Date().toISOString(), devices: {} }; const report = { base: BASE, when: new Date().toISOString(), devices: {} };
const consoleErrors = []; const consoleErrors = [];
// A browser per device. One long-lived instance was crashing partway through the
// run, which took the guest teardown with it and left throwaway accounts behind.
let browser;
try {
for (const device of DEVICES) { for (const device of DEVICES) {
browser = await launch();
const page = await browser.newPage(); const page = await browser.newPage();
page.on('pageerror', e => consoleErrors.push({ device: device.name, error: String(e).slice(0, 200) })); page.on('pageerror', e => consoleErrors.push({ device: device.name, error: String(e).slice(0, 200) }));
page.on('console', m => { page.on('console', m => {
...@@ -243,10 +249,15 @@ for (const device of DEVICES) { ...@@ -243,10 +249,15 @@ for (const device of DEVICES) {
} }
} }
await page.close(); await page.close();
await browser.close();
browser = null;
}
} finally {
// Teardown must run even if the browser dies mid-run.
try { if (browser) await browser.close(); } catch (e) {}
await removeGuests();
} }
report.consoleErrors = consoleErrors; report.consoleErrors = consoleErrors;
await browser.close();
await removeGuests();
fs.writeFileSync(path.join(OUT, 'report.json'), JSON.stringify(report, null, 2)); fs.writeFileSync(path.join(OUT, 'report.json'), JSON.stringify(report, null, 2));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment