import { chromium } from 'playwright-core'; const chrome = process.env.CHROME_PATH ?? '/home/emil/.cache/ms-playwright/chromium-1248/chrome-linux64/chrome'; const browser = await chromium.launch({ executablePath: chrome, args: ['--no-sandbox'] }); const page = await browser.newPage({ viewport: { width: 1600, height: 1000 }, deviceScaleFactor: 1 }); const errors = []; page.on('pageerror', (error) => errors.push(error.message)); page.on('console', (message) => { if (message.type() === 'error') errors.push(message.text()); }); await page.goto('http://127.0.0.1:5173/', { waitUntil: 'load' }); await page.waitForTimeout(2200); await page.locator('.room', { hasText: 'choir' }).click(); await page.waitForTimeout(400); await page.locator('.choir-form input').fill('raise the tempo a little'); await page.locator('.choir-send').click(); await page.waitForSelector('.choir-proposal', { timeout: 20000 }); const proposal = (await page.locator('.choir-proposal').last().textContent())?.replace(/\s+/g, ' ').trim(); await page.locator('.choir-proposal-actions button').first().click(); await page.waitForFunction( () => document.querySelector('.choir-readout')?.textContent?.includes('132'), null, { timeout: 20000 } ); await page.waitForTimeout(600); await page.screenshot({ path: '../preview-p2-agent.png' }); const report = await page.evaluate(() => ({ readout: document.querySelector('.choir-readout')?.textContent?.replace(/\s+/g, ' ').trim(), messages: [...document.querySelectorAll('.choir-message')].map((el) => el.textContent?.replace(/\s+/g, ' ').trim()), proposals: document.querySelectorAll('.choir-proposal').length, wire: [...document.querySelectorAll('.wire-label')].map((el) => el.textContent).slice(-8), choir: document.querySelector('.choir-head h1')?.textContent })); console.log(JSON.stringify({ proposal, report, errors }, null, 2)); const failures = []; if (!proposal?.includes('tempo')) failures.push('no tempo proposal'); if (!report.readout?.includes('132')) failures.push('tempo did not move in the readout'); if (!report.messages.some((line) => line?.includes('Applied'))) failures.push('no applied message'); if (report.proposals !== 0) failures.push('proposal was not resolved'); if (errors.length) failures.push('console errors'); await browser.close(); if (failures.length) { console.error('AGENT UI SMOKE FAILED: ' + failures.join('; ')); process.exit(1); } console.log('agent UI smoke passed');