// Browser acceptance: switch through all 13 five-axis cases, confirm the bound // structure GLB loads and that the joint state published on the preview host // carries the expected slot keys and changes while a program runs. import { chromium } from '/home/mes006/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/index.mjs'; import { readFile } from 'node:fs/promises'; import { mkdir } from 'node:fs/promises'; const BASE = process.env.AXIS_URL ?? 'http://127.0.0.1:5174/'; const OUT = new URL('../coverage/glb-machine-manager/physical-drive/', import.meta.url); await mkdir(OUT, { recursive: true }); const catalog = JSON.parse(await readFile(new URL('../web/workspace/machine-visual-bindings.json', import.meta.url), 'utf8')); const browser = await chromium.launch({ executablePath: '/usr/bin/google-chrome', headless: true, args: ['--no-sandbox'] }); const page = await browser.newPage({ viewport: { width: 1600, height: 1000 } }); const errors = []; page.on('pageerror', (error) => errors.push(String(error))); page.on('console', (message) => { if (message.type() === 'error') errors.push(message.text()); }); await page.goto(BASE, { waitUntil: 'domcontentloaded' }); await page.waitForFunction(() => document.querySelector('[data-axis-state-source="linuxcnc-wasm"]'), null, { timeout: 120000 }); // A case switch powers the machine off, and `gates.load` requires // machineOn && idle, so every switch after the first one needs power on first. async function ensureLoadable() { for (let attempt = 0; attempt < 4; attempt += 1) { const state = await page.evaluate(() => { const button = (id) => document.querySelector(`[data-axis-control="${id}"]`); return { estop: button("toolbar-estop")?.getAttribute("aria-pressed"), power: button("toolbar-power")?.getAttribute("aria-pressed"), powerDisabled: button("toolbar-power")?.hasAttribute("disabled") }; }); if (state.estop === "true") { await button("toolbar-estop"); continue; } if (state.power !== "true" && !state.powerDisabled) { await button("toolbar-power"); await page.waitForTimeout(1500); continue; } return; } } async function button(id) { await page.click(`[data-axis-control="${id}"]`).catch(() => undefined); await page.waitForTimeout(1200); } const rows = []; for (const item of catalog.cases) { await ensureLoadable(); await page.selectOption('[data-axis-control="workspace-case-select"]', item.entrypoint); // Wait for THIS case's model, not merely "some" model: the previous case's // GLB stays mounted until the new one is parsed, which made an earlier run // report slot keys one case behind. const expectedModel = item.glb.default; const loaded = await page.waitForFunction( (name) => { const node = document.querySelector('[data-xyzac-preview="machine"]'); const model = node?.getAttribute('data-xyzac-model-source-path'); const glb = node?.getAttribute('data-machine-glb'); return model === name && glb ? glb : null; }, expectedModel, { timeout: 90000 }).catch(() => null); const glb = loaded ? await loaded.jsonValue() : null; const slots = await page.evaluate(() => { const raw = document.querySelector('[data-xyzac-preview="machine"]')?.getAttribute('data-machine-joint-state'); if (!raw) return null; try { return Object.keys(JSON.parse(raw)); } catch { return null; } }); await page.screenshot({ path: new URL(`${item.machineId}.png`, OUT).pathname, fullPage: false }); rows.push({ id: item.machineId, coordinates: item.coordinates, glbLoaded: Boolean(glb), slotKeys: slots, expectedKeys: item.jointOrder.map((slot) => slot.key) }); console.log(JSON.stringify({ id: item.machineId, glbLoaded: Boolean(glb), slots })); } await browser.close(); const report = { schema: 'five-axis-live-models.v1', url: BASE, cases: rows, browser_errors: errors }; await readFile; (await import('node:fs/promises')).writeFile(new URL('browser.report.json', OUT), `${JSON.stringify(report, null, 2)}\n`); console.log(JSON.stringify({ cases: rows.length, loaded: rows.filter((row) => row.glbLoaded).length, errors: errors.length }));