Files
Lu Fan(SonnyCalcr) 1b875267db refactor: 移除 WebView2,界面只保留 Direct2D (#1013)
* refactor(engine): 语音独立工具改用原生托盘菜单,移除 WebView2

托盘菜单改用 Win32 弹出菜单,设置项改为用关联编辑器打开 config.toml,关于页改为消息框。删除 window_webview2 与两份 HTML 资源,windows-app 特性不再依赖 webview2 端口。

* refactor(server): 移除 WebView2,候选窗、工具栏、托盘菜单与设置窗口只保留 Direct2D

删除 src/webview2 与 webview_utils,小窗口的置顶、皮肤重载和工具栏状态缓存移到 window/small_windows,presenter 成为唯一路径,D2D 下的置顶时序与 cloak 行为保持不变。设置进程去掉 WebView2 宿主、鼠标转发与启动图,只构建原生窗口;旧快捷方式传入的 --d2d / --webview2 被忽略。删除 appearance.ui_backend 与 appearance.settings_ui_backend(读取、写入、设置页下拉框与两份配置模板),升级时由模板合并丢弃旧值。设置窗口的图片资源移到 server/assets/settings,安装到数据目录的 assets\settings。不再链接 WebView2Loader,vcpkg 去掉 webview2 端口。

* build(installer): 打包与 CI 不再处理 WebView2 页面和运行时

Prepare-PackageFiles 去掉 -UiHtmlDirectory 与 html 暂存,改为暂存 server/assets/settings;安装器不再检查 WebView2 Runtime、不再创建 ProgramData 下的 WebView2 用户数据目录,升级和卸载时清理旧版留下的 webview2 / webview2-settings 与数据目录里的 html。CI 删除设置页构建、契约同步检查和候选窗 DOM 测试,release 的打包任务不再依赖网页产物;dependabot 去掉 npm。第三方声明去掉 WebView2Loader。

* refactor(ui-html): 删除 WebView2 页面与设置页前端工程

候选窗、工具栏、托盘菜单、设置页、主题和契约副本都已没有使用者;设置窗口用到的图片资源已移到 server/assets/settings。sync-contracts.py 与 pnpm/Vite/TypeScript 工程一并删除,契约仍以 engine/contracts/webview 为唯一来源。

* docs(server): 文档改为只描述 Direct2D 界面

仓库地图去掉 ui-html,组件边界、uiAccess 与置顶时序、设置窗口和配置读写的说明改写为 Direct2D 唯一界面;安装说明去掉 WebView2 Runtime 检查,打包命令去掉 -UiHtmlDirectory;engine/contracts/webview 的说明改为设置窗口是唯一使用者,名字是历史遗留。

* docs(skins): 皮肤说明不再区分 WebView2 与 D2D 渲染器

v2 字段去掉「仅 WebView2」,改为说明由 Direct2D 原生渲染、部分字段仍在补全;颜色必须带 # 改为清单格式约定。随包的 skins/niya-demo/skin.toml 不改,免得用户机器上的同名皮肤在升级时被当成已修改而改名备份。

* docs(ui): demo 说明文字不再提 WebView2
2026-10-17 02:48:02 +08:00

133 lines
5.6 KiB
Markdown

# Tests
This project now includes a lightweight regression test target wired into the main CMake build.
## What It Covers
Current tests focus on high-value IME behaviors that are easy to accidentally break during refactors:
- `shuangpin` scheme request construction
- `quanpin` scheme request construction
- case-preserving shuangpin segmentation
- full-helpcode detection
- `engine + shuangpin` continuation behavior
- cloud suggestion trigger timing for shuangpin
The goal is not to fully simulate the whole IME UI pipeline yet. The goal is to protect the core input rules and
session behavior.
## Build and run
Run these commands from the **MSIME-Windows repository root** after preparing
vcpkg and Boost with `python server/scripts/prepare_env.py`:
```powershell
python scripts/product_lock.py fetch-dictionaries --staging-root .
if ($LASTEXITCODE -ne 0) { throw 'Dictionary verification failed' }
$env:LOCALAPPDATA = Join-Path $PWD 'build/test-data/user-local'
$env:METASEQUOIA_IME_DATA_DIR = Join-Path $env:LOCALAPPDATA 'metasequoiaime'
New-Item -ItemType Directory -Force $env:METASEQUOIA_IME_DATA_DIR | Out-Null
Copy-Item MetasequoiaImeDict/out/* $env:METASEQUOIA_IME_DATA_DIR -Force
Copy-Item engine/helpcode/helpcodes $env:METASEQUOIA_IME_DATA_DIR -Recurse -Force
Copy-Item server/assets/tables/* $env:METASEQUOIA_IME_DATA_DIR -Force
Copy-Item server/assets/config/config.toml $env:METASEQUOIA_IME_DATA_DIR -Force
.\server\tests\scripts\llaunch.ps1 -Configuration Release
```
Use a dedicated PowerShell terminal: these environment variables isolate both
Windows helpers and the shared Engine from the installed user's data for the
rest of that session. The scripts run CTest; they do not launch the interactive
Server, install or register the input method. CI additionally runs the native
Win32/x64 pipe probe after building the full Server.
Tests belong to the **Server CMake project**, which provides the Engine, GUI and
third-party targets. `server/tests/CMakeLists.txt` is an `add_subdirectory` input,
not an independent project. The obsolete test presets have been removed; an old
locally generated `server/tests/CMakePresets.json` is no longer used.
Once test data is prepared, the convenience scripts work from any directory:
```powershell
.\server\tests\scripts\llaunch.ps1 -Configuration Release # build, then CTest
.\server\tests\scripts\lrun.ps1 -Configuration Release # CTest only
```
Omitting `-Configuration` selects Debug in `server/build`; Release uses
`server/build-release`. Both compile `MetasequoiaImeServerTests` and
`test_webview_contract` in the parent build tree. Configuration, compilation,
test failures and an empty CTest registry return failure rather than launching a
stale executable or reporting success.
The equivalent direct CTest command from the repository root is:
```powershell
ctest --test-dir server/build-release -C Release --output-on-failure --no-tests=error
```
## Test Layout
- `tests/src/main.cpp`
- tiny custom test runner
- `tests/includes/test_framework.h`
- lightweight assertion helpers
- `tests/src/test_shuangpin_scheme.cpp`
- shuangpin scheme unit tests
- `tests/src/test_quanpin_scheme.cpp`
- quanpin scheme unit tests
- `tests/src/test_shuangpin_query.cpp`
- query/helper function tests
- `tests/src/test_engine_shuangpin_session.cpp`
- session-level behavior tests
## Model path benchmark
Build the Server test target in Release mode. Run the benchmark from a Windows terminal:
```powershell
cmake --build server/build-release --config Release --target MetasequoiaImeServerTests
server/build-release/bin/Release/MetasequoiaImeServerTests.exe --benchmark-model-path 10000 > model-path.csv
```
The executable creates small model files in a temporary data directory.
It restores `METASEQUOIA_IME_DATA_DIR` when it exits.
It does not load model contents.
Each row reports P50, P95, P99, and worst latency in nanoseconds.
`hot` repeats one path.
`rotating` cycles through 128 paths.
The rotating set increases metadata lookup pressure.
It does not guarantee an operating system cache miss.
`first-touch` checks each missing path once without benchmark warmup.
The operating system can still cache shared parent directories.
`contended` adds a thread that creates and removes files in the model directory.
This tests directory activity on the same volume.
It does not simulate all disk workloads.
The benchmark calls the production path resolvers used by `ApplyConfiguration()`.
It measures their cost per call.
It does not measure full `handle_key()` latency.
The benchmark sets `METASEQUOIA_IME_DATA_DIR` to an isolated temporary directory.
Each resolver call reads this override and builds a path.
Normal installations do not set this override. Their directory lookup takes a different path.
The `disabled-empty-id` row returns before `data_directory()` runs.
The `data-directory-only` row measures `data_directory()` with the temporary override.
Median differences give only a rough scale for the remaining resolver work.
Do not subtract percentiles from separate rows to assign costs to path joining or file checks.
Use the rows to inspect latency distributions and tail latency across path access patterns.
They do not establish the same cost or performance loss in production.
Run each case more than once on the target Windows machine.
Record the storage type and active disk workload with the CSV results.
## Recommended Practice
When you change input behavior, add a regression test if the change affects:
- input segmentation
- space/enter/backspace behavior
- helpcode handling
- continuation after candidate selection
- create-word flow
- cloud suggestion timing
The best tests in this project are the ones that capture a concrete input example that previously broke.