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:
2026-11-24 22:09:42 +08:00
parent c3b3160f33
commit facbb196d8
47 changed files with 6813 additions and 247 deletions

View File

@@ -0,0 +1,202 @@
// P0 shell cases: entry/isolation, project shell, first document, OPFS contract,
// viewport and canvas. These are the preconditions every later case builds on.
import { assertNoPageErrors, prepareProjectShell, prepareWorkbenchShell } from "../../ui-parity-preflight.mjs";
import { VIEWPORT, canvasHash, dismissStartWorkspace, openRoute, pageState } from "../runtime.mjs";
const fail = message => { throw new Error(message); };
export async function waitCubeEnabled(page, timeout = 120000) {
await page.waitForFunction(() => {
const toolbar = document.querySelector('[role="toolbar"][aria-label="Solids"]');
const button = toolbar ? [...toolbar.querySelectorAll("button")].find(node => node.getAttribute("aria-label") === "Cube") : undefined;
return Boolean(button && !button.disabled);
}, null, { timeout });
}
// The application menu is a <details>/<summary> list, so the item buttons are
// not visible until their own menu is opened — role locators never match them.
export async function openFileMenu(page) {
const menu = page.locator("nav.application-menus details").filter({ has: page.locator("button.action", { hasText: "新建 Document" }) }).first();
if (!(await menu.count())) fail("File menu not found");
await menu.locator("summary").first().click();
await page.waitForTimeout(200);
return menu;
}
export async function closeTaskPanel(page) {
if (await page.locator('fieldset[aria-label="Task: Box dimensions"]').count()) await page.keyboard.press("Escape");
await page.waitForTimeout(300);
}
export async function closeStartDialog(page) {
for (let attempt = 0; attempt < 20; attempt += 1) {
if (await page.locator("dialog[open]").count()) { await page.keyboard.press("Escape"); await page.waitForTimeout(250); continue; }
await page.waitForTimeout(300);
if ((await page.locator("dialog[open]").count()) === 0) return;
}
}
export const shellCases = [
{
id: "SHELL-01",
title: "入口、COOP/COEP 隔离与工作台壳层",
priority: "P0",
executor: "functional",
source: "manual ch00/ch01",
timeoutMs: 120000,
async run({ page, origin, step, ctx }) {
await step("打开 Part 工作台并确认隔离头生效", "crossOriginIsolated 且 SharedArrayBuffer 可用", async () => {
const isolation = await openRoute(page, { origin }, "/workbench.html?module=Part");
return isolation;
});
await step("工作台壳层可见且无横向溢出", ".dock-workbench 可测量、在视口内", async () => {
const { state } = await prepareWorkbenchShell(page, { origin, path: "/workbench.html?module=Part", viewport: VIEWPORT });
return state;
});
await step("页面无未捕获错误", "pageerror 为空", async () => {
assertNoPageErrors(ctx.session.pageErrors);
return { pageErrors: 0 };
});
},
},
{
id: "SHELL-02",
title: "工程壳层与 Start 对话框",
priority: "P0",
executor: "functional",
source: "manual ch01",
timeoutMs: 120000,
async run({ page, origin, step, ctx }) {
await step("打开工程页并确认工具栏就绪", ".desktop-workspace 与 Solids 工具栏可见", async () => {
const { state } = await prepareProjectShell(page, { origin, path: "/project.html", viewport: VIEWPORT, toolbarName: "Solids", minDropdowns: 0 });
return state;
});
await step("Start 对话框可关闭且不拦截操作", "dialog[open] 数量为 0", async () => {
await closeStartDialog(page);
await dismissStartWorkspace(page);
const open = await page.locator("dialog[open]").count();
if (open) fail(`Start dialog still open: ${open}`);
return { openDialogs: 0 };
});
await step("工具栏图标全部渲染", "img 均 complete 且 naturalWidth > 0", async () => {
// SVG icons 404/sniff-blocked by a wrong static-host MIME show up here
// as naturalWidth === 0 while still returning HTTP 200.
const icons = await page.evaluate(() => ({ total: document.images.length, broken: [...document.images].filter(image => !image.complete || image.naturalWidth === 0).map(image => image.getAttribute("src")).slice(0, 10) }));
if (!icons.total) fail("no icon images rendered");
if (icons.broken.length) fail(`broken icons: ${icons.broken.join(", ")}`);
return icons;
});
await step("页面无未捕获错误", "pageerror 为空", async () => {
assertNoPageErrors(ctx.session.pageErrors);
return { pageErrors: 0 };
});
},
},
{
id: "SHELL-03",
title: "新建文档、创建 Cube 并显示体积",
priority: "P0",
executor: "functional",
source: "manual ch01/ch02",
timeoutMs: 240000,
async run({ page, origin, step, ctx }) {
await step("关闭 Start 并新建 Document", "Solids/Cube 命令可用", async () => {
await openRoute(page, { origin }, "/project.html", { dismissStart: true });
await closeStartDialog(page);
const menu = await openFileMenu(page);
await menu.locator("button.action", { hasText: "新建 Document" }).first().click();
await waitCubeEnabled(page);
await closeStartDialog(page);
return { cubeEnabled: true };
});
await step("执行 Cube 命令", "文档树出现对象且体积为 1000 mm³(默认 10mm 立方体)", async () => {
await waitCubeEnabled(page);
await page.getByRole("toolbar", { name: "Solids" }).getByRole("button", { name: "Cube", exact: true }).click();
await closeTaskPanel(page);
await page.waitForFunction(() => parseFloat(document.querySelector("[data-native-volume]")?.textContent ?? "") > 0, null, { timeout: 120000 });
const volume = await page.evaluate(() => parseFloat(document.querySelector("[data-native-volume]")?.textContent ?? ""));
const tree = await page.evaluate(() => [...document.querySelectorAll('[role="treeitem"]')].map(node => node.textContent.trim()));
if (tree.length < 1) fail("document tree is empty after Cube");
if (Math.abs(volume - 1000) > 1e-6) fail(`volume ${volume} != 1000`);
return { volume, tree: tree.slice(0, 5) };
});
await step("页面无未捕获错误", "pageerror 为空", async () => {
assertNoPageErrors(ctx.session.pageErrors);
return { pageErrors: 0 };
});
},
},
{
id: "SHELL-04",
title: "OPFS 导出目录可写可读",
priority: "P0",
executor: "functional",
source: "OPFS contract (web/src/storage.ts:67)",
timeoutMs: 60000,
async run({ page, origin, step }) {
await step("进入同源页面", "应用挂载", async () => {
await openRoute(page, { origin }, "/workbench.html?module=Part");
return true;
});
await step("freecad-exports 目录写入、列出、回读、删除", "四步全部成功", async () => {
const result = await page.evaluate(async () => {
const name = `functional-suite-probe-${Date.now()}.txt`;
const payload = new TextEncoder().encode("freecad-web-suite");
const rootDir = await navigator.storage.getDirectory();
const exportsDir = await rootDir.getDirectoryHandle("freecad-exports", { create: true });
const handle = await exportsDir.getFileHandle(name, { create: true });
const writer = await handle.createWritable();
await writer.write(payload);
await writer.close();
const names = [];
for await (const [entry] of exportsDir.entries()) names.push(entry);
const text = await (await (await exportsDir.getFileHandle(name)).getFile()).text();
await exportsDir.removeEntry(name);
const after = [];
for await (const [entry] of exportsDir.entries()) after.push(entry);
return { bytes: payload.byteLength, listed: names.includes(name), text, removed: !after.includes(name) };
});
if (!result.listed) fail("probe file missing from listing");
if (result.text !== "freecad-web-suite") fail(`read-back mismatch: ${result.text}`);
if (!result.removed) fail("probe file was not removed");
return result;
});
},
},
{
id: "SHELL-05",
title: "视口尺寸、画布与场景渲染",
priority: "P0",
executor: "functional",
source: "manual ch01 viewport",
timeoutMs: 120000,
async run({ page, origin, step, ctx }) {
// The 3D canvas lives in the project shell; the module shell only renders
// the command browser (no canvas by design, verified in the DOM probe).
await step("打开工程页并确认视口", "1440x1000 且无横向溢出", async () => {
await openRoute(page, { origin }, "/project.html", { dismissStart: true });
const state = await page.evaluate(() => ({
width: innerWidth, height: innerHeight,
overflow: document.documentElement.scrollWidth > document.documentElement.clientWidth,
}));
if (state.width !== VIEWPORT.width || state.height !== VIEWPORT.height) fail(`viewport ${state.width}x${state.height}`);
if (state.overflow) fail("horizontal overflow");
return state;
});
await step("画布存在且有内容", "canvas 尺寸非零、截图 hash 非空", async () => {
const canvases = await page.evaluate(() => [...document.querySelectorAll("canvas")].map(canvas => ({ width: canvas.width, height: canvas.height })));
if (!canvases.length) fail("no canvas");
if (!canvases.some(item => item.width > 0 && item.height > 0)) fail("canvas has zero size");
const hash = await canvasHash(page);
if (!hash || hash.bytes < 1024) fail(`canvas screenshot too small: ${hash?.bytes ?? 0}`);
return { canvases, hash };
});
await step("页面无未捕获错误", "pageerror 为空", async () => {
assertNoPageErrors(ctx.session.pageErrors);
return { pageErrors: 0 };
});
},
},
];
export { pageState };