#!/usr/bin/env node /** * Focused case: Add menu -> Mesh -> Circle/Grid/Monkey through the product * ?ui=web entry, then undo/redo. Evidence only; no assertions. * * node tools/web/complete/probe-add-menu.mjs --base-url http://127.0.0.1:5176 */ import { ASSETS, parseArgs, launchBrowser, newPage, openFile, waitScene, switchWorkspace } 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(60_000); const log = (...parts) => console.log(new Date().toISOString().slice(11, 19), ...parts); const stats = async () => page.evaluate(() => ({ stats: document.querySelector('[data-testid="scene-stats"]')?.textContent ?? "", status: document.querySelector('[data-testid="engine-status"]')?.textContent ?? "", output: document.querySelector(".native-workflow-output")?.textContent ?? "", alerts: Array.from(document.querySelectorAll('[role="alert"]')).map((node) => node.textContent).slice(0, 3), })); const count = async () => Number((await stats()).stats.match(/Objects\s+(\d+)/)?.[1] ?? -1); const waitCount = async (expected) => { const deadline = Date.now() + 90_000; while (Date.now() < deadline) { if (await count() === expected) return true; await page.waitForTimeout(250); } return false; }; const addAt = async (label) => { await page.getByRole("button", { name: "添加", exact: true }).click(); await page.getByRole("menuitem", { name: "网格", exact: true }).click(); await page.getByRole("menuitem", { name: label, exact: true }).click(); }; const editMenu = async (label) => { await page.getByRole("button", { name: "编辑", exact: true }).click(); await page.getByRole("menuitem", { name: label, exact: true }).click(); }; try { await switchWorkspace(page, "Layout"); await openFile(page, ASSETS.studio); await waitScene(page, { objects: 6, timeout: 240_000 }); let expected = await count(); log("start", JSON.stringify(await stats())); for (const label of ["圆环", "栅格", "猴头"]) { await addAt(label); expected += 1; const ok = await waitCount(expected); log(`add ${label}`, ok ? "OK" : "MISS", JSON.stringify(await stats())); } await editMenu("撤销"); log("undo", await waitCount(expected - 1), JSON.stringify(await stats())); await editMenu("重做"); log("redo", await waitCount(expected), JSON.stringify(await stats())); } catch (error) { log("probe error", error instanceof Error ? error.message : String(error)); log("state", JSON.stringify(await stats().catch(() => null))); } finally { log("consoleErrors", JSON.stringify(consoleErrors.slice(-20))); await context.close(); await browser.close(); }