Files
msime-windows/server/tests
Jia Suiandfanlusky 60c2b26698 fix(engine,server): 全拼纠错收窄「多字」纠错并让开关真正关闭纠错 (#889)
* fix(engine,server): 全拼多字纠错收窄为仅 QWERTY 邻键插入

多字(插入)纠错只保留「误插 QWERTY 邻键」:生成器 insertion_variants 不再生成重复相邻键(双击),生成式空间不再生成任意字母插入(远键插入)。autocorrect_table.h 随生成器重新生成。

* fix(engine): 全拼纠错开关关闭时真正不再改写切分

纠错开关关掉后真正不纠错:把手误拼写别名层从常开改为跟掩码走(ü 归一 jv->ju / nue->nve 仍常开);两个早于掩码可知的切分入口 QuanpinScheme::build_request 与 QuanpinDictionary::get_or_compute_segments 显式带上掩码,切分缓存键随之隔离。

* fix(engine,server): 纠错开关关闭时辅助码、写回与排序上下文也按字面切分

关掉全拼纠错后,只有方案的 build_request 和查询自身切分不再跑手误别名层,
其余几条路径仍用默认(带别名)的切分,和查询落在不同的键上:

- 辅助码路径自己切底串作为显式切分交给词典,haoyonga 仍被切成 hao'yong'ga;
- 调频、造词、删词、建 SQL、校验去掉分隔符后重切,开关关掉时选中 hao'yong'a
  的词会去更新 hao'yong'ga,调频静默失败;
- 排序 / 固定位置的上下文 key(引擎与 server 两处)仍按别名切,laing 与 liang
  的固定位置互相串。

改动:
- cut_pinyin_by_mode 的 include_correction_aliases 改为必填,每个调用点显式决定;
  双拼词典、设置页词库校验和离线工具传 true,保持原行为。
- 新增 quanpin::correction_aliases_enabled,方案、词典、辅助码与排序 key 共用
  (只看换位、邻键两位),修正只带删除 / 插入位的掩码在方案与词典两层判断不一致。
- 词典按最近一次 query 的掩码记录别名开关,写回路径统一走 cut_for_write。
- 会话改为在换方案、改开关时 bind_quanpin_scheme 一次,不再每次 refresh 下发。
- 方案只存 bool;jv -> ju 放回纠错表,去掉合并表。
- 在 CI 实际执行的 test_input_session 中补回归用例(写回、辅助码、固定位置、
  方案掩码),每条都确认回退修复后会失败。

---------

Co-authored-by: fanlusky <1730976608@qq.com>
2026-10-12 20:41:23 +08:00
..
2026-06-20 22:11:00 +08:00
2025-04-20 17:44:33 +08:00
2025-04-21 18:32:45 +08:00

Tests

Run the candidate DOM test from the repository root:

node --test server/tests/test-candidate-dom-render.cjs

The test runs the JavaScript renderer from windows_webview2_candidate.cpp. It checks text, order, badges, translations, and fixed candidate color.

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:

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:

.\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:

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

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.