Files
FreeCADWasmDev/tools/web-freecad-functional-suite.mjs
wangdequan facbb196d8 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>
2026-11-24 22:09:42 +08:00

99 lines
4.1 KiB
JavaScript

#!/usr/bin/env node
// Headed Web FreeCAD functional suite.
// node tools/web-freecad-functional-suite.mjs --priority P0
// See tools/functional-suite/cli.mjs for the full option contract.
import fs from "node:fs";
import path from "node:path";
import { parseArgs, selectCases, USAGE } from "./functional-suite/cli.mjs";
import { allCases } from "./functional-suite/cases/index.mjs";
import { createRunContext, finalize, newRunDir, persist, pruneRuns, writeManifest } from "./functional-suite/report.mjs";
import { openBrowser, openPage, resetState, root, runCase, startHost } from "./functional-suite/runtime.mjs";
import { runLegacyCases } from "./functional-suite/executors/legacy.mjs";
const options = parseArgs();
if (options.help) { console.log(USAGE); process.exit(0); }
const selected = selectCases(allCases(), options);
if (!selected.length) { console.error("no cases selected"); process.exit(2); }
const base = options.out ? path.resolve(options.out) : path.join(root, "docs", "current", "web-functional-suite");
const output = newRunDir(base, options.resume);
let previous = [];
if (options.resume) {
const resultsFile = path.join(output, "results.json");
if (fs.existsSync(resultsFile)) {
const payload = JSON.parse(fs.readFileSync(resultsFile, "utf8"));
previous = (payload.results ?? []).filter(item => item.status !== "running");
}
}
const completed = new Map(previous.map(item => [item.id, item]));
let host;
let browser;
let session;
const ctx = createRunContext({ options, root, output, origin: "" });
const shutdown = async () => {
try { await session?.context.close(); } catch { /* already closed */ }
try { await browser?.close(); } catch { /* already closed */ }
try { host?.close(); } catch { /* already closed */ }
};
try {
host = await startHost();
ctx.origin = host.origin;
browser = await openBrowser(options);
session = await openPage(browser, ctx);
ctx.session = session;
writeManifest(ctx, {
chrome: browser.version(),
cases: selected.map(item => ({ id: item.id, priority: item.priority, executor: item.executor })),
disk: { dist: path.relative(root, path.join(root, "web", "dist")) },
});
for (const definition of selected) {
const prior = completed.get(definition.id);
if (prior && !options.force) {
ctx.results.push(prior);
persist(ctx);
console.log(`${definition.id}: skipped (resume, ${prior.status})`);
continue;
}
try {
await resetState(session.page, ctx.origin);
// Errors are a per-case assertion, so previous cases must not leak in.
session.pageErrors.length = 0;
session.consoleErrors.length = 0;
} catch (error) {
// A broken page cannot host the next case; surface it on the case record.
const failed = { id: definition.id, title: definition.title, priority: definition.priority, executor: definition.executor, status: "blocked", classification: "precondition", failureClass: "fixture", steps: [], seconds: 0, error: `resetState failed: ${String(error?.message ?? error)}`, startedAt: new Date().toISOString(), artifacts: {} };
ctx.results.push(failed);
ctx.gaps.push({ caseId: definition.id, status: "blocked", classification: "precondition", failureClass: "fixture", message: failed.error, evidence: "" });
persist(ctx);
console.log(`${definition.id}: blocked (resetState failed)`);
continue;
}
await runCase(session.page, definition, ctx);
}
if (options.legacyIds.length) {
const results = await runLegacyCases(options, ctx, { base });
console.log(`legacy: ${results.length} case(s) imported`);
}
finalize(ctx);
if (options.prune) pruneRuns(base, options.prune);
} catch (error) {
fs.mkdirSync(output, { recursive: true });
fs.writeFileSync(path.join(output, "fatal.json"), `${JSON.stringify({ at: new Date().toISOString(), error: String(error?.stack ?? error) }, null, 2)}\n`);
console.error(`fatal: ${String(error?.message ?? error)}`);
process.exitCode = 1;
} finally {
await shutdown();
}
const counts = ctx.counts;
console.log(JSON.stringify({ output, counts, gaps: ctx.gaps.length }));
if (counts.failed > 0 || counts.running > 0) process.exitCode = 1;