// Smoke: open the production-line reference panel and fetch GLBs from the // working reference directory via Playwright route interception (no public copy). import fs from "node:fs"; import path from "node:path"; import { createRequire } from "node:module"; import { fileURLToPath } from "node:url"; const here = path.dirname(fileURLToPath(import.meta.url)); const webRoot = path.resolve(here, "../../.."); const require = createRequire(path.join(webRoot, "package.json")); const { chromium } = require("playwright"); const sourceDir = "/home/mes123456/FreeCADWasmDev/working/GLTFmodel"; const shot = path.join(here, "line-reference-smoke.png"); const browser = await chromium.launch({ executablePath: "/usr/bin/google-chrome", headless: true, args: ["--no-sandbox", "--disable-dev-shm-usage", "--enable-unsafe-swiftshader", "--use-gl=angle", "--use-angle=swiftshader"] }); const page = await browser.newPage({ viewport: { width: 1600, height: 900 } }); const errors = []; const consoleErrors = []; page.on("pageerror", error => errors.push(String(error))); page.on("console", message => { if (message.type() === "error") consoleErrors.push(message.text().slice(0, 200)); }); await page.route("**/line-glb/*.glb", route => { const name = decodeURIComponent(new URL(route.request().url()).pathname.split("/").pop() ?? ""); const file = path.join(sourceDir, name); if (!fs.existsSync(file)) return route.fulfill({ status: 404, body: "missing" }); return route.fulfill({ status: 200, contentType: "model/gltf-binary", body: fs.readFileSync(file) }); }); const result = { ok: false, steps: [] }; try { await page.goto("http://127.0.0.1:5181/project.html?workbench=Part", { waitUntil: "domcontentloaded", timeout: 120000 }); await page.waitForSelector('select[aria-label="Workbench"]', { timeout: 120000 }); await page.waitForTimeout(1200); await page.locator('nav[aria-label="Application menus"] details').filter({ hasText: "File" }).locator("summary").click(); await page.getByRole("button", { name: "新建 Document" }).click(); await page.waitForTimeout(2200); result.steps.push({ step: "document", status: await page.locator('footer [role="status"]').textContent().catch(() => "") }); await page.getByRole("button", { name: "Toggle line reference viewer" }).click(); const panel = page.getByRole("complementary", { name: "Line reference viewer" }); await panel.waitFor({ state: "visible", timeout: 30000 }); const select = panel.locator('select[aria-label="Reference model"]'); await select.waitFor({ state: "visible", timeout: 30000 }); for (let attempt = 0; attempt < 60; attempt++) { await page.waitForTimeout(500); const footer = await panel.locator("footer").textContent().catch(() => ""); if (/个网格/.test(footer ?? "")) break; } const options = await select.locator("option").allTextContents(); result.steps.push({ step: "panel", options: options.length, footer: await panel.locator("footer").textContent() }); await select.selectOption({ label: "地面与地线" }); let ground = ""; for (let attempt = 0; attempt < 80; attempt++) { await page.waitForTimeout(500); ground = await panel.locator("footer").textContent().catch(() => ""); if (/4\.8[0-9]/.test(ground ?? "")) break; } result.steps.push({ step: "ground", footer: ground }); await panel.screenshot({ path: shot }); result.options = options.length; result.groundFooter = ground; result.ok = options.length === 27 && /4\.8[0-9] × 3\.6[0-9] × 0\.3[0-9]/.test(ground ?? "") && errors.length === 0 && consoleErrors.length === 0; } catch (error) { result.error = String(error?.stack ?? error); } finally { result.pageErrors = errors; result.consoleErrors = consoleErrors; result.screenshot = shot; const evidenceDir = path.join(here, "..", "evidence", "p0"); fs.mkdirSync(evidenceDir, { recursive: true }); fs.writeFileSync(path.join(evidenceDir, "reference-smoke.json"), `${JSON.stringify(result, null, 2)}\n`); console.log(JSON.stringify(result, null, 2)); await browser.close(); }