Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(desktop): 内嵌 WebDriver 插件只在 E2E 进程注册

hairyf00ed8ebff878
diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rs
index 36713ac6..79c4a5bf 100644
--- a/src-tauri/src/desktop/builder.rs
+++ b/src-tauri/src/desktop/builder.rs
@@ -1000,9 +1000,17 @@ pub fn handler() -> impl Fn(Invoke<Wry>) -> bool + Send + Sync + 'static {
// configure tauri builder
pub fn builder() -> tauri::Builder<tauri::Wry> {
- let builder = tauri::Builder::default()
- // E2E:内嵌 WebDriver server(仅在 TAURI_WEBDRIVER_PORT 存在时监听)。
- .plugin(tauri_plugin_wdio_webdriver::init())
+ let mut builder = tauri::Builder::default();
+
+ // E2E:内嵌 WebDriver server 只在 E2E 进程装配(`@wdio/tauri-service` 拉起应用时注入
+ // TAURI_WEBDRIVER_PORT)。插件一旦注册就会无条件监听 127.0.0.1:4445,并接管每个 webview
+ // 的 script dialog(默认弹窗被禁用,转成等 WebDriver 应答、最长 30s 的 pending alert);
+ // 正常 dev/release 会话既不该开这个端口,也不该动用户的弹窗与文件选择。
+ if crate::config::is_e2e_run() {
+ builder = builder.plugin(tauri_plugin_wdio_webdriver::init());
+ }
+
+ let builder = builder
.manage(crate::desktop::pet_mouse::PetMouseStreamState::default())
.setup(|app| {
let app_handle = app.handle().clone();
diff --git a/test/wdio-e2e-gate.test.ts b/test/wdio-e2e-gate.test.ts
new file mode 100644
index 00000000..46c696c9
--- /dev/null
+++ b/test/wdio-e2e-gate.test.ts
@@ -0,0 +1,30 @@
+import { readFileSync } from 'node:fs'
+import { describe, expect, it } from 'vitest'
+
+const BUILDER = readFileSync(new URL('../src-tauri/src/desktop/builder.rs', import.meta.url), 'utf8')
+const SETTING = readFileSync(new URL('../src-tauri/src/config/setting.rs', import.meta.url), 'utf8')
+
+describe('embedded WebDriver plugin is registered for E2E runs only', () => {
+ it('registers tauri-plugin-wdio-webdriver inside the is_e2e_run guard', () => {
+ const call = 'tauri_plugin_wdio_webdriver::init()'
+ // 全仓只有这一处注册点:多出一处就会绕开守卫,正常会话也开 4445 并接管 script dialog。
+ expect(BUILDER.split(call)).toHaveLength(2)
+
+ const builderFn = BUILDER.indexOf('pub fn builder() -> tauri::Builder<tauri::Wry> {')
+ expect(builderFn).toBeGreaterThan(-1)
+
+ const guard = BUILDER.indexOf('if crate::config::is_e2e_run() {', builderFn)
+ expect(guard).toBeGreaterThan(-1)
+
+ const blockEnd = BUILDER.indexOf('\n }\n', guard)
+ expect(blockEnd).toBeGreaterThan(guard)
+ expect(BUILDER.slice(guard, blockEnd)).toContain(call)
+ })
+
+ it('keys the guard on the env var the WebDriver service injects when it spawns the app', () => {
+ // @wdio/tauri-service 的 embedded provider 拉起应用时注入 TAURI_WEBDRIVER_PORT,
+ // 门控与 E2E Store / WebView2 profile 隔离共用同一个判定。
+ expect(SETTING).toContain('pub fn is_e2e_run() -> bool {')
+ expect(SETTING).toContain('std::env::var_os(E2E_PORT_ENV_VAR).is_some_and(|v| !v.is_empty())')
+ })
+})