Files
FreeCADWasmDev/tools/functional-suite/report.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

127 lines
6.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Run artefacts: manifest, results, checkpoint, markdown/JUnit/HTML reports.
import fs from "node:fs";
import path from "node:path";
import { renderGapSections } from "./gap-ledger.mjs";
const ISO_STAMP = () => new Date().toISOString().replace(/[:.]/g, "-");
const esc = value => String(value ?? "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
export function createRunContext({ options, root, output, origin }) {
return {
schema: "freecad-web/functional-suite/v1",
root, output, origin,
startedAt: new Date().toISOString(),
updatedAt: null,
options,
results: [],
gaps: [],
counts: { passed: 0, failed: 0, blocked: 0, reference_only: 0, running: 0 },
manifest: {},
};
}
export function newRunDir(base, resume) {
if (resume) return path.resolve(resume);
const dir = path.join(base, `run-${ISO_STAMP()}`);
fs.mkdirSync(dir, { recursive: true });
return dir;
}
export function writeManifest(ctx, extra = {}) {
ctx.manifest = {
schema: "freecad-web/functional-suite-manifest/v1",
generatedAt: new Date().toISOString(),
origin: ctx.origin,
platform: process.platform,
node: process.version,
display: process.env.DISPLAY ?? null,
headless: ctx.options.headless,
command: process.argv.join(" "),
...extra,
};
fs.writeFileSync(path.join(ctx.output, "manifest.json"), `${JSON.stringify(ctx.manifest, null, 2)}\n`);
}
export function recount(ctx) {
const counts = { passed: 0, failed: 0, blocked: 0, reference_only: 0, running: 0 };
for (const result of ctx.results) counts[result.status] = (counts[result.status] ?? 0) + 1;
ctx.counts = counts;
return counts;
}
export function persist(ctx) {
ctx.updatedAt = new Date().toISOString();
recount(ctx);
fs.writeFileSync(path.join(ctx.output, "results.json"), `${JSON.stringify({
schema: ctx.schema, startedAt: ctx.startedAt, updatedAt: ctx.updatedAt, origin: ctx.origin,
headless: ctx.options.headless, counts: ctx.counts, results: ctx.results,
}, null, 2)}\n`);
const completed = ctx.results.filter(item => item.status !== "running").map(item => ({ id: item.id, status: item.status, seconds: item.seconds }));
fs.writeFileSync(path.join(ctx.output, "checkpoint.json"), `${JSON.stringify({
schema: "freecad-web/functional-suite-checkpoint/v1", updatedAt: ctx.updatedAt,
current: ctx.results.find(item => item.status === "running")?.id ?? null, completed,
}, null, 2)}\n`);
}
const statusCell = item => {
if (item.status === "passed") return "passed";
if (item.status === "blocked") return `blocked (${item.failureClass})`;
return `${item.status} (${item.classification})`;
};
export function writeMarkdown(ctx) {
const gaps = renderGapSections(ctx.gaps);
const rows = ctx.results.map(item =>
`| ${item.id} | ${item.priority} | ${statusCell(item)} | ${Number(item.seconds ?? 0).toFixed(1)}s | ${item.steps.length} | ${item.error ? item.error.slice(0, 120).replace(/\|/g, "\\|") : ""} |`);
return `# Web FreeCAD 功能测试(有头)\n\n` +
`- 运行:${ctx.startedAt}\n- Origin:${ctx.origin}\n- 模式:${ctx.options.headless ? "headless" : "headed"}\n` +
`- 计数:passed ${ctx.counts.passed} / failed ${ctx.counts.failed} / blocked ${ctx.counts.blocked} / reference_only ${ctx.counts.reference_only}\n\n` +
`## 用例\n\n| id | 优先级 | 状态 | 耗时 | 步骤 | 错误 |\n|---|---|---|---|---|---|\n${rows.join("\n")}\n\n` +
`## Blocked(前置未满足)\n\n${gaps.blocked}\n\n## Product(产品/UI 缺口)\n\n${gaps.product}\n`;
}
export function writeJUnit(ctx) {
const body = ctx.results.map(item => {
const time = Number(item.seconds ?? 0).toFixed(3);
const failure = item.status === "passed" ? "" :
item.status === "blocked"
? `\n <skipped message="${esc(item.failureClass)}: ${esc(item.error)}"/>`
: `\n <failure message="${esc(item.classification)}">${esc(item.error)}</failure>`;
return ` <testcase classname="${esc(item.priority)}" name="${esc(item.id)}" time="${time}">${failure}\n </testcase>`;
});
return `<?xml version="1.0" encoding="UTF-8"?>\n<testsuite name="web-freecad-functional-suite" tests="${ctx.results.length}" failures="${ctx.counts.failed}" skipped="${ctx.counts.blocked}" time="${(ctx.results.reduce((sum, item) => sum + Number(item.seconds ?? 0), 0)).toFixed(3)}">\n${body.join("\n")}\n</testsuite>\n`;
}
export function writeIndex(ctx) {
const rows = ctx.results.map(item => {
const color = item.status === "passed" ? "#137333" : item.status === "blocked" ? "#8a6d00" : "#a50e0e";
return `<tr><td><a href="cases/${esc(item.id)}/">${esc(item.id)}</a></td><td>${esc(item.priority)}</td><td style="color:${color}">${esc(statusCell(item))}</td><td>${Number(item.seconds ?? 0).toFixed(1)}s</td><td>${esc(item.error ? item.error.slice(0, 160) : "")}</td></tr>`;
});
return `<!doctype html><meta charset="utf-8"><title>Web FreeCAD functional suite</title>
<style>body{font:14px/1.5 system-ui,sans-serif;margin:24px}table{border-collapse:collapse}td,th{border:1px solid #ddd;padding:4px 8px;text-align:left}</style>
<h1>Web FreeCAD 功能测试(有头)</h1>
<p>${esc(ctx.startedAt)} · origin ${esc(ctx.origin)} · passed ${ctx.counts.passed} / failed ${ctx.counts.failed} / blocked ${ctx.counts.blocked}</p>
<table><thead><tr><th>id</th><th>优先级</th><th>状态</th><th>耗时</th><th>错误</th></tr></thead><tbody>${rows.join("")}</tbody></table>
<p><a href="report.md">report.md</a> · <a href="results.json">results.json</a> · <a href="junit.xml">junit.xml</a></p>`;
}
export function finalize(ctx) {
persist(ctx);
fs.writeFileSync(path.join(ctx.output, "report.md"), writeMarkdown(ctx));
fs.writeFileSync(path.join(ctx.output, "junit.xml"), writeJUnit(ctx));
fs.writeFileSync(path.join(ctx.output, "index.html"), writeIndex(ctx));
const gaps = renderGapSections(ctx.gaps);
fs.writeFileSync(path.join(ctx.output, "GAPS.md"),
`# Gap ledger\n\n## Blocked (preconditions): ${gaps.counts.blocked}\n\n${gaps.blocked}\n\n## Product regressions/gaps: ${gaps.counts.product}\n\n${gaps.product}\n`);
}
export function pruneRuns(base, keep) {
if (!fs.existsSync(base)) return [];
const dirs = fs.readdirSync(base, { withFileTypes: true })
.filter(entry => entry.isDirectory() && entry.name.startsWith("run-"))
.map(entry => entry.name).sort();
const removed = dirs.slice(0, Math.max(0, dirs.length - keep));
for (const name of removed) fs.rmSync(path.join(base, name), { recursive: true, force: true });
return removed;
}