File size: 1,700 Bytes
fc90384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { chromium } from 'playwright';
import fs from 'node:fs/promises';
const root = new URL('../..', import.meta.url).pathname;
const result = { date: new Date().toISOString(), url: 'https://huggingface.co/spaces/Mike0021/MiniCPM5-2B-WebGPU-Pi-HTTP' };
const browser = await chromium.launch({ executablePath: '/usr/bin/chromium', headless: true });
try {
  const page = await browser.newPage();
  await page.goto(result.url, { waitUntil: 'domcontentloaded' });
  // A FrameLocator survives the Hub replacing/navigating its initial iframe.
  const app = page.frameLocator('iframe[src*="mike0021-minicpm5-2b-webgpu-pi-http.static.hf.space"]');
  // Wait for event handlers/worker initialization, not merely the static HTML.
  await app.locator('#files button').first().waitFor();
  await app.locator('body').evaluate(() => window.browserPi.ready);
  await app.locator('#command').fill('curl -fsS https://jsonplaceholder.typicode.com/todos/1 -o embedded.json && jq -r .title embedded.json');
  await app.locator('#shell-run').click();
  await app.locator('.shell-entry:last-child .shell-status.success').waitFor();
  result.stdout = await app.locator('.shell-entry:last-child .shell-stdout').textContent();
  result.storageNotice = await app.locator('#notice').textContent();
  result.openInNewTabOffered = await app.locator('#open-tab').isVisible();
  result.passed = result.stdout.includes('delectus aut autem');
  console.log(JSON.stringify(result));
} catch (error) { result.failure = error.message; process.exitCode = 1; console.log('FAIL', error.message); }
finally { await fs.writeFile(root + '/validation/http-embedded.json', JSON.stringify(result, null, 2) + '\n'); await browser.close(); }