/ concept-collection / turing-surface-cache
Sign in
concept-collection / turing-surface-cache
turing-surface-cache / scripts / check-live.mjs
62 lines · 2.5 KBBlameHistoryRaw
1/**
2 * Smoke-check a deployed URL in headless Chrome: load it and wait for the
3 * boot-time solve to finish — either from the cloud cache or computed locally.
4 * Talks to the real cache. Usage: node scripts/check-live.mjs [url]
5 */
6import puppeteer from 'puppeteer-core';
8const url = process.argv[2] ?? 'https://concept-collection.github.io/turing-surface-cache/';
9const browser = await puppeteer.launch({
10 executablePath: process.env.CHROME_PATH ?? '/usr/bin/google-chrome',
11 args: ['--headless=new', '--no-sandbox', '--enable-unsafe-webgpu',
12 '--use-webgpu-adapter=swiftshader', '--enable-unsafe-swiftshader'],
13});
14const page = await browser.newPage();
15await page.setViewport({ width: 1100, height: 900 });
16const problems = [];
17page.on('pageerror', (e) => problems.push(`pageerror: ${e.message}`));
18page.on('requestfailed', (r) => {
19 // The cache lookup 404s by design when the selection is not cached.
20 if (!r.url().startsWith('https://tempory.net/')) {
21 problems.push(`request failed: ${r.url()}`);
22 }
23});
24page.on('console', (m) => {
25 if (m.type() === 'error' && !/GL Driver|favicon|tempory\.net/.test(m.text())) {
26 problems.push(`console error: ${m.text()}`);
27 }
28});
30try {
31 await page.goto(url, { waitUntil: 'load', timeout: 60_000 });
32 // Nothing computes without the button, so any selection is safe to idle on.
33 await page.waitForSelector('#tend');
34 // Terminal statuses only — "checking the cloud cache…" is transient. A
35 // miss settles on empty windows asking for the button; nothing computes
36 // during this check.
37 await page.waitForFunction(
38 () => /from the cloud cache|press Compute solution|failed/.test(
39 document.getElementById('status')?.textContent ?? '') ||
40 (document.getElementById('err')?.textContent?.length ?? 0) > 4,
41 { timeout: 600_000 },
42 );
43 console.log('status:', await page.$eval('#status', (el) => el.textContent));
44 const err = await page.$eval('#err', (el) => el.textContent);
45 if (err) problems.push(`err: ${err}`);
46 const panels = await page.$$eval('.sphere-box canvas', (els) => els.length);
47 console.log('sphere canvases:', panels);
48 if (panels !== 2) problems.push(`expected 2 sphere canvases, got ${panels}`);
49 if (problems.length) {
50 console.log('PROBLEMS:');
51 for (const p of new Set(problems)) console.log(' ' + p);
52 process.exitCode = 1;
53 } else {
54 console.log('LIVE CHECK: PASS');
55 }
56} catch (e) {
57 console.error(`LIVE CHECK FAIL: ${e.message}`);
58 for (const p of new Set(problems)) console.error(' ' + p);
59 process.exitCode = 1;
60} finally {
61 await browser.close();
moveopenescclose