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

@@ -4,10 +4,9 @@
// node capture.mjs --scenario ../../manual/scenarios/ch01-ui.json [--headed]
import fs from "node:fs";
import path from "node:path";
import { createHash } from "node:crypto";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
import { listOpfsFiles, readOpfsFile, seedOpfsFromBytes } from "../carrier-course/lib/opfs.mjs";
import { createActionRunner } from "./lib/actions.mjs";
const here = path.dirname(fileURLToPath(import.meta.url));
const webRoot = path.resolve(here, "../..");
@@ -31,8 +30,6 @@ const reportDir = path.join(webRoot, "manual", "data", "capture");
fs.mkdirSync(shotDir, { recursive: true });
fs.mkdirSync(reportDir, { recursive: true });
const sha256 = file => createHash("sha256").update(fs.readFileSync(file)).digest("hex");
async function runOnce() {
const browser = await chromium.launch({
executablePath: "/usr/bin/google-chrome",
@@ -47,167 +44,23 @@ async function runOnce() {
page.on("console", message => { if (message.type() === "error") consoleErrors.push(message.text().slice(0, 300)); });
const trace = [];
const shots = [];
const record = entry => trace.push({ at: new Date().toISOString(), ...entry });
const click = async action => {
let locator;
if (action.role) locator = page.getByRole(action.role, { name: action.name, exact: action.exact });
else {
locator = page.locator(action.selector);
if (action.hasText) locator = locator.filter({ hasText: action.hasText });
if (action.target) locator = locator.locator(action.target);
}
if (action.nth !== undefined) locator = locator.nth(action.nth);
else if (!action.all) locator = locator.first();
if (action.optional && (await locator.count()) === 0) return;
if (action.all) {
const count = await locator.count();
for (let index = 0; index < count; index++) await locator.nth(index).click();
} else await locator.click({ timeout: action.timeout ?? 30000 });
};
const shot = async action => {
const file = path.join(shotDir, `${action.name}.png`);
if (action.selector) {
const target = page.locator(action.selector).first();
await target.waitFor({ state: "visible", timeout: 30000 });
await target.screenshot({ path: file });
} else {
await page.screenshot({ path: file, fullPage: Boolean(action.fullPage) });
}
const stat = fs.statSync(file);
if (stat.size < 1024) throw new Error(`screenshot too small: ${file}`);
shots.push({ id: `${chapter}/${workflow}/${action.name}`, file: path.relative(webRoot, file),
bytes: stat.size, sha256: sha256(file), fullPage: Boolean(action.fullPage), selector: action.selector ?? null });
record({ action: "shot", name: action.name, bytes: stat.size });
};
const save = async action => {
await page.evaluate(() => { const details = document.querySelector(".file-tools"); if (details) details.open = true; });
await page.waitForTimeout(400);
const before = await listOpfsFiles(page);
await page.locator('button:has-text("保存 FCStd 到 OPFS")').first().click();
let after = before; let status = "";
for (let attempt = 0; attempt < 40; attempt++) {
await page.waitForTimeout(750);
after = await listOpfsFiles(page);
status = await page.locator("p.status").first().textContent().catch(() => "");
if (after.some(name => !before.includes(name) && /\.FCStd$/i.test(name)) || /Saved\s+\S+\.FCStd\s+to OPFS/i.test(status ?? "")) break;
}
const match = /Saved\s+(\S+\.FCStd)\s+to OPFS/i.exec(status ?? "");
const name = match?.[1] ?? after.find(item => !before.includes(item) && /\.FCStd$/i.test(item));
if (!name) throw new Error(`save produced no FCStd; status=${status}`);
const bytes = (await readOpfsFile(page, name)).bytes;
const fixture = path.join(webRoot, "manual", "fixtures", `${chapter}-${workflow}.FCStd`);
fs.mkdirSync(path.dirname(fixture), { recursive: true });
fs.writeFileSync(fixture, Buffer.from(bytes));
record({ action: "save", name, bytes: bytes.length, status });
};
// The action interpreter is shared with the headed functional suite; only the
// evidence destinations and the record sink differ.
const runner = createActionRunner(page, {
origin, shotDir, shotPrefix: `${chapter}/${workflow}/`, record, shotIndex: shots,
fixturePath: path.join(webRoot, "manual", "fixtures", `${chapter}-${workflow}.FCStd`),
});
try {
for (const action of scenario.actions) {
switch (action.type) {
case "goto":
await page.goto(`${origin}${action.url}`, { waitUntil: "domcontentloaded", timeout: 120000 });
record({ action: "goto", url: action.url });
break;
case "waitFor":
if (action.selector) await page.waitForSelector(action.selector, { timeout: action.timeout ?? 120000 });
if (action.text) await page.getByText(action.text, { exact: action.exact ?? false }).first()
.waitFor({ state: "visible", timeout: action.timeout ?? 120000 });
record({ action: "waitFor", selector: action.selector ?? null, text: action.text ?? null });
break;
case "click": await click(action); record({ action: "click", selector: action.selector ?? action.name }); break;
case "fill":
await page.locator(action.selector).first().fill(String(action.value));
record({ action: "fill", selector: action.selector, value: action.value });
break;
case "select":
await page.locator(action.selector).first().selectOption(action.label ? { label: action.label } : action.value);
record({ action: "select", selector: action.selector, label: action.label ?? action.value });
break;
case "selectIndex":
await page.locator(action.selector).first().selectOption({ index: action.index });
record({ action: "selectIndex", selector: action.selector, index: action.index });
break;
case "press": await page.keyboard.press(action.key); record({ action: "press", key: action.key }); break;
case "clickCanvas": {
const target = page.locator(action.selector).first();
await target.scrollIntoViewIfNeeded();
await page.waitForTimeout(200);
const box = await target.boundingBox();
if (!box) throw new Error(`canvas missing: ${action.selector}`);
await page.mouse.click(box.x + box.width * action.fx, box.y + box.height * action.fy);
await page.waitForTimeout(action.wait ?? 250);
record({ action: "clickCanvas", selector: action.selector, fx: action.fx, fy: action.fy });
break;
}
case "assertAnyText": {
const texts = await page.locator(action.selector).allTextContents();
if (!texts.some(text => String(text).includes(action.contains)))
throw new Error(`assertAnyText failed: ${action.contains} in ${JSON.stringify(texts.slice(0, 5))}`);
record({ action: "assertAnyText", selector: action.selector, contains: action.contains });
break;
}
case "drag": {
const box = await page.locator(action.selector).first().boundingBox();
if (!box) throw new Error(`drag target missing: ${action.selector}`);
const x = box.x + box.width / 2; const y = box.y + box.height / 2;
await page.mouse.move(x, y); await page.mouse.down();
await page.mouse.move(x + (action.dx ?? 0), y + (action.dy ?? 0), { steps: 18 });
await page.mouse.up(); await page.waitForTimeout(400);
record({ action: "drag", selector: action.selector, dx: action.dx, dy: action.dy });
break;
}
case "eval":
await page.evaluate(action.script);
record({ action: "eval" });
break;
case "seed": {
const file = path.resolve(action.file);
if (!fs.existsSync(file)) throw new Error(`seed fixture missing: ${file}`);
await seedOpfsFromBytes(page, action.name ?? path.basename(file), fs.readFileSync(file));
record({ action: "seed", file, name: action.name ?? path.basename(file) });
break;
}
case "shot": await shot(action); break;
case "save": await save(action); break;
case "assertText": {
const text = await page.locator(action.selector).first().textContent();
if (!String(text ?? "").includes(action.contains)) throw new Error(`assertText failed: ${action.selector} ${text}`);
record({ action: "assertText", selector: action.selector, contains: action.contains });
break;
}
case "assertVisible":
await page.locator(action.selector).first().waitFor({ state: "visible", timeout: 30000 });
record({ action: "assertVisible", selector: action.selector });
break;
case "waitOptions": {
const locator = page.locator(action.selector).first();
let count = 0;
for (let attempt = 0; attempt < 80; attempt++) {
count = await locator.locator("option").count();
if (count >= (action.min ?? 1)) break;
await page.waitForTimeout(500);
}
if (count < (action.min ?? 1)) throw new Error(`waitOptions failed: ${action.selector} ${count}`);
record({ action: "waitOptions", selector: action.selector, count });
break;
}
case "assertValue": {
const value = await page.locator(action.selector).first().inputValue();
if (String(value) !== String(action.value)) throw new Error(`assertValue failed: ${action.selector} ${value} != ${action.value}`);
record({ action: "assertValue", selector: action.selector, value });
break;
}
case "wait": await page.waitForTimeout(action.ms ?? 500); break;
default: throw new Error(`unknown action ${action.type}`);
}
}
for (const action of scenario.actions) await runner.run(action);
if (pageErrors.length || consoleErrors.length)
throw new Error(`page errors: ${JSON.stringify({ pageErrors, consoleErrors })}`);
const report = {
schema: "freecad-web-manual/capture/v1", generatedAt: new Date().toISOString(),
chapter, workflow, scenario: path.relative(webRoot, scenarioPath), origin,
ok: true, trace, shots, pageErrors, consoleErrors,
ok: true, trace, pageErrors, consoleErrors,
shots: shots.map(item => ({ ...item, file: path.relative(webRoot, item.file) })),
};
fs.writeFileSync(path.join(reportDir, `${chapter}-${workflow}.json`), `${JSON.stringify(report, null, 2)}\n`);
return report;