feat(web): panel scroll contract, layout probe and functional suite
- lock the three-column height chain on workbench/PartDesign pages so each side panel scrolls independently and the centre stage keeps its size - dock module task panels above the layout with their own scrollbar instead of letting them push the stage out of the viewport - add tools/layout-probe.mjs (page scroll, aside bounds, pane scrolling, stage stability) and CLI mode for tools/static-host.mjs with relative --root support - add the P0-P4 browser functional suite, manual scenarios and capture tooling; document it under docs/current/web-functional-suite Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
112
tools/functional-suite/cases/modules.mjs
Normal file
112
tools/functional-suite/cases/modules.mjs
Normal file
@@ -0,0 +1,112 @@
|
||||
// P2 module smoke: every registered module must load its shell, expose its
|
||||
// command surface and answer one canonical worker command.
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { root } from "../runtime.mjs";
|
||||
import { blockedPrecondition } from "../gap-ledger.mjs";
|
||||
import { dismissStartWorkspace, openRoute } from "../runtime.mjs";
|
||||
|
||||
const REGISTRY = path.join(root, "docs", "current", "feature-capability-registry.json");
|
||||
// Web FreeCAD ships without OpenSCAD (project iron rule) and AddonManager has no
|
||||
// interactive command, so neither is a functional module under test here.
|
||||
const SKIP = new Set(["OpenSCAD", "AddonManager"]);
|
||||
// Read-only commands come first: they exercise worker + registry without
|
||||
// depending on selection state or parameters, so a failure means the module
|
||||
// really is broken rather than under-specified by the smoke.
|
||||
const PREFERRED_SUFFIXES = ["inspectSourceInventory", "inspectPythonApi", "inspectRegistry", "pythonApi", "measurementApi", "navigationBoundary", "serverContract", "createRecompute"];
|
||||
// The Web module has no worker route for serverContract (browser-native module);
|
||||
// its persistence boundary command is the one that actually dispatches.
|
||||
const CANONICAL_OVERRIDES = { Web: "web.saveReopenBoundary" };
|
||||
|
||||
function loadModules() {
|
||||
const registry = JSON.parse(fs.readFileSync(REGISTRY, "utf8"));
|
||||
const byModule = new Map();
|
||||
for (const record of registry.records) {
|
||||
if (!byModule.has(record.module)) byModule.set(record.module, []);
|
||||
byModule.get(record.module).push(record);
|
||||
}
|
||||
const modules = [];
|
||||
for (const meta of registry.modules) {
|
||||
if (SKIP.has(meta.module)) continue;
|
||||
const records = byModule.get(meta.module) ?? [];
|
||||
const interactive = records.filter(record => record.uiStatus === "interactive" && record.implementationStatus === "routed");
|
||||
const override = CANONICAL_OVERRIDES[meta.module];
|
||||
const canonical = (override ? interactive.find(record => record.command === override) : null)
|
||||
?? PREFERRED_SUFFIXES.map(suffix => interactive.find(record => record.command.endsWith(suffix))).find(Boolean)
|
||||
?? interactive[0] ?? null;
|
||||
modules.push({ name: meta.module, interactive: interactive.length, canonical: canonical?.command ?? null });
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
||||
export const MODULES = loadModules();
|
||||
|
||||
const escapeRe = text => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
|
||||
export async function selectModule(page, name) {
|
||||
// Anchor the match: "Part" is a substring of "MeshPart" and "PartDesign".
|
||||
const exact = new RegExp(`^\\s*${escapeRe(name)}\\s*$`);
|
||||
const button = page.locator("button.module").filter({ has: page.locator("strong", { hasText: exact }) }).first();
|
||||
if (!(await button.count())) throw blockedPrecondition("entry", `module ${name} is not exposed in the module dock`);
|
||||
await button.click();
|
||||
// Module labels are capitalised ("Assembly") while command ids are lowercase
|
||||
// ("assembly.createRecompute"), so compare case-insensitively.
|
||||
await page.waitForFunction(expected => [...document.querySelectorAll("button.command span")].some(span => String(span.textContent).toLowerCase().startsWith(`${expected}.`)), name.toLowerCase(), { timeout: 60000 });
|
||||
}
|
||||
|
||||
export async function runCommand(page, name) {
|
||||
const exact = new RegExp(`^\\s*${escapeRe(name)}\\s*$`);
|
||||
const command = page.locator("button.command").filter({ has: page.locator("span", { hasText: exact }) }).first();
|
||||
await command.waitFor({ state: "visible", timeout: 60000 });
|
||||
await command.click();
|
||||
// The panel prefills the payload the worker expects; overwriting it with "{}"
|
||||
// is what makes an otherwise valid command fail with invalid_request.
|
||||
const args = page.getByLabel("命令 JSON 参数");
|
||||
let payload = "";
|
||||
if (await args.count()) {
|
||||
payload = (await args.inputValue()).trim();
|
||||
if (!payload) { payload = "{}"; await args.fill(payload); }
|
||||
}
|
||||
const run = page.getByRole("button", { name: "执行选中命令", exact: true });
|
||||
await run.waitFor({ state: "visible", timeout: 30000 });
|
||||
await run.click();
|
||||
await page.waitForFunction(() => window.__freecadWorkbenchState?.response?.kind === "result" || window.__freecadWorkbenchState?.response?.kind === "error", null, { timeout: 180000 });
|
||||
return page.evaluate(() => window.__freecadWorkbenchState.response);
|
||||
}
|
||||
|
||||
export const moduleCases = MODULES.map(meta => ({
|
||||
id: `MOD-${meta.name}-01`,
|
||||
title: `${meta.name} 模块冒烟:壳层、命令面与规范动作`,
|
||||
priority: "P2",
|
||||
executor: "functional",
|
||||
module: meta.name,
|
||||
source: "feature-capability-registry.json",
|
||||
timeoutMs: 240000,
|
||||
async run({ page, origin, step }) {
|
||||
await step("打开模块工作台", "模块壳层挂载且隔离头生效", async () => {
|
||||
const isolation = await openRoute(page, { origin }, `/workbench.html?module=${encodeURIComponent(meta.name)}`);
|
||||
await dismissStartWorkspace(page);
|
||||
return isolation;
|
||||
});
|
||||
await step(`${meta.name} 模块在模块坞中可选中`, "button.module 存在且被选中", async () => {
|
||||
await selectModule(page, meta.name);
|
||||
const selected = await page.evaluate(() => document.querySelector("button.module[aria-current], button.module.selected")?.textContent?.trim().slice(0, 40) ?? null);
|
||||
return { module: meta.name, selected };
|
||||
});
|
||||
await step("命令面已注册", "该模块至少注册一条命令", async () => {
|
||||
await page.waitForFunction(() => document.querySelectorAll("button.command").length > 0, null, { timeout: 60000 });
|
||||
const count = await page.locator("button.command").count();
|
||||
if (count < 1) throw new Error(`${meta.name} exposes no commands`);
|
||||
return { commands: count, registered: meta.interactive };
|
||||
});
|
||||
if (!meta.canonical) throw blockedPrecondition("command-state", `${meta.name} has no interactive routed command`);
|
||||
await step(`规范动作 ${meta.canonical}`, "原生返回 kind=result 且无 sceneError", async () => {
|
||||
const response = await runCommand(page, meta.canonical);
|
||||
if (response?.kind === "error") throw new Error(`command error: ${JSON.stringify(response.error).slice(0, 300)}`);
|
||||
const row = response?.result?.records?.[0];
|
||||
const result = row?.result ?? response?.result;
|
||||
if (result?.sceneError) throw new Error(`scene refresh failed: ${result.sceneError}`);
|
||||
return { kind: response?.kind, command: meta.canonical, hasRow: Boolean(row) };
|
||||
});
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user