Files
msime-windows/server/tests
fanlusky b5def6a2e3 refactor(server): 按职责拆分 ime_config.cpp
ime_config.cpp 有 4000 行,配置状态与加载、TOML 文本编辑、升级时的模板合并、
写回与通知 Server,以及上百对 GetConfigured* / SetConfigured* 全挤在一个文件里。
按职责拆成以下几个翻译单元:

- ime_config.cpp:全部配置全局变量的定义(顺序与初始值不变)、语音配置的读写锁
  快照与发布、各项校验白名单、LoadImeConfig(读取与缺省值)、旧版语音配置迁移、
  InitImeConfig / ReloadImeConfigIfChanged / InvalidateImeConfigWriteTime
- ime_config_toml.cpp:保留格式的键值替换与插入、跨行值定位、赋值遍历与解析、
  读文件、原子写文件与 TOML 解析校验
- ime_config_template.cpp:凭证兜底重放、MergeTomlIntoTemplate /
  MergeConfigIntoTemplate、损坏配置的留证与抢救、SyncConfigWithInstalledTemplate、
  旧 ACP 乱码目录的配置找回
- ime_config_write.cpp:WriteConfiguredValues / WriteConfiguredValue 与
  NotifyImeServer*(Aux 管道与窗口消息两条通知路径)
- ime_config_appearance.cpp:每页候选数、字体与字号、文字颜色、候选窗布局与跟随
  光标、小窗 UI 后端、皮肤、预编辑样式、固定徽标、设置窗口保留时长
- ime_config_fonts.cpp:ResolveSystemFontFamilyForCss 与 GetSystemFontFamilies
- ime_config_theme.cpp:主题模式、各界面主题覆盖与 ResolveConfiguredTheme
- ime_config_input.cpp:输入方案与中日文模式、简繁、中英切换键、双拼与五笔方案、
  上屏样式、辅助码、全拼纠错、模糊音、调频
- ime_config_keys.cpp:翻页键、方向键选词、以词定字、智能标点、配对标点、标点锁定
  及发给 TSF 的载荷
- ime_config_toolbar.cpp:悬浮工具栏与光标状态角标
- ime_config_general.cpp:诊断日志、输入统计、中英与表情混输、候选翻译、云候选、
  整句联想、工具模式与剪贴板历史
- ime_config_services.cpp:语音输入、AI 助手、腾讯 TMT、自定义翻译与小牛翻译
- ime_config_internal.h:上述文件之间共享的声明,只给 ime_config*.cpp 包含

纯搬移,不改行为:函数体、注释和格式都没动。原来在匿名命名空间里、现在
要跨文件用的符号放进 ime_config_detail 命名空间并在内部头文件里声明,
避免与 Server 其他翻译单元里的同名内部符号冲突;只被一个文件用到的仍留在
该文件的匿名命名空间,包括 g_session_backend、两个语音 token 槽位补写标记、
g_config_last_write_time、PublishVoiceInput、AiAssistantProviders、LoadImeConfig
和各文件自己的小工具。全局变量的定义都还在 ime_config.cpp,按原顺序排列,
初始化顺序不变;函数内的 static(字体缓存、DirectWrite 工厂、凭证键表、剪贴板
首次加载标记等)仍各自只有一份定义。取值范围常量、kFuzzyPinyinRuleKeys、
ConfigFileLock、ParseScheme 前置声明、模板文件名、TomlAssignmentVisitor 和
ConfigValueUpdate 原样挪进内部头文件。MetasequoiaImeServer、
MetasequoiaImeSettings 和测试工程都编译 ime_config.cpp,三处源文件列表一并
补上新文件。

非搬移改动只有两处:NotifyImeServer 的默认实参从定义挪到了头文件里的声明上;
测试里 kFuzzyPinyinRuleKeys 副本的注释改指 ime_config_internal.h。

用脚本比对了原文件与拆分后全部文件的非空、非 #include 行多重集:除上述
函数签名外,差异只有新增的声明、extern、命名空间包装、using 指令、
#pragma once 和文件头注释。可用 git diff --color-moved 复核。
2026-09-27 17:22:17 +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

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.