// Smoke en Chrome headless contra una URL (vite preview local o el Space publicado). Descarga real del modelo + inferencia WASM real. import puppeteer from 'puppeteer-core'; const url = process.env.URL || 'http://127.0.0.1:43135/'; const out = process.env.OUT || '/workspace/mesas-lab/verify'; const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: true, protocolTimeout: 900000, args: ['--no-sandbox'] }); const page = await browser.newPage(); await page.setViewport({ width: 1280, height: 1000 }); const hosts = new Set(); const posts = []; page.on('request', (r) => { hosts.add(new URL(r.url()).host); if (r.method() !== 'GET') posts.push(r.method() + ' ' + r.url().slice(0, 120)); }); page.on('console', (m) => { if (m.type() === 'error') console.log('[console.error]', m.text().slice(0, 200)); }); page.on('pageerror', (e) => console.log('[pageerror]', String(e).slice(0, 200))); await page.goto(url, { waitUntil: 'networkidle0' }); const frame = page; // app servida directamente (usar la URL *.static.hf.space para el Space) const t0 = Date.now(); await frame.click('#load-btn'); await frame.waitForFunction(() => /Modelo listo|Error/.test(document.getElementById('model-status').textContent), { timeout: 600000 }); console.log('model:', await frame.$eval('#model-status', (e) => e.textContent), `(${Date.now() - t0} ms incl. descarga)`); const expected = { 'comedor-1': ['ocupada', 'libre', 'limpiar', 'libre'], 'comedor-2': ['limpiar', 'ocupada', 'libre', 'limpiar'], 'comedor-3': ['ocupada', 'libre', 'limpiar', 'libre', 'limpiar', 'ocupada'] }; for (const id of [...Object.keys(expected), 'video-comedor-1']) { const t = Date.now(); await frame.click(`button[data-example="${id}"]`); await frame.waitForFunction((id) => { const r = document.getElementById('results'); return r.dataset.exampleId === id && /ok|error/.test(r.dataset.status); }, { timeout: 600000 }, id); const info = await frame.evaluate(() => { const r = document.getElementById('results'); return { status: r.dataset.status, states: JSON.parse(r.dataset.states || '{}'), latencyMs: r.dataset.latencyMs, device: r.dataset.device, summary: document.getElementById('summary').textContent, log: [...document.querySelectorAll('#log li')].map((l) => l.textContent).reverse() }; }); const got = Object.values(info.states); console.log(id, `wall=${Date.now() - t}ms`, JSON.stringify(info), expected[id] ? (JSON.stringify(got) === JSON.stringify(expected[id]) ? 'MATCH' : 'MISMATCH ' + JSON.stringify(expected[id])) : ''); const el = await frame.$('#canvas'); await el.screenshot({ path: `${out}/result-${id}.png` }); } await page.screenshot({ path: `${out}/ui-full.png`, fullPage: true }); console.log('hosts:', [...hosts].join(', ')); console.log('non-GET requests:', posts.length ? posts.join(' | ') : 'none'); await browser.close();