Download task_021/tests/validate_enhanced_cases.js from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 3.7 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_021/tests/validate_enhanced_cases.js
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_021/tests/validate_enhanced_cases.js
-
curl -L -o validate_enhanced_cases.js https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_021/tests/validate_enhanced_cases.js
3.7 kB
| const path = require('path'); | |
| const { pathToFileURL } = require('url'); | |
| const { chromium } = require('playwright'); | |
| const entryUrl = pathToFileURL(path.join(process.cwd(), 'index.html')).href; | |
| const seed = Number.parseInt(process.env.ENHANCED_SEED || '32031', 10); | |
| function assert(condition, message) { | |
| if (!condition) throw new Error(message); | |
| } | |
| async function runCase(browser, name, validate) { | |
| const context = await browser.newContext({ viewport: { width: 1000, height: 700 } }); | |
| const networkAttempts = []; | |
| await context.route('**/*', async (route) => { | |
| const url = route.request().url(); | |
| if (/^https?:/i.test(url)) { | |
| networkAttempts.push(url); | |
| await route.abort('blockedbyclient'); | |
| return; | |
| } | |
| await route.continue(); | |
| }); | |
| await context.addInitScript(({ fixedSeed }) => { | |
| let state = fixedSeed >>> 0; | |
| Math.random = () => { | |
| state = (state * 1664525 + 1013904223) >>> 0; | |
| return state / 0x100000000; | |
| }; | |
| }, { fixedSeed: seed }); | |
| const page = await context.newPage(); | |
| page.setDefaultTimeout(5000); | |
| const errors = []; | |
| page.on('pageerror', (error) => errors.push(error.message)); | |
| try { | |
| await page.goto(entryUrl, { waitUntil: 'domcontentloaded' }); | |
| await validate(page); | |
| assert(networkAttempts.length === 0, `${name}: external network request attempted`); | |
| assert(errors.length === 0, `${name}: browser errors: ${errors.join(' | ')}`); | |
| console.log(`${name} passed`); | |
| } finally { | |
| await context.close(); | |
| } | |
| } | |
| async function assertNamesAppearOnce(page, names) { | |
| for (const name of names) { | |
| const count = await page.locator(`[data-component-name="${name}"]`).count(); | |
| assert(count === 1, `${name} must occur exactly once as a data-component-name value; got ${count}`); | |
| } | |
| } | |
| (async () => { | |
| assert(Number.isInteger(seed), 'ENHANCED_SEED must be a fixed integer'); | |
| const browser = await chromium.launch({ | |
| headless: true, | |
| args: ['--no-sandbox', '--disable-background-networking', '--disable-component-update', '--no-first-run'], | |
| }); | |
| try { | |
| // ENHANCED_CASE_1: all required layout component names occur exactly once. | |
| await runCase(browser, 'ENHANCED_CASE_1', async (page) => { | |
| await assertNamesAppearOnce(page, ['AppShell', 'NavigationSidebar', 'MainContentArea']); | |
| }); | |
| // ENHANCED_CASE_2: all required prompt component names occur exactly once. | |
| await runCase(browser, 'ENHANCED_CASE_2', async (page) => { | |
| await assertNamesAppearOnce(page, ['PromptResponseBlock', 'PromptInput', 'AIContentArea']); | |
| }); | |
| // ENHANCED_CASE_3: the prescribed component names are exposed as registry keys. | |
| await runCase(browser, 'ENHANCED_CASE_3', async (page) => { | |
| const required = ['AppShell', 'NavigationSidebar', 'MainContentArea', 'PromptResponseBlock', 'PromptInput', 'AIContentArea']; | |
| const registryState = await page.evaluate((names) => { | |
| const registry = window.componentRegistry; | |
| return { | |
| isObject: registry !== null && typeof registry === 'object' && !Array.isArray(registry), | |
| ownKeys: registry && typeof registry === 'object' | |
| ? names.filter((name) => Object.prototype.hasOwnProperty.call(registry, name)) | |
| : [], | |
| }; | |
| }, required); | |
| assert(registryState.isObject, 'window.componentRegistry must be an object'); | |
| assert(required.every(name => registryState.ownKeys.includes(name)), | |
| `window.componentRegistry must expose all six prescribed names; found ${registryState.ownKeys.join(', ')}`); | |
| }); | |
| } finally { | |
| await browser.close(); | |
| } | |
| })().catch((error) => { | |
| console.error(error && error.stack || error); | |
| process.exit(1); | |
| }); | |