import assert from "node:assert/strict"; import { pathToFileURL } from "node:url"; const modulePath = process.env.PLAYWRIGHT_MODULE; if (!modulePath) { console.log(JSON.stringify({ schema: "xyzbc-panel-browser.v1", status: "blocked", code: "playwright_unavailable" })); process.exit(0); } const { chromium } = await import(pathToFileURL(modulePath).href); const browser = await chromium.launch({ headless: true, executablePath: process.env.BROWSER_EXECUTABLE_PATH ?? "/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(error.message)); const control = (id) => page.locator(`[data-axis-control="${id}"]`); try { await page.goto(process.env.XYZAC_PANEL_URL ?? "http://127.0.0.1:5174/"); await page.waitForFunction(() => document.querySelector("main")?.dataset.axisProgramLoading === "false"); await control("toolbar-power").click(); await page.waitForTimeout(300); await control("machine-type-select").selectOption({ label: "XYZBC TRT" }); await page.waitForFunction(() => document.querySelector("main")?.dataset.axisProgramPath?.includes("boat-xyzbc.ngc") && document.querySelector("main")?.dataset.axisProgramLoading === "false", null, { timeout: 45000 }); assert.equal(await control("machine-type-select").inputValue(), "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzbc-trt.ini"); const result = await page.evaluate(() => ({ machine: document.querySelector(".xyzac-manual-summary")?.getAttribute("aria-label"), axes: [...document.querySelectorAll(".manual-axis-block .axis-radio span")].map((node) => node.textContent), summary: document.querySelector(".xyzac-manual-summary")?.textContent, toolPreview: document.querySelector(".xyzac-tool-preview")?.getAttribute("aria-label"), model: document.querySelector(".xyzac-machine-view")?.dataset.xyzacModelId, coordinates: document.querySelector(".xyzac-machine-view")?.dataset.xyzacModelSourcePath, canvases: document.querySelectorAll(".axis-preview-split canvas[data-engine]").length, previewHuds: document.querySelectorAll(".axis-preview-split .axis-preview-hud").length, machineToolpathFrame: document.querySelector(".xyzac-machine-view")?.dataset.xyzacToolpathFrame, machineToolpathAttached: document.querySelector(".xyzac-machine-view")?.dataset.xyzacToolpathAttached, })); assert.equal(result.machine, "XYZBC authoritative position"); assert.deepEqual(result.axes, ["X", "Y", "Z", "B", "C"]); assert.match(result.summary, /XYZBC authority/); assert.equal(result.toolPreview, "XYZBC authoritative tool preview"); assert.equal(result.model, "xyzbc-trt"); assert.equal(result.coordinates, "linuxcnc/src/hal/user_comps/vismach/xyzbc-trt-gui.py"); assert.equal(result.canvases, 2); assert.equal(result.previewHuds, 0); assert.equal(result.machineToolpathFrame, "rotate-c"); assert.equal(result.machineToolpathAttached, "true"); assert.deepEqual(errors, []); console.log(JSON.stringify({ schema: "xyzbc-panel-browser.v1", status: "verified", program: "boat-xyzbc.ngc", machine: result.model, axes: result.axes, canvases: result.canvases, preview_huds: result.previewHuds, machine_toolpath_frame: result.machineToolpathFrame, machine_toolpath_attached: result.machineToolpathAttached, browser_errors: errors })); } finally { await browser.close(); }