Spaces:
Running on Zero
Running on Zero
Download test_browser.cjs from ibm-granite/LLMON-Attention-Visualization: direct link, hf CLI and curl.
- Browser
- Download file 5.49 kB
-
https://huggingface.co/spaces/ibm-granite/LLMON-Attention-Visualization/resolve/main/test_browser.cjs
- Command line
-
hf download hf://spaces/ibm-granite/LLMON-Attention-Visualization/test_browser.cjs
-
curl -L -o test_browser.cjs https://huggingface.co/spaces/ibm-granite/LLMON-Attention-Visualization/resolve/main/test_browser.cjs
5.49 kB
| const { chromium } = require('playwright'); | |
| const assert = require('node:assert/strict'); | |
| (async () => { | |
| const base = process.env.LLMON_TEST_URL || 'http://127.0.0.1:7860'; | |
| const browser = await chromium.launch({ headless: true, executablePath: process.env.LLMON_CHROMIUM_PATH }); | |
| try { | |
| const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }); | |
| const errors = []; | |
| page.on('pageerror', error => errors.push(error.message)); | |
| let joins = 0; | |
| page.on('request', request => { if (request.url().includes('/gradio_api/queue/join')) joins++; }); | |
| const health = await (await page.request.get(base + '/api/health')).json(); | |
| for (const path of ['/', '/how-it-works/index.html', '/experiment_1/index.html', '/experiment_2/index.html', '/generation-flow-2/index.html', '/experiment_3/index.html']) { | |
| await page.goto(base + path, { waitUntil: 'networkidle' }); | |
| if (path.includes('generation-flow-2')) assert(new URL(page.url()).pathname === '/experiment_2/index.html'); | |
| assert(!await page.getByRole('link', { name: 'Generation Flow 2', exact: true }).count()); | |
| if (path === '/') { | |
| // The landing is the template's header plus the always-open about | |
| // card: no workspace panels, no info toggle, no close button. | |
| await page.locator('.app-card__header').waitFor(); | |
| await page.getByRole('link', { name: 'Open Generation Flow' }).first().waitFor(); | |
| await page.getByRole('link', { name: 'How it works' }).waitFor(); | |
| await page.getByRole('region', { name: 'About this demo' }).waitFor(); | |
| for (const gone of ['.workspace', '.examples-panel', '[aria-label="Info panel"]', '[aria-label="Close info panel"]']) | |
| assert.equal(await page.locator(gone).count(), 0, `Landing must not contain ${gone}`); | |
| // The header dropdown (model cards, paper, theme) must open ABOVE the | |
| // about card and be clickable, not hidden behind it. | |
| await page.getByRole('button', { name: 'More options' }).click(); | |
| for (const label of ['View Granite 4.1 3B LLMON', 'View Granite 4.1 8B LLMON', 'Read the LLMON paper']) { | |
| const item = page.getByRole('menuitem', { name: label }); | |
| await item.waitFor(); | |
| assert(await item.evaluate(el => { const r = el.getBoundingClientRect(); const top = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); return el === top || el.contains(top); }), | |
| `${label} must not be covered by the about card`); | |
| } | |
| await page.getByRole('button', { name: 'More options' }).click(); | |
| continue; | |
| } | |
| await page.getByRole('navigation', { name: 'Visualizations' }).waitFor(); | |
| const guideLink = page.getByRole('navigation', { name: 'Visualizations' }).getByRole('link').first(); | |
| assert.equal(await guideLink.innerText(), 'How it works'); | |
| assert.equal(await page.getByRole('navigation', { name: 'Visualizations' }).getByRole('link').count(), 2); | |
| assert.equal(await guideLink.getAttribute('href'), '/how-it-works/index.html'); | |
| assert.equal(await page.getByRole('link', { name: 'Admin', exact: true }).count(), 0); | |
| if (path === '/how-it-works/index.html') { | |
| await page.getByRole('heading', { name: 'How it works', exact: true }).waitFor(); | |
| assert.equal(await guideLink.getAttribute('aria-current'), 'page'); | |
| assert.equal(await page.getByRole('status').count(), 0); | |
| } else if (!health.model_ready) { | |
| await page.getByRole('status').filter({ hasText: health.message }).waitFor(); | |
| } else if (path !== '/') { | |
| await page.waitForFunction(() => !document.body.textContent.includes('loading examples'), { timeout: 20000 }); | |
| if (path.includes('experiment_2')) { | |
| await page.waitForFunction(() => /L\d+\/\d+/.test(document.body.textContent), { timeout: 20000 }); | |
| } | |
| assert.equal(await page.getByRole('status').filter({ hasText: 'not configured' }).count(), 0); | |
| if (path.includes('experiment_3')) { | |
| const example = await (await page.request.get(base + '/api/data/example/0')).json(); | |
| await page.locator('input[type=file]').setInputFiles({ | |
| name: 'browser-check.jsonl', mimeType: 'application/x-ndjson', | |
| buffer: Buffer.from(JSON.stringify({ id: 314, instruction: 'Browser check', llmon_prompt_dirty: example.llmon_prompt })), | |
| }); | |
| const card = page.getByRole('region', { name: /^Diagnosis for / }); | |
| const chip = card.getByText(/^(SUCCESS|PARTIAL|FAILURE)$/); | |
| await chip.waitFor({ timeout: 120000 }); | |
| const result = (await chip.innerText()).toLowerCase(); | |
| await page.getByRole('button', { name: /Ex #314 — Browser check/ }) | |
| .locator(`[aria-label$=": ${result}"]`).waitFor(); | |
| } | |
| } | |
| await page.setViewportSize({ width: 390, height: 844 }); | |
| await page.waitForFunction(() => document.documentElement.scrollWidth <= window.innerWidth + 1); | |
| await page.setViewportSize({ width: 1440, height: 1000 }); | |
| console.log('Rendered', path); | |
| } | |
| assert.deepEqual(errors, []); | |
| if (health.model_ready) assert(joins > 0, 'The browser must use the Gradio queue for live inference.'); | |
| console.log(`Browser checks passed; model_ready=${health.model_ready}; Gradio queue requests=${joins}`); | |
| } finally { | |
| await browser.close(); | |
| } | |
| })().catch(error => { console.error(error); process.exit(1); }); | |