test(linux-egui): host_contract 按有效目标语义更新 Windows 键盘断言

#1021 重构后 WindowsKeyboardRuntimeTarget 由插入模式派生:默认 TSF 模式下
翻转 keyboard-list 偏好不产生有效目标变化,Linux 接受并广播 PreferencesChanged;
将插入模式切到 SendInput 且隐藏键盘列表会真正驱动 Windows 语言 profile,
合同仍要求显式拒绝(Unsupported)。旧断言只翻转原始字段,与新语义冲突。
This commit is contained in:
sim committed 2026-09-07 14:31:36 +08:00
1 parent b1370b5d40
commit 9d03bae349
1 file changed
+23 -4
@@ -1,5 +1,7 @@
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use openless_core::shared_types::WindowsInsertionMode;
use openless_linux_egui::{ use openless_linux_egui::{
drain_events, BackendConfig, BackendDependencies, BackendErrorCode, BackendEventKind, drain_events, BackendConfig, BackendDependencies, BackendErrorCode, BackendEventKind,
BackendServices, CliDispatchOutcome, CliIntent, DictationSession, EventDrainOutcome, BackendServices, CliDispatchOutcome, CliIntent, DictationSession, EventDrainOutcome,
@@ -415,14 +417,31 @@ fn linux_public_settings_contract_is_validated_transactional_and_runtime_backed(
assert_eq!(backend.snapshot().preferences_revision, revision + 1); assert_eq!(backend.snapshot().preferences_revision, revision + 1);
assert_eq!(events.try_recv(), Err(EventRecvError::Empty)); assert_eq!(events.try_recv(), Err(EventRecvError::Empty));
// Windows-only effects must stay explicit on the Linux host: since the
// Windows keyboard target is derived from the insertion mode, a raw
// keyboard-list toggle under the default TSF mode has no effective target
// and is accepted, while a change that would drive the Windows language
// profile is rejected as Unsupported.
let mut no_windows_effect = backend.get_preferences();
no_windows_effect.windows_show_openless_in_keyboard_list =
!no_windows_effect.windows_show_openless_in_keyboard_list;
host.update_settings_strict(no_windows_effect, revision + 1)
.expect("toggling the keyboard-list pref under TSF must not produce a Windows effect");
assert_eq!(backend.snapshot().preferences_revision, revision + 2);
assert!(matches!(
events.try_recv().unwrap().kind,
BackendEventKind::PreferencesChanged(_)
));
assert_eq!(events.try_recv(), Err(EventRecvError::Empty));
let mut windows_only = backend.get_preferences(); let mut windows_only = backend.get_preferences();
windows_only.windows_show_openless_in_keyboard_list = windows_only.windows_insertion_mode = WindowsInsertionMode::SendInput;
!windows_only.windows_show_openless_in_keyboard_list; windows_only.windows_show_openless_in_keyboard_list = false;
let unsupported = host let unsupported = host
.update_settings_strict(windows_only, revision + 1) .update_settings_strict(windows_only, backend.snapshot().preferences_revision)
.expect_err("Windows-only effects must be explicit on the Linux host"); .expect_err("Windows-only effects must be explicit on the Linux host");
assert_eq!(unsupported.code, BackendErrorCode::Unsupported); assert_eq!(unsupported.code, BackendErrorCode::Unsupported);
assert_eq!(backend.snapshot().preferences_revision, revision + 1); assert_eq!(backend.snapshot().preferences_revision, revision + 2);
assert_eq!(events.try_recv(), Err(EventRecvError::Empty)); assert_eq!(events.try_recv(), Err(EventRecvError::Empty));
for enabled in [true, false] { for enabled in [true, false] {
let mut preferences = backend.get_preferences(); let mut preferences = backend.get_preferences();