From 2fc3f740cab20dee4ea7069b4d9c08562dc930fb Mon Sep 17 00:00:00 2001 From: Richard Wu Date: Wed, 4 Nov 2026 17:12:32 +0800 Subject: [PATCH] test: add a bypass wrapper for the UI smoke script Windows PowerShell with an AllSigned policy refuses unsigned .ps1 files. ui-smoke.cmd runs ui-smoke.ps1 with a process-scoped -ExecutionPolicy Bypass (no system policy change) and keeps the window open when double-clicked. --- agent/README.md | 2 +- agent/docs/next-2026-11-03.md | 8 +++++--- agent/tests/ui-smoke.cmd | 11 +++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 agent/tests/ui-smoke.cmd diff --git a/agent/README.md b/agent/README.md index 3e6abb3..3e36094 100644 --- a/agent/README.md +++ b/agent/README.md @@ -18,7 +18,7 @@ | `scripts/build.ps1` | 开发构建(cargo test + build --release + 校验) | | `scripts/publish.ps1` | 用户手动发布到 Nutstore(Medium) | | `tests/smoke.ps1` | cargo test + 关联检查 + 可选隔离启动 | -| `tests/ui-smoke.ps1` + `ui-smoke.mjs` | 发布前 UI 冒烟:CDP 断言页面渲染、截图、JSON 报告(需普通桌面 PowerShell + Node 21+) | +| `tests/ui-smoke.cmd` / `ui-smoke.ps1` + `ui-smoke.mjs` | 发布前 UI 冒烟:CDP 断言页面渲染、截图、JSON 报告(需普通桌面 PowerShell + Node 21+;`.cmd` 内部用 Bypass,适合 AllSigned 策略) | | `tests/fixtures/` | 手工/冒烟用 Markdown 样例 | | `reports/` | 验证记录(文本;截图放 `agent/tmp/`,不入库) | | `notes/` | 草稿 | diff --git a/agent/docs/next-2026-11-03.md b/agent/docs/next-2026-11-03.md index 6f3b838..68dc5e6 100644 --- a/agent/docs/next-2026-11-03.md +++ b/agent/docs/next-2026-11-03.md @@ -76,11 +76,13 @@ cargo fmt -- --check ~~~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 # 失败时留着窗口人工看 +.\agent\tests\ui-smoke.cmd # 推荐:双击或从 cmd 运行,脚本内部用 Bypass +.\agent\tests\ui-smoke.ps1 # 若执行策略允许 .ps1 +powershell -NoProfile -ExecutionPolicy Bypass -File .\agent\tests\ui-smoke.ps1 ~~~ +> 本机执行策略可能是 AllSigned:直接跑未签名 .ps1 会被拒绝,所以提供了 `.cmd` 包装(内部 `-ExecutionPolicy Bypass`,不修改系统策略)。 + - 脚本用独立配置目录(`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 贴出来即可。 diff --git a/agent/tests/ui-smoke.cmd b/agent/tests/ui-smoke.cmd new file mode 100644 index 0000000..19a935a --- /dev/null +++ b/agent/tests/ui-smoke.cmd @@ -0,0 +1,11 @@ +@echo off +setlocal +rem Double-clickable wrapper: Windows PowerShell may refuse unsigned .ps1 files +rem (AllSigned policy). This runs the script with a process-scoped Bypass. +set "SCRIPT=%~dp0ui-smoke.ps1" +"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT%" %* +set "CODE=%ERRORLEVEL%" +if not "%CODE%"=="0" echo.&echo UI smoke exited with code %CODE%. +rem Keep the window open when launched without arguments (double-click). +if "%~1"=="" pause +exit /b %CODE%