#!/usr/bin/env node /** * Focused case: F3 operator search executes a non-allowlisted desktop operator * (mesh.primitive_circle_add) in the ?ui=web entry. * * node tools/web/complete/probe-f3-operator.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(60_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, 4), palette: document.querySelector('[role="dialog"][aria-label="操作搜索"]') ? "open" : "closed", })); try { await openFile(page, ASSETS.studio); await waitScene(page, { objects: 6, timeout: 240_000 }); log("start", JSON.stringify(await state())); await page.getByRole("button", { name: "操作搜索", exact: true }).click(); await page.getByRole("textbox", { name: "搜索 Blender 操作" }).fill("primitive_circle_add"); await page.waitForTimeout(1500); const results = await page.evaluate(() => Array.from(document.querySelectorAll('.operator-search-results button')).map((node) => node.textContent)); log("results", JSON.stringify(results.slice(0, 8))); const target = page.locator('.operator-search-results button').filter({ hasText: "MESH_OT_primitive_circle_add [WEB_MAIN]" }).first(); if (!await target.count()) { log("no native result"); } else { await target.click(); await page.waitForTimeout(800); log("after select", JSON.stringify(await state())); const run = page.getByRole("button", { name: "执行", exact: true }); if (await run.count()) { await run.click(); } else { log("no execute button"); } for (let index = 0; index < 12; index++) { await page.waitForTimeout(500); const current = await state(); if (/Objects\s+7\b/.test(current.stats) || current.alerts.length) { log("result", JSON.stringify(current)); break; } if (index === 11) log("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(); }