test: add a CDP-based pre-release UI smoke harness

The DSH sandbox blocks named pipes, so Chromium/WebView2 cannot start inside
it (window renders white, msedgewebview2 exits immediately; Edge headless
fails with a Mojo platform-channel access-denied fatal). UI verification
therefore moves to a script the user runs from a normal desktop shell.

- agent/tests/ui-smoke.ps1: launches the built exe with an isolated config
  and --remote-debugging-port, waits for the port, runs the driver, closes.
- agent/tests/ui-smoke.mjs: connects over CDP, snapshots the page (preview
  content, headings, fold toggles, highlighted code, window.ipc bridge),
  saves a screenshot and a JSON report for the agent to read.
- The driver was validated against a mock CDP server; the real end-to-end run
  needs a desktop shell (sandbox cannot host WebView2).
This commit is contained in:
2026-11-04 15:15:24 +08:00
parent fadba614a8
commit 0b97bcb6dc
5 changed files with 360 additions and 1 deletions

View File

@@ -65,9 +65,31 @@ cargo fmt -- --check
手动冒烟(无自动化):多标签切换、编辑/阅读、Ctrl+F、Ctrl+P、折叠、拖拽打开、外部修改提示、只读保存失败。
## 5.1 发布前 UI 冒烟(必须由用户在普通 PowerShell 跑)
**为什么不能由 Agent 跑**:DSH 的 Windows 沙箱禁止命名管道,Chromium/WebView2 的 Mojo IPC 起不来。
实测:md-preview 能启动、窗口出现,但 `msedgewebview2.exe` 立刻退出(数据目录只建了一半),页面白屏;Edge headless 报
`FATAL:mojo\public\cpp\platform\platform_channel.cc Check failed: 拒绝访问 (0x5)`。
这是沙箱限制,不是应用 bug;同时开发 exe 是 Low 完整性,从这里 `icacls /setintegritylevel Medium` 会被拒绝(无 write-up)。
**用法**(普通 PowerShell,Node 21+;本机 `C:\Program Files\nodejs\node.exe` 是 24.x):
~~~powershell
cd D:\Scripts\md-preview\AgentLowWorking
.\agent\tests\ui-smoke.ps1 # 开发构建 + code-samples.md
.\agent\tests\ui-smoke.ps1 -Expect home # 启动页
.\agent\tests\ui-smoke.ps1 -KeepOpen # 失败时留着窗口人工看
~~~
- 脚本用独立配置目录(`target\ui-test\config`)启动 exe,设置 `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9333`,等端口起来后调用 `agent/tests/ui-smoke.mjs`。
- mjs 通过 CDP 读取页面快照、断言(页面加载、`#preview` 有内容、`window.ipc` 桥、页面 API、标题/折叠按钮/代码高亮),再截图,写 `target/ui-test/ui-smoke.json` 与 `ui-smoke.png`。
- Agent 可以直接读这两个文件定位问题;失败时把 report 里的 checks 贴出来即可。
- 已知边界:只验证“页面真的渲染了 + 基础 API 在”,不覆盖标签切换、保存、外部修改等 Rust 侧流程(那些靠单元测试和人工点)。
- 注意:如果用 `-Exe` 指向 Nutstore 的发布版(Medium),启动会写 HKCU 关联(应用原有行为,指向它自己);默认的开发构建是 Low,写不了注册表。
## 6. 注意
- 本仓库现在**只能在 Windows 上编译**;`cargo test` 里仍有 `cfg(target_os = "windows")` 的 Windows 专用测试。
- `main.rs` 顶部的 `windows_subsystem` 只对 release 生效;debug 构建带控制台,属正常。
- 页面 JS 改动后建议做一次语法检查(临时测试把页面写到文件,再 `node --check`)。
- 构建/测试临时文件放 `target\tmp`;不要写 `%TEMP%`。
- 构建/测试临时文件放 `target\tmp`;不要写 `%TEMP%`。