Remove the leftover localOnly gate and run pasted multi-statement blocks via exec. Verified version output and a multi-line cube-add snippet updating Main. Co-Authored-By: Claude Code <noreply@anthropic.com>
51 lines
2.3 KiB
JavaScript
51 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Focused case: Scripting -> Python Console executes embedded WebEngine Python.
|
|
*
|
|
* node tools/web/complete/probe-python-console.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(90_000);
|
|
const log = (...parts) => console.log(new Date().toISOString().slice(11, 19), ...parts);
|
|
const state = async () => page.evaluate(() => {
|
|
const consoleRoot = document.querySelector('[aria-label="Python Console"]');
|
|
return {
|
|
output: consoleRoot?.querySelector('pre')?.textContent?.slice(-400) ?? null,
|
|
stats: document.querySelector('[data-testid="scene-stats"]')?.textContent ?? "",
|
|
status: document.querySelector('[data-testid="engine-status"]')?.textContent ?? "",
|
|
};
|
|
});
|
|
const run = async (source) => {
|
|
const consoleRoot = page.locator('[aria-label="Python Console"]').first();
|
|
const input = consoleRoot.getByRole("textbox", { name: "Python 输入", exact: true });
|
|
await input.fill(source);
|
|
await input.press("Enter");
|
|
for (let index = 0; index < 120; index++) {
|
|
await page.waitForTimeout(500);
|
|
const current = await state();
|
|
if (current.output && current.output.includes("PROBE_DONE")) { return current; }
|
|
if (index === 119) return current;
|
|
}
|
|
return await state();
|
|
};
|
|
try {
|
|
await openFile(page, ASSETS.studio);
|
|
await waitScene(page, { objects: 6, timeout: 240_000 });
|
|
await switchWorkspace(page, "Scripting");
|
|
await page.locator('[aria-label="Python Console"]').first().waitFor({ timeout: 30_000 });
|
|
log("version", JSON.stringify(await run("import bpy\nprint('PROBE_DONE', bpy.app.version_string)")));
|
|
log("cube", JSON.stringify(await run("import bpy\nbpy.ops.mesh.primitive_cube_add()\nprint('PROBE_DONE', len(bpy.data.objects))")));
|
|
} 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(-8)));
|
|
await context.close();
|
|
await browser.close();
|
|
}
|