Files
workinf_Blender_Wasm/docs/web/DEPLOYED-FUNCTIONAL-TESTS.md
mes123456 a5f772e18f
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
feat(web): deployed functional suite, outliner expansion fix and local-first runs
Outliner: react-accessible-treeview's controlled expandedIds sync expands a
node together with its parent, then the next pass treats that extra parent id
as removed from the controlled set and collapses the whole branch. Reproduced
as a collapsed tree after ch11 -> ch12 (scene rows complete in React, one
collapsed row in the DOM). Keep OUTLINER_ROOT_ID in the controlled set so both
passes agree, and drop the rows-digest memo that regressed the normal path.
Also arm a bounded post-open OUTLINER_REFRESH loop so the tree settles on rows
of the newly opened Main instead of the previous one.

Tests: web/playwright.deployed.config.ts + web/tests/deployed walk the 31
manual chapters and the 31 capability rows headed against a deployed origin,
and tools/web/run-deployed-functional-tests.mjs preflights, runs and reports.
--local serves the production bundle from web/dist on loopback with the same
COOP/COEP/CORP/CSP headers, so a case costs compile time instead of a 300 MB
download: full local suite 60/60 in 10.3 min, also 60/60 against the deployed
release. Report dirs are resolved absolute and [ch28a]-style tags map to their
chapter.

Area layout: split from the clamped source rect and keep the area switcher
inside a narrow header.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 16:12:26 +08:00

7.9 KiB
Raw Blame History

Deployed functional tests(线上功能测试工具)

面向已发布站点的有头功能测试套件。执行对象默认是 https://49.232.250.35:58014,可以一边看着浏览器窗口一边跑。

加载策略(为什么这么快)

线上包每次冷启动都要下载并编译约 300 MB 的 web_engine.wasm,单个新浏览器上下文约 3 分钟。按「每例一个上下文」跑 58 条用例,光加载就要 3 小时。

本工具默认采用共享持久化会话:

机制 效果
每个 worker 只启动 1 个持久化上下文(Chrome profile 落在 web/.cache/deployed-profile) wasm 只下载/编译一次;用例之间直接复用页面
服务端支持 If-None-Match → 304(Cache-Control: no-cache + ETag) 重复运行不再传 300 MB,只做一次校验
用例自行打开所需工程来隔离状态 不需要为隔离而重建上下文
每例 trace(仅失败保留)+ 每例关键截图 失败可复盘,不必整段录像
工程打开改为「活动对象 + 对象数连续稳定」 挡住线上启动模板覆盖用户工程的竞态

需要逐例独立上下文 / 录像时,用 --isolate(或 --record-video),代价回到每例约 3 分钟。

本地优先(推荐流程)

先在本地跑同一套用例,再加 --local 换成线上之前的上云步骤:

# 1. 构建产物自己扛加载:web/dist 由本地静态服务器按生产响应头托管
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs --local

# 2. 本地全绿后再发布,然后打线上
node tools/web/deploy-58014.sh --skip-build --release-id <release-id>
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs --smoke
DEPLOYED_REPORT_DIR=tests/golden/DEPLOYED-FUNCTIONAL-<date>-CLOUD \
  DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs

--local 的行为:

  • 用 tools/web/deployment-http-server.mjs 把 web/dist 托管在 127.0.0.1:<随机端口>,响应头与线上一致(COOP/COEP/CORP、'wasm-unsafe-eval' CSP、ETag)。测的是生产构建产物,不是 dev server。
  • 该服务器必须独立进程:runner 用 spawnSync 启动 Playwright,会阻塞自身事件循环,进程内服务器在整轮测试里都无法应答。
  • 308 MB wasm 不经过网络,用例成本只剩编译时间(启动从约 3 分钟降到约 0.2 秒),全量约 10 分钟。
  • 报告默认写到 tests/golden/DEPLOYED-FUNCTIONAL-LOCAL-<YYYYMMDD>/,与线上报告分开,避免互相覆盖。
  • 端口可用 DEPLOYED_LOCAL_PORT 固定;报告目录可用 DEPLOYED_REPORT_DIR 覆盖。
  • 预检里的 TLS 项在本地必然 ok:false(http 源,非硬失败),这是预期行为。

快速开始

cd /home/mes123456/workinf_Blender_Wasm

# 全量(共享会话;主要成本只在首次启动)
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs

# 发布后冒烟(@smoke 子集)
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs --smoke

# 只跑某一组(00 预检 / 01 文件与工程 / 02 布局与建模 …)
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs --only 00

# 按标题过滤
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs --grep "ch07"

# 其他站点
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs --origin https://example.org:58014

# 完全隔离 + 录像(慢;每例一个新上下文)
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs --isolate --record-video

# 并行(每个 worker 一个上下文,内存与显存按 worker 数翻倍)
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs --workers 2

# 清掉缓存 profile(怀疑缓存了旧产物时)
DISPLAY=:1 node tools/web/run-deployed-functional-tests.mjs --fresh-profile

也可以走 npm:cd web && DISPLAY=:1 npm run test:deployed[:smoke]。

覆盖口径

两层账本,缺一不可:

  1. 使用手册 31 章(user-manual/WEB_Blender_Web_Manual_20261113/manual.json):tests/deployed/01-… 到 06-… 按手册的 6 个部分分组,用例标题带 [chNN] 标签。报告会把「没有任何用例覆盖的章节」列成 summary.notCovered。
  2. 能力矩阵 31 条(tools/web/manual/feature-matrix.json):08-capability-matrix.spec.ts 数据驱动,每条能力至少一条用户可见证据。

手册步骤本身没有选择器,因此不能被当成脚本执行;章节只用于分组和验收口径。把手册改成可执行 DSL 不在本工具范围内。

目录

web/playwright.deployed.config.ts        远端 baseURL、无 webServer、强制有头
web/tests/deployed/
  support/deployed.ts                    启动/打开工程/截图/receipt/OPFS 助手
  support/chapters.ts                    读取 manual.json 的 31 章
  support/matrix.ts                      读取 feature-matrix.json 的 31 条能力
  00-preflight.spec.ts                   线上身份 + 有头启动 + 练习工程
  ...                                    按手册部分分组的走查
tools/web/run-deployed-functional-tests.mjs   预检 → 跑测 → 报告

报告

每次运行写到 tests/golden/DEPLOYED-FUNCTIONAL-<YYYYMMDD>/(本地日期):

文件 内容
preflight.json 预检逐项结果(显示、响应头、引擎清单、wasm 哈希、证书到期、release、index ETag)
report.json 机器可读总报告:release、preflight、cases[]、summary{pass,fail,skip,blocked,notCovered}、acceptance: "NOT_CLAIMED"
report.html 单文件可读报告(无外部资源),失败项内联错误栈
receipts/<caseId>.json 每个用例一条:走了什么流程、看到什么、截图路径
screenshots/<caseId>-<step>.png 每例关键截图
failures/ 失败用例的 Playwright 截图 / 录像 / trace 副本

退出码:0 全通过 · 1 有失败用例 · 2 预检阻塞或无法启动(此时不启动浏览器)· 64 参数错误。

summary.pass 只统计真正执行并通过的用例;Playwright 里被跳过(含一条失败后中止同文件后续)的用例计入 summary.skip,不会被算成通过。

预检拦什么

  • DISPLAY 未设置 → 直接退出 2(有头是硬要求;xvfb 会丢掉 ANGLE/GL 路径,不推荐)。
  • 证书已过期 → 退出 2;剩余 ≤14 天 → 报告里留警示项。49.232.250.35 使用 Let's Encrypt 的 IP 短周期证书(约 7 天有效),由服务器上的 snap.certbot.renew.timer 每天两次自动续签,部署钩子 renewal-hooks/deploy/robotopl-nginx-reload.sh 负责 systemctl reload nginx;预检里的到期天数因此会长期显示在 7 天以内,属预期。
  • COOP/COEP/CORP/CSP 不符 → 退出 2(缺这些头时 SharedArrayBuffer 不可用,后面的用例没有意义)。
  • 线上 wasm 哈希 ≠ 本地 web/dist 构建 → 不阻塞,但记入报告:这代表线上不是当前源码的产物。

失败分类约定

报告里的失败要能区分责任:

  • PRODUCT:用户可见行为不符(对象数、状态栏、下载文件、渲染像素、持久化)。
  • ENV:网络/证书/GPU 等环境问题 —— 由预检拦掉大部分,运行中出现也要显式标注。
  • TEST:选择器或时序错误。修用例,不改断言口径去「变绿」。

禁止用「按钮点到了」当作通过。断言必须落在用户可见结果上。

已知限制

  • 有头窗口占用真实桌面焦点;跑全量期间不要同时操作桌面(workers: 1 串行)。
  • 每个新浏览器上下文都要重新拉 300 MB wasm,整体耗时主要由首加载决定。
  • 只覆盖 Chromium(Chrome 151);无头与 CI 不在范围内。
  • 默认入口(不带 ?ui=web)是 WASM 内嵌 + 原生桌面覆盖层,会拦截指针点击;这类用例必须用元素级 element.click() 或先切到「Web 业务工具」。
  • 报告只证明「这次运行的所见」,不代表整体验收,固定标 NOT_CLAIMED。