Files
FreeCADWasmDev/docs/current/web-functional-suite/README.md
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

9.7 KiB
Raw Permalink Blame History

Web FreeCAD 有头功能测试套件

统一入口:tools/web-freecad-functional-suite.mjs。默认有头运行(DISPLAY=:1 上可见窗口),全自动无人值守;用例层按优先级分层,复用现有手册场景、工作台命令面与 OPFS 契约。

运行

cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD"
DISPLAY=:1 node tools/web-freecad-functional-suite.mjs --priority P0        # 壳层冒烟
DISPLAY=:1 node tools/web-freecad-functional-suite.mjs --priority P1        # 手册章节全流程
DISPLAY=:1 node tools/web-freecad-functional-suite.mjs --priority P2        # 全模块冒烟(31 例)
DISPLAY=:1 node tools/web-freecad-functional-suite.mjs --priority P3        # 交叉用例(导出/OPFS/回开/错误恢复)
DISPLAY=:1 node tools/web-freecad-functional-suite.mjs --only MOD-Fem-01 --force
DISPLAY=:1 node tools/web-freecad-functional-suite.mjs --legacy-ids all     # 附带旧 53 例手册套件

常用参数(完整列表见 tools/functional-suite/cli.mjs):

参数 作用
--only <ids> 逗号分隔的用例 id
--priority P0,P1,P2,P3 按层选择
--module <names> 只跑指定模块的 MOD-*
--resume <dir> / --force 断点续跑;--force 重跑已完成用例
--headless / --slow <ms> / --highlight 无头、放慢、高亮(观察用)
--screenshots fails|all 失败截图(默认)或全量截图
--out <dir> 证据根目录(默认 docs/current/web-functional-suite)
--prune <n> 只保留最近 n 次运行目录
--legacy-ids <ids|all> 以子进程运行 tools/run_user_manual_tests.mjs 并归一化为 LEGACY-*
--timeout-scale <x> 统一放大/缩小用例超时

退出码:0 = 全部 passed;1 = 存在 failed/running;2 = 没有选中任何用例。

用例分层

前缀 层 内容 来源
SHELL-0x P0 入口隔离(COOP/COEP)、Start 工作区、新建文档 + Cube、OPFS 可写、画布与图标渲染 cases/shell.mjs
CH-<chapter>-<workflow> P1 手册 27 份场景 JSON 全动作执行 + 章末后置断言(pageerror、状态栏、画布) cases/chapters.mjs → web/manual/scenarios/*.json
CH-ch14-*、CH-ch15-* P1 无场景 JSON 的两章用手写用例(生产线资产契约、Help/命令面板/偏好/快捷键) cases/handwritten.mjs
MOD-<Module>-01 P2 31 个模块:壳层挂载、模块坞选中、命令面注册、规范命令返回 kind=result cases/modules.mjs → feature-capability-registry.json
X-* P3 五种导出格式落 OPFS、FCStd 存取哈希、保存后回开、坏文件错误恢复、viewport 无溢出、左右面板独立滚动(X-panel-scroll) cases/crosscut.mjs
LEGACY-<id> P4 旧手册套件 53 例(仅 --legacy-ids 时运行) executors/legacy.mjs

场景动作解释器与 web/tools/manual/capture.mjs 共用同一份实现:web/tools/manual/lib/actions.mjs(18 种动作)。

前置顺序与失败分类

每个用例先准备前置(host/端口、fixture、文档与对象、命令状态、viewport),再执行产品断言。失败分类:

  • blocked / precondition:入口、fixture、viewport、host/iframe、命令状态不满足——先补缺项,不记产品回归。
  • failed / product-regression:前置全部满足后的产品行为失败,写入 gaps.ndjson 与报告。
  • 前置类由 blockedPrecondition(class, message)(gap-ledger.mjs)显式抛出;其余按 classifyFailure 归类。

输出(每次运行一个目录)

docs/current/web-functional-suite/run-<stamp>/:

  • manifest.json:origin、Chrome 版本、用例清单、dist 相对路径
  • results.json / checkpoint.json:逐案结果与断点(--resume 依据)
  • report.md / junit.xml / index.html:人读报告、CI 报告、浏览器索引
  • gaps.ndjson:缺口台账(caseId、classification、failureClass、evidence)
  • cases/<id>/result.json、step-*.json、shots/*.png、失败时 failure.png + failure-canvas.png

用例间用 resetState 隔离:回 about:blank、递归清空 OPFS、再进入口页;页面/控制台错误按用例清零,作为该用例的断言。

浏览器

Playwright + 系统 Chrome(FREECAD_CHROME 可覆盖,默认 /usr/bin/google-chrome)。固定 flags:--no-sandbox --disable-dev-shm-usage --use-angle=swiftshader --enable-unsafe-swiftshader,viewport 1440×1000;--gpu 仅供人工观察性能。静态服务用 tools/static-host.mjs 的临时端口(带 COOP/COEP),不占用 5180/5183 等固定端口。

配套工具(面板滚动排查沉淀)

  • tools/static-host.mjs:既是共享模块,也可直接当 CLI 用——node tools/static-host.mjs [--root <dist>] [--port <n>] [--document <file>],打印 ORIGIN= 后常驻,供 web/tools/manual/capture.mjs --origin 或临时探针复用。--root 支持相对路径(内部统一 path.resolve;此前传相对根会因路径守卫让所有请求 403)。
  • tools/layout-probe.mjs:三栏布局/滚动探针,替代逐个手写的临时脚本。默认对 /project.html、/partdesign.html、workbench.html?module=Part|Robot|Mesh 逐页断言:锁定页整页不可滚动、aside 全部在视口内、每个 aside 拥有可滚动 .pane-scroll(默认注入 2000px 占位块)、注入与滚动面板后中央舞台位移 ≤1px。全量报告用 --json,人工核对用 --headed --pause 拖动面板观察;--url 可重复指定页面,--origin 可复用已有 host。

已修复的缺口(套件落地过程中)

  • 静态 host 的 .svg MIME 为 application/octet-stream 导致工具栏大面积无图标 → 补全 MIME 表,并在 SHELL-02 增加图标渲染断言。
  • templatepymod.inspectSourceInventory 路由到 python worker 导致 invalid_request → 生成器映射改到 templatepymod.worker.ts 并重生成。
  • Fem 探针 fem.action 报 memory access out of bounds:11 月 15 日旧产物与当前构建图不匹配(全局 -pthread/-matomics vs 预编译 vtk 无原子特性)→ 以 -Wl,--no-check-features 重新链接 FreeCADWebFemGenericFamilyProbe,逐步骤日志确认 newDocument/addObject/recompute/closeDocument 全通。
  • 手册第 15 章写 Ctrl+K 打开命令面板,壳层只实现 Ctrl+Shift+P → project-shell.tsx 同时支持两者。
  • ch05 场景 fixture 硬编码旧树路径 → 改为本树绝对路径。
  • 元素截图/章末画布采样在模态遮挡下 30s 超时 → shot 与 canvasHash 改为有界超时 + viewport/clip 回退(证据能力,不改变产品断言)。
  • X-opfs-roundtrip / X-save-reopen 报「120 s 内没有 .FCStd」:cases/crosscut.mjs 的 listExports/readExport 接受 dirName 却把硬编码 EXPORTS 传给 page.evaluate,始终只列 freecad-exports → 改传 dirName。产品行为正常,FCStd 一直落在 freecad-documents。
  • glTF/GLB 导出报 glTF writer is unavailable - OCCT has been built without RapidJSON support:OCCT WASM 以 USE_RAPIDJSON=OFF 配置 → tools/rebuild-occt-rwgltf-rapidjson.sh 用 -DHAVE_RAPIDJSON 单点重编 4 个 RWGltf 编译单元(RapidJSON 1.1.0 位于 build-web/rapidjson/)并替换 3 份 libTKRWMesh.a,再重链 FreeCADWebDocumentProbe、同步资产、重建 dist。任何一次完整 OCCT 重建后用该脚本恢复,否则会静默回退。
  • ExportService 白名单缺 .gltf/.glb,导出返回 unsupported_extension → web/src/export-service.ts 的 EXTENSIONS 补齐。
  • MOD-Fem-01 的 fem.action 报 memory access out of bounds:web/tools/sync-assets.mjs 固定从 build-web/fem-wasm/bin 复制 Fem 探针(11 月 14 日旧产物),覆盖了 build-web/configure/bin 里重新链好的版本 → 改为与 CAM 相同的「按 mtime 择新」策略,buildProfileForProbe 同步跟随实际来源。旧产物与当前构建图特性不一致,正是该 OOB 的已知根因。
  • 工作台 / PartDesign 整页滚动、面板无独立滚动条(左右面板改参数时三维视口被挤出):web/src/panel-scroll.css 统一三栏高度链(html.stage-lock / html.stage-lock-pd → body 100dvh → #app/根 div flex:1 1 0% → .layout{grid-template-rows:minmax(0,1fr)} → aside{overflow:hidden} → .pane-scroll{overflow-y:auto}),入口按页加根类;X-panel-scroll 逐页断言面板独立滚动且中央视口不动。注意 flex-basis 必须是 0%,用 auto 会让面板内容高度参与收缩并推移舞台。
  • 模块任务面板(Mesh 建规则网格、Robot 关节、Assembly、Draft…)渲染在 .layout 之前的文档流里,内容长高会把三栏布局顶出视口(Robot 页 .layout top≈1490、asides 仅 32px;Mesh 点 Create 后按钮跑到 y≈2131)→ workbench-shell.tsx 把这些面板(Start 工作区 iframe 除外)包进 .module-task-dock,由 panel-scroll.css 给其 max-height:42dvh + 自滚动。包装起点必须位于所有模块任务面板之前,只包后半段会让 Mesh 仍然塌陷。
  • 文档树里非 PartDesign 的 3D 对象图标 404(/icons/partdesign/Part_3D_object.svg):project-shell.tsx / partdesign-workspace-component.tsx 把 Part 图标拼进了 partdesign 目录,实际文件在 /icons/part/Part_3D_object.svg → 改回正确目录;capture.mjs 的 ch01 场景冒烟以此为断言。

OPFS 目录契约(用例寻址口径)

  • 保存的 FCStd 文档在 freecad-documents(writeDocumentFile),几何导出在 freecad-exports(writeExportFile),参数在 freecad-parameters。用例必须按目录分别轮询/回读,禁止跨目录假设;下载目录始终为空,导出不得自动下载。