import assert from 'node:assert/strict'; import { mkdir, readFile, writeFile } from 'node:fs/promises'; import { pathToFileURL } from 'node:url'; const imported = await import(pathToFileURL(process.env.PLAYWRIGHT_MODULE ?? '/home/mes006/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/index.js')); const playwright = imported.default ?? imported; const browser = await playwright.chromium.launch({ headless: true, executablePath: '/usr/bin/google-chrome', args: ['--no-sandbox', '--use-angle=swiftshader', '--enable-unsafe-swiftshader'] }); const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }); const errors = []; page.on('pageerror', (error) => errors.push(`pageerror:${error.message}`)); page.on('console', (message) => { if (message.type() === 'error') errors.push(`console:${message.text()}`); }); const control = (id) => page.locator(`[data-axis-control="${id}"]`); const cases = [ ['xyzac-trt', 7], ['xyzbc-trt', 7], ['xyzab-tdr', 7], ['bridge-mill-5axiskins', 10], ['max5-maxkins', 7], ['hexapod-genhexkins', 10], ['pentapod-pentakins', 9], ['puma-pumakins', 8], ['puma-genserkins', 8], ['trivkins-xyzab', 7], ['trivkins-xyzcw', 7], ['trivkins-xyzya', 7], ['scorbot-kins', 7], ]; const report = { schema: 'physical-case-glb-browser.v1', status: 'running', cases: [], browser_errors: errors }; const out = new URL('../coverage/glb-machine-manager/physical-cases/', import.meta.url); await mkdir(out, { recursive: true }); try { await page.goto(process.env.PHYSICAL_CASE_URL ?? 'http://127.0.0.1:5174/', { waitUntil: 'domcontentloaded', timeout: 30000 }); await page.waitForFunction(() => document.querySelector('main.axis-app')?.dataset.axisStateSource === 'linuxcnc-wasm', null, { timeout: 60000 }); await control('machine-manager-settings').click(); for (const [id, minimumNodes] of cases) { await control('machine-document-new').click(); const chooser = page.waitForEvent('filechooser'); await control('machine-manager-import').click(); const fileChooser = await chooser; await fileChooser.setFiles({ name: `${id}.glb`, mimeType: 'model/gltf-binary', buffer: await readFile(new URL(`../web/react/public/machine-cases/physical/${id}.glb`, import.meta.url)) }); await page.waitForFunction(() => document.querySelector('.machine-manager-workbench')?.getAttribute('aria-busy') === 'false', null, { timeout: 30000 }); const nodes = page.locator('[data-axis-control="machine-tree-node"]'); await page.waitForFunction((minimum) => document.querySelectorAll('[data-axis-control="machine-tree-node"]').length >= minimum, minimumNodes, { timeout: 30000 }); assert.ok(await nodes.count() >= minimumNodes, id); const preview = page.locator('[data-machine-manager-preview]'); assert.equal(await preview.getAttribute('data-machine-manager-render-state'), 'rendered', id); await page.screenshot({ path: new URL(`${id}.png`, out).pathname, fullPage: true }); report.cases.push({ id, tree_nodes: await nodes.count(), scene_objects: await preview.getAttribute('data-machine-manager-scene-objects'), rendered: await preview.getAttribute('data-machine-manager-rendered') }); } assert.deepEqual(errors, []); report.status = 'verified'; } catch (error) { report.status = 'failed'; report.error = error instanceof Error ? error.stack : String(error); await page.screenshot({ path: new URL('failure.png', out).pathname, fullPage: true }).catch(() => {}); throw error; } finally { report.browser_errors = errors; await writeFile(new URL('browser.report.json', out), `${JSON.stringify(report, null, 2)}\n`); await browser.close(); } console.log(JSON.stringify(report));