From 9d03bae349b47a6cea9c0ad2264fc6bada1dc46b Mon Sep 17 00:00:00 2001 From: sim Date: Mon, 7 Sep 2026 14:31:36 +0800 Subject: [PATCH] =?UTF-8?q?test(linux-egui):=20host=5Fcontract=20=E6=8C=89?= =?UTF-8?q?=E6=9C=89=E6=95=88=E7=9B=AE=E6=A0=87=E8=AF=AD=E4=B9=89=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20Windows=20=E9=94=AE=E7=9B=98=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #1021 重构后 WindowsKeyboardRuntimeTarget 由插入模式派生:默认 TSF 模式下 翻转 keyboard-list 偏好不产生有效目标变化,Linux 接受并广播 PreferencesChanged; 将插入模式切到 SendInput 且隐藏键盘列表会真正驱动 Windows 语言 profile, 合同仍要求显式拒绝(Unsupported)。旧断言只翻转原始字段,与新语义冲突。 --- .../app/linux-egui/tests/host_contract.rs | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/openless-all/app/linux-egui/tests/host_contract.rs b/openless-all/app/linux-egui/tests/host_contract.rs index ce2b2396..adcfb5e6 100644 --- a/openless-all/app/linux-egui/tests/host_contract.rs +++ b/openless-all/app/linux-egui/tests/host_contract.rs @@ -1,5 +1,7 @@ use std::sync::{Arc, Mutex}; +use openless_core::shared_types::WindowsInsertionMode; + use openless_linux_egui::{ drain_events, BackendConfig, BackendDependencies, BackendErrorCode, BackendEventKind, 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!(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(); - windows_only.windows_show_openless_in_keyboard_list = - !windows_only.windows_show_openless_in_keyboard_list; + windows_only.windows_insertion_mode = WindowsInsertionMode::SendInput; + windows_only.windows_show_openless_in_keyboard_list = false; 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"); 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)); for enabled in [true, false] { let mut preferences = backend.get_preferences();