#!/usr/bin/env node /** * Focused case: edit mode -> select all -> extrude on the studio ground mesh, * then undo. * * node tools/web/complete/probe-mesh-edit.mjs --base-url http://127.0.0.1:5176 */ import { ASSETS, parseArgs, launchBrowser, newPage, openFile, waitScene } from "../course/lib/lesson-recorder.mjs"; const args = parseArgs(); const BASE = args.baseUrl || "http://127.0.0.1:5176"; const browser = await launchBrowser(args.gpu); const { context, page, consoleErrors } = await newPage(browser, { baseUrl: BASE }); page.setDefaultTimeout(90_000); const log = (...parts) => console.log(new Date().toISOString().slice(11, 19), ...parts); const state = async () => page.evaluate(() => ({ stats: document.querySelector('[data-testid="scene-stats"]')?.textContent ?? "", status: document.querySelector('[data-testid="engine-status"]')?.textContent ?? "", alerts: Array.from(document.querySelectorAll('[role="alert"]')).map((node) => node.textContent).slice(0, 3), mode: document.querySelector('.mode-chip button')?.textContent ?? "", selected: document.querySelector('[data-testid="mesh-selection"]')?.textContent ?? "", })); const enterEdit = async () => { await page.getByRole("button", { name: "操作搜索", exact: true }).click(); await page.getByRole("textbox", { name: "搜索 Blender 操作" }).fill("Enter Edit Mode"); await page.waitForTimeout(400); await page.getByRole("textbox", { name: "搜索 Blender 操作" }).press("Enter"); const deadline = Date.now() + 60_000; while (Date.now() < deadline && !/Edit/i.test((await state()).mode)) await page.waitForTimeout(250); }; const menu = async (label, item) => { await page.getByRole("button", { name: label, exact: true }).click(); await page.getByRole("menuitem", { name: item, exact: true }).click(); }; try { await openFile(page, ASSETS.studio); await waitScene(page, { objects: 6, timeout: 240_000 }); await enterEdit(); log("edit", JSON.stringify(await state())); await menu("选择", "全部"); await page.waitForTimeout(1000); log("selected", JSON.stringify(await state())); await menu("网格", "挤出"); for (let index = 0; index < 40; index++) { await page.waitForTimeout(500); const current = await state(); if (!/Vertices 4 /.test(current.stats) || current.alerts.length) { log("extruded", JSON.stringify(current)); break; } if (index === 39) log("extrude timeout", JSON.stringify(current)); } await menu("编辑", "撤销"); for (let index = 0; index < 20; index++) { await page.waitForTimeout(500); const current = await state(); if (/Vertices 4 /.test(current.stats)) { log("undone", JSON.stringify(current)); break; } if (index === 19) log("undo timeout", JSON.stringify(current)); } } catch (error) { log("probe error", error instanceof Error ? error.message : String(error)); log("state", JSON.stringify(await state().catch(() => null))); } finally { log("consoleErrors", JSON.stringify(consoleErrors.slice(-12))); await context.close(); await browser.close(); }