DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(config): 新增「自动更新」开关,可关闭静默下载与退出自动安装 (#1132) (#1135)
Hairyfe207b92e795
diff --git a/src-tauri/src/bridge/config.rs b/src-tauri/src/bridge/config.rsindex e5b2dc89..7e9c420a 100644--- a/src-tauri/src/bridge/config.rs+++ b/src-tauri/src/bridge/config.rs@@ -5,6 +5,7 @@use crate::config;use crate::service::cli;+use crate::service::update;use tauri::AppHandle;/// 当前桌面端配置@@ -65,6 +66,7 @@ pub async fn update_app_config(zoom_factor: Option<f64>,harness_max_heap_mb: Option<u32>,auto_start: Option<bool>,+ auto_update: Option<bool>,cli_link_enabled: Option<bool>,close_action: Option<String>,backup_retention_count: Option<u32>,@@ -110,6 +112,9 @@ pub async fn update_app_config(if let Some(auto_start) = auto_start {setting.auto_start = auto_start;}+ if let Some(auto_update) = auto_update {+ setting.auto_update = auto_update;+ }if let Some(enabled) = cli_link_enabled {setting.cli_link_enabled = enabled;}@@ -123,6 +128,11 @@ pub async fn update_app_config(setting.backup_include_credentials = include;}});+ // 关闭自动更新时立刻丢弃已下载的待安装包:否则用户退出前又打开开关,旧的+ // 安装包会在退出时被直接拉起安装(见 service::update::clear_pending_installer)。+ if auto_update == Some(false) {+ update::clear_pending_installer(&app_handle);+ }let profile = crate::service::workflow::instances::window_profile(&app_handle, window.label());let mut setting = setting;setting.active_profile = profile.clone();diff --git a/src-tauri/src/config/setting.rs b/src-tauri/src/config/setting.rsindex a3a9d6ef..1d12d3ed 100644--- a/src-tauri/src/config/setting.rs+++ b/src-tauri/src/config/setting.rs@@ -16,6 +16,12 @@ pub struct Setting {#[serde(default)]pub harness_max_heap_mb: Option<u32>,pub auto_start: bool,+ /// 是否自动更新桌面应用:开启时启动后轮询检查、发现新版本即静默下载,并在+ /// 退出时自动打开安装器。关闭后只剩「帮助 → 检查更新」这类用户显式发起的+ /// 更新链路,不再静默下载或强制安装(第三方打包与自行管理版本的用户需要,+ /// issue #1132)。+ #[serde(default = "default_auto_update")]+ pub auto_update: bool,pub language: String,#[serde(default)]pub dsh_pkg_commit: Option<String>,@@ -122,6 +128,12 @@ fn default_cli_link_enabled() -> bool {true}+/// 自动更新默认开启:与沿袭下来的「静默下载 + 退出时自动安装」行为一致,+/// 老 store 缺字段时不会被静默关掉。+fn default_auto_update() -> bool {+ true+}+/// 界面默认缩放为 100%。pub fn default_zoom_factor() -> f64 {1.0@@ -200,6 +212,7 @@ impl Default for Setting {port: default_port(),harness_max_heap_mb: None,auto_start: true,+ auto_update: default_auto_update(),language: "zh-CN".to_string(),dsh_pkg_commit: None,dsh_pkg_tag: None,@@ -380,6 +393,7 @@ fn preserve_persisted_fields(mut replacement: Setting, current: &Setting) -> Setreplacement.zoom_factor = normalize_zoom_factor(current.zoom_factor);replacement.harness_max_heap_mb = normalize_harness_max_heap_mb(current.harness_max_heap_mb);replacement.close_action = normalize_close_action(¤t.close_action);+ replacement.auto_update = current.auto_update;replacement.pet_enabled = current.pet_enabled;replacement.active_pet.clone_from(¤t.active_pet);replacement.pet_size = current.pet_size;@@ -761,6 +775,33 @@ mod tests {}}+ #[test]+ fn auto_update_defaults_on_and_survives_full_setting_writes() {+ let legacy: Setting = serde_json::from_value(serde_json::json!({+ "installed": true,+ "port": 3080,+ "auto_start": true,+ "language": "zh-CN"+ }))+ .expect("legacy setting should deserialize");+ assert!(+ legacy.auto_update,+ "旧配置缺失 auto_update 时应回落默认开启,不能静默关掉老用户的自更新"+ );++ let merged = preserve_persisted_fields(+ Setting::default(),+ &Setting {+ auto_update: false,+ ..Default::default()+ },+ );+ assert!(+ !merged.auto_update,+ "整对象写入不得把用户显式关闭的自动更新翻回开启"+ );+ }+#[test]fn legacy_full_setting_write_preserves_latest_fields() {let stale = Setting {@@ -773,6 +814,7 @@ mod tests {dsh_pkg_tag: Some("new-tag".to_string()),zoom_factor: 0.8,close_action: "quit".to_string(),+ auto_update: false,pet_enabled: false,active_pet: Some("chat:stale".to_string()),pet_size: Some(80.0),@@ -817,6 +859,7 @@ mod tests {assert_eq!(merged.zoom_factor, 1.6);assert_eq!(merged.appearance, current.appearance);assert_eq!(merged.close_action, "tray");+ assert!(merged.auto_update, "整对象写入不得覆盖最新的自动更新开关");assert!(merged.pet_enabled);assert_eq!(merged.active_pet.as_deref(), Some("codex:latest"));assert_eq!(diff --git a/src-tauri/src/service/update/mod.rs b/src-tauri/src/service/update/mod.rsindex 0a9dbb5f..2e4e8859 100644--- a/src-tauri/src/service/update/mod.rs+++ b/src-tauri/src/service/update/mod.rs@@ -14,7 +14,8 @@//! - 安装包下载到 AppData/updates 目录;已存在则视为「已下载」,不再重复拉取。//! - 打开安装器(exe/msi/dmg 等)交给系统默认处理器(ShellExecute/LaunchServices)。//! - 下载完成的安装包登记为「待安装」(见 [`pending`]):用户没立刻安装时,-//! 关闭应用的那一刻自动打开安装器,避免用户错过升级。+//! 关闭应用的那一刻自动打开安装器,避免用户错过升级。该自动链路受设置页+//! 「自动更新」开关约束(issue #1132),关闭后只保留用户显式发起的检查/安装。//!//! 模块划分(参考 `service/cli/`、`service/download/`)://! - [`version`]:版本比较与当前平台安装包资产选择@@ -35,6 +36,22 @@ pub use about::{about, DesktopAboutInfo};pub use install::{check, download, open_installer, DesktopDownloadProgress, DesktopUpdateInfo};pub use pending::launch_pending_installer;+/// 自动更新(静默下载后退出时自动安装)是否生效。+///+/// 唯一真值是设置页「自动更新」开关:关闭后只剩用户显式发起的链路(「检查更新」+/// 与对话框里的「立即更新」),退出时不会拿已下载的安装包替换本应用(issue #1132)。+pub(super) fn auto_update_enabled(app_handle: &tauri::AppHandle) -> bool {+ crate::config::get_store_dat_setting(app_handle).auto_update+}++/// 丢弃「待安装」标记(用户关闭自动更新时调用)。+///+/// 只在退出时按当前设置判断还不够:用户关掉开关、退出前又打开,旧的已下载安装包+/// 会立刻重新变成「退出即安装」——那正是开关要避免的未经确认替换。+pub fn clear_pending_installer(app_handle: &tauri::AppHandle) {+ pending::set(app_handle, None);+}+/// 仓库主页(同时用于构造 atom / expanded_assets / 下载地址)const REPO_URL: &str = "https://github.com/hairyf/deepseek-harness-desktop";/// 版权信息(与 tauri.conf.json bundle.copyright 保持一致)diff --git a/src-tauri/src/service/update/pending.rs b/src-tauri/src/service/update/pending.rsindex 34aba86a..51fa9583 100644--- a/src-tauri/src/service/update/pending.rs+++ b/src-tauri/src/service/update/pending.rs@@ -71,11 +71,15 @@ pub(super) fn set(app_handle: &AppHandle, pending: Option<(&Path, &str)>) {/// 应用退出时自动打开已下载的待安装包。///-/// 只在「已下载但用户没在应用内打开过」时触发(标记由 `install` 模块维护)。+/// 只在「已下载但用户没在应用内打开过」且设置页「自动更新」开启时触发(标记由+/// `install` 模块维护)。关闭自动更新时顺手清掉标记:用户不想被替换安装,残留的+/// 旧安装包也不该在下次退出时突然生效。/// 同步、不触网:退出路径不能引入等待或网络请求,把安装包交给系统默认处理器/// 启动即可(Windows 会触发 UAC,macOS/Linux 交给各自的系统安装流程)。pub fn launch_pending_installer(app_handle: &AppHandle) {- if !super::version::supports_stable_updates(&app_handle.config().identifier) {+ if !super::version::supports_stable_updates(&app_handle.config().identifier)+ || !super::auto_update_enabled(app_handle)+ {set(app_handle, None);return;}diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex 42e9b5a8..114857e1 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -135,6 +135,8 @@"ui.port": "Port","ui.heap_limit": "Service memory limit","ui.heap_limit_auto": "Auto",+ "ui.auto_update": "Automatic updates",+ "ui.auto_update_hint": "Checks for new versions and installs them on exit. Turn this off when a system package manager (e.g. pacman, AUR) manages this app.","ui.launch_on_login": "Launch app at login","ui.launch_on_login_hint": "Starts the desktop app after you sign in. Harness service startup is configured separately.","ui.close_action": "Close action",@@ -184,6 +186,7 @@"messages.port_changed": "Port changed","messages.port_restart_hint": "It takes effect after the service restarts. Restart now?","messages.launch_on_login_failed": "Failed to update launch at login",+ "messages.auto_update_failed": "Failed to update automatic updates","messages.close_action_failed": "Failed to update close action","messages.cli_link_failed": "Failed to update CLI integration","messages.port_invalid": "Port must be an integer between 1 and 65535",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex b0414303..3880eab5 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -135,6 +135,8 @@"ui.port": "服务端口","ui.heap_limit": "服务内存上限","ui.heap_limit_auto": "自动",+ "ui.auto_update": "自动更新",+ "ui.auto_update_hint": "开启后自动检查并在退出时安装新版本;使用系统包管理器(如 pacman、AUR)管理本应用时建议关闭。","ui.launch_on_login": "开机自启动","ui.launch_on_login_hint": "登录系统后启动桌面应用;Harness 服务的自动运行配置与此项相互独立。","ui.close_action": "关闭行为",@@ -184,6 +186,7 @@"messages.port_changed": "端口已更改","messages.port_restart_hint": "重启服务后生效,是否立即重启?","messages.launch_on_login_failed": "更新开机自启动设置失败",+ "messages.auto_update_failed": "更新自动更新设置失败","messages.close_action_failed": "更新关闭行为设置失败","messages.cli_link_failed": "更新命令行集成设置失败","messages.port_invalid": "端口必须是 1 到 65535 之间的整数",diff --git a/src/layout/index.tsx b/src/layout/index.tsxindex 7aecf7e5..537c2764 100644--- a/src/layout/index.tsx+++ b/src/layout/index.tsx@@ -39,6 +39,7 @@ export function App() {const { t } = useTranslation()const { status } = useStore(store.harness)+ const { hydrated: settingReady, auto_update: autoUpdate } = useStore(store.setting)const { updateInfo, updating } = useStore(store.harnessUpdater)const { holder: coreProfileSwitchHolder, guardCoreUpgrade } = useCoreProfileSwitch()@@ -80,12 +81,16 @@ export function App() {// 首次挂载自动启动 harness(store 内部对 StrictMode 重复挂载去重)useMount(() => store.harness.startup())- // 桌面端更新轮询:启动即检查一次,之后低频轮询;失败一律静默(不打扰用户)。+ // 桌面端更新轮询:设置页「自动更新」开启后才检查——关闭后不再静默下载安装包,+ // 也不会在退出时被自动安装(issue #1132)。水合前不检查:默认值不代表用户选择。// 发现新版本由 store 静默下载安装包,更新入口收敛到导航栏 chip 与「帮助 > 检查更新」。+ const autoCheckUpdate = settingReady && autoUpdatefunction checkDesktopUpdate() {+ if (!store.setting.hydrated || !store.setting.auto_update)+ returnvoid store.desktopUpdater.check().catch(() => {})}- useMount(checkDesktopUpdate)+ useWatch([autoCheckUpdate], checkDesktopUpdate, { immediate: true })useIntervalFn(checkDesktopUpdate, DESKTOP_UPDATE_POLL_INTERVAL)// 下载完成提示:dsh iframe 内的下载在 WebView2 中是静默保存的(用户零感知),diff --git a/src/store/modules/desktop-updater/store.test.ts b/src/store/modules/desktop-updater/store.test.tsindex e2332766..a9dff578 100644--- a/src/store/modules/desktop-updater/store.test.ts+++ b/src/store/modules/desktop-updater/store.test.ts@@ -110,6 +110,30 @@ describe('desktop updater operation coordination', () => {})})+ it('stays silent while automatic updates are off but still honors an explicit install', async () => {+ const { setting } = await import('../setting')+ setting.$patch({ auto_update: false })+ const found = { ...UPDATE, downloaded: false }+ mocks.invoke.mockImplementation((command: string) => {+ if (command === 'check_desktop_update')+ return Promise.resolve(found)+ throw new Error(`Unexpected command: ${command}`)+ })++ await expect(desktopUpdater.check()).resolves.toEqual(found)+ expect(mocks.invoke).not.toHaveBeenCalledWith('download_desktop_update')++ mocks.invoke.mockImplementation((command: string) => {+ if (command === 'download_desktop_update')+ return Promise.resolve({ ...found, downloaded: true })+ if (command === 'open_desktop_installer')+ return Promise.resolve()+ throw new Error(`Unexpected command: ${command}`)+ })+ await expect(desktopUpdater.downloadAndOpen()).resolves.toBe(true)+ expect(mocks.invoke).toHaveBeenCalledWith('download_desktop_update')+ })+it('downloads and opens an installer only once for simultaneous actions', async () => {const download = deferred<DesktopUpdateInfo>()const open = deferred<void>()diff --git a/src/store/modules/desktop-updater/store.ts b/src/store/modules/desktop-updater/store.tsindex 998aab5b..1ec53427 100644--- a/src/store/modules/desktop-updater/store.ts+++ b/src/store/modules/desktop-updater/store.ts@@ -8,6 +8,7 @@ import { listen } from '@tauri-apps/api/event'import i18next from 'i18next'import { defineStore } from 'valtio-define'import { toast } from '@/utils/toast'+import { setting } from '../setting'let checkTask: Promise<DesktopUpdateInfo | null> | null = nulllet downloadTask: Promise<void> | null = null@@ -24,7 +25,7 @@ let downloadAndOpenTask: Promise<boolean> | null = null* - 检测到新版本即**静默下载**,不弹右下角 toast、不打断用户;进度只在* 「检查更新」/「更新可用」chip 打开的对话框里展示;* - 用户没在对话框里安装时,Rust 侧会在应用退出时自动打开已下载的安装器- * (见 service::update::pending)。+ * (见 service::update::pending),仅在设置页「自动更新」开启时生效。*/export const desktopUpdater = defineStore({state: () => ({@@ -57,8 +58,12 @@ export const desktopUpdater = defineStore({if (info) {this.updateInfo = info// 检测到更新即静默下载(不弹 toast、不打开安装器);失败静默,- // 用户点击「立即更新」时会重试并给出可见的错误提示- void this.download()+ // 用户点击「立即更新」时会重试并给出可见的错误提示。+ // 「自动更新」关闭后不再静默下载:手动检查只负责展示对话框,下载留给+ // 「立即更新」这类显式动作(issue #1132);这里在异步检查返回后重读开关,+ // 因此检查途中被关掉也不会继续下载。+ if (setting.auto_update)+ void this.download()}else {this.updateInfo = nulldiff --git a/src/store/modules/setting/store.ts b/src/store/modules/setting/store.tsindex 1bdc98e5..ecd7e6e2 100644--- a/src/store/modules/setting/store.ts+++ b/src/store/modules/setting/store.ts@@ -18,6 +18,7 @@ export const setting = defineStore({port: 3080,harness_max_heap_mb: null as number | null,auto_start: true,+ auto_update: true,cli_link_enabled: true,zoom_factor: 1,close_action: 'tray',diff --git a/src/store/modules/setting/types/index.ts b/src/store/modules/setting/types/index.tsindex 4bdc79bc..8513b9a0 100644--- a/src/store/modules/setting/types/index.ts+++ b/src/store/modules/setting/types/index.ts@@ -7,6 +7,7 @@ export interface AppSettingUpdate {zoomFactor?: numberharnessMaxHeapMb?: numberautoStart?: boolean+ autoUpdate?: booleancliLinkEnabled?: booleancloseAction?: stringbackupRetentionCount?: numberdiff --git a/src/ui/config/components/auto-update.test.tsx b/src/ui/config/components/auto-update.test.tsxnew file mode 100644index 00000000..90ef3a62--- /dev/null+++ b/src/ui/config/components/auto-update.test.tsx@@ -0,0 +1,77 @@+// @vitest-environment jsdom+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'+import { defineStore } from 'valtio-define'+import { afterEach, describe, expect, it, vi } from 'vitest'+import { ConfigAutoUpdate } from './auto-update'++const mocks = vi.hoisted(() => ({ setting: {} as any, toast: vi.fn() }))+vi.mock('@/store', () => ({+ store: {+ get setting() {+ return mocks.setting+ },+ },+}))+vi.mock('@/utils/toast', () => ({ toast: mocks.toast }))+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }))++afterEach(() => {+ cleanup()+ vi.clearAllMocks()+})++function setup(initial: boolean, fail = false) {+ const update = vi.fn(async (value: { autoUpdate?: boolean }) => {+ if (fail)+ throw new Error('disk write failed')+ mocks.setting.$patch({ auto_update: value.autoUpdate })+ })+ mocks.setting = defineStore({+ state: () => ({ auto_update: initial }),+ actions: { update },+ })+ const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } })+ render(<QueryClientProvider client={client}><ConfigAutoUpdate /></QueryClientProvider>)+ return update+}++function autoUpdateSwitch(): HTMLInputElement {+ return screen.getByRole('switch', { name: 'ui.auto_update' }) as HTMLInputElement+}++describe('automatic update setting', () => {+ it('reflects the persisted switch value', () => {+ setup(false)++ expect(autoUpdateSwitch().checked).toBe(false)+ })++ it('turns silent download and exit-time installation off through the backend command', async () => {+ const update = setup(true)++ fireEvent.click(autoUpdateSwitch())++ await waitFor(() => expect(update).toHaveBeenLastCalledWith({ autoUpdate: false }))+ await waitFor(() => expect(autoUpdateSwitch().checked).toBe(false))+ expect(mocks.toast).not.toHaveBeenCalled()+ })++ it('turns the switch back on without a success toast', async () => {+ const update = setup(false)++ fireEvent.click(autoUpdateSwitch())++ await waitFor(() => expect(update).toHaveBeenLastCalledWith({ autoUpdate: true }))+ expect(mocks.toast).not.toHaveBeenCalled()+ })++ it('surfaces a failed write as a danger toast and keeps the old value', async () => {+ setup(true, true)++ fireEvent.click(autoUpdateSwitch())++ await waitFor(() => expect(mocks.toast).toHaveBeenCalledWith('messages.auto_update_failed', { variant: 'danger' }))+ expect(autoUpdateSwitch().checked).toBe(true)+ })+})diff --git a/src/ui/config/components/auto-update.tsx b/src/ui/config/components/auto-update.tsxnew file mode 100644index 00000000..2582601a--- /dev/null+++ b/src/ui/config/components/auto-update.tsx@@ -0,0 +1,40 @@+import { Switch } from '@heroui/react'+import { useMutation } from '@tanstack/react-query'+import { useTranslation } from 'react-i18next'+import { useStore } from 'valtio-define'+import { store } from '@/store'+import { toast } from '@/utils/toast'++/** 「自动更新」开关:静默下载 + 退出时自动安装的总开关(issue #1132) */+export function ConfigAutoUpdate() {+ const { t } = useTranslation()+ const { auto_update: autoUpdate } = useStore(store.setting)+ const { mutate: setAutoUpdate, isPending } = useMutation({+ mutationFn: (enabled: boolean) => store.setting.update({ autoUpdate: enabled }),+ onError: (error: unknown) => {+ console.error('[ConfigAutoUpdate] update failed:', error)+ toast(t('messages.auto_update_failed'), { variant: 'danger' })+ },+ })++ return (+ <div>+ <div className="flex items-center justify-between gap-2">+ <span className="text-xs font-medium text-ink">{t('ui.auto_update')}</span>+ <Switch+ isSelected={autoUpdate}+ isDisabled={isPending}+ onChange={setAutoUpdate}+ aria-label={t('ui.auto_update')}+ >+ <Switch.Content>+ <Switch.Control>+ <Switch.Thumb />+ </Switch.Control>+ </Switch.Content>+ </Switch>+ </div>+ <p className="text-[10px] text-muted/70">{t('ui.auto_update_hint')}</p>+ </div>+ )+}diff --git a/src/ui/config/debug.test.tsx b/src/ui/config/debug.test.tsxindex 07509a82..83fb29e5 100644--- a/src/ui/config/debug.test.tsx+++ b/src/ui/config/debug.test.tsx@@ -23,6 +23,7 @@ vi.mock('react-i18next', () => ({}))vi.mock('@/hooks/use-listen', () => ({ useListen: () => {} }))vi.mock('@/ui/config/components/close-action', () => ({ ConfigCloseAction: () => null }))+vi.mock('@/ui/config/components/auto-update', () => ({ ConfigAutoUpdate: () => null }))vi.mock('@/ui/config/components/launch-on-login', () => ({ ConfigLaunchOnLogin: () => null }))vi.mock('@/ui/config/hooks/use-core-profile-switch', () => ({useCoreProfileSwitch: () => ({ holder: null, guardCoreUpgrade: vi.fn() }),diff --git a/src/ui/config/debug.tsx b/src/ui/config/debug.tsxindex 2bae5917..22c219c6 100644--- a/src/ui/config/debug.tsx+++ b/src/ui/config/debug.tsx@@ -13,6 +13,7 @@ import { queryKeys } from '@/config/query-keys'import { useListen } from '@/hooks/use-listen'import { store } from '@/store'import { HARNESS_HEAP_MAX_MB, HARNESS_HEAP_MIN_MB } from '@/store/modules/setting'+import { ConfigAutoUpdate } from '@/ui/config/components/auto-update'import { ConfigCloseAction } from '@/ui/config/components/close-action'import { ConfigLaunchOnLogin } from '@/ui/config/components/launch-on-login'import { useCoreProfileSwitch } from '@/ui/config/hooks/use-core-profile-switch'@@ -348,6 +349,7 @@ export function ConfigDebug() {</div><div className="border-t border-line/30" /><div className="space-y-1.5">+ <ConfigAutoUpdate /><ConfigLaunchOnLogin /><ConfigCloseAction />diff --git a/test/auto-update.test.ts b/test/auto-update.test.tsnew file mode 100644index 00000000..2b1c34a1--- /dev/null+++ b/test/auto-update.test.ts@@ -0,0 +1,62 @@+import { readFileSync } from 'node:fs'+import { describe, expect, it } from 'vitest'++function read(path: string): string {+ return readFileSync(new URL(`../${path}`, import.meta.url), 'utf8')+}++/**+ * 「自动更新」开关的接线契约(issue #1132):用户关闭后不得再静默下载、+ * 也不得在退出时被替换安装。任何一环漏接都会让开关变成装饰。+ */+describe('automatic update opt-out contract', () => {+ it('persists auto_update in the native setting with a backward-compatible default', () => {+ const source = read('src-tauri/src/config/setting.rs')++ expect(source).toContain('pub auto_update: bool')+ expect(source).toContain('#[serde(default = "default_auto_update")]')+ expect(source).toContain('fn default_auto_update() -> bool {')+ // 默认必须是开启:老 store 缺字段时不能被静默关掉既有的自更新行为+ expect(source).toMatch(/fn default_auto_update\(\) -> bool \{\s*true\s*\}/)+ // 整对象写入(旧调用方)不得覆盖精确设置路径写下的开关+ expect(source).toContain('replacement.auto_update = current.auto_update;')+ })++ it('writes the switch through the native config command', () => {+ const source = read('src-tauri/src/bridge/config.rs')++ expect(source).toContain('auto_update: Option<bool>')+ expect(source).toContain('setting.auto_update = auto_update;')+ })++ it('never hands the pending installer over on exit while automatic updates are off', () => {+ const source = read('src-tauri/src/service/update/pending.rs')++ expect(source).toContain('super::auto_update_enabled(app_handle)')+ })++ it('drops the pending installer as soon as the switch is turned off', () => {+ const bridge = read('src-tauri/src/bridge/config.rs')+ const update = read('src-tauri/src/service/update/mod.rs')++ expect(update).toContain('pub fn clear_pending_installer')+ expect(bridge).toContain('if auto_update == Some(false)')+ expect(bridge).toContain('update::clear_pending_installer(&app_handle)')+ })++ it('suppresses the silent download no matter who asks for a check', () => {+ const source = read('src/store/modules/desktop-updater/store.ts')++ // 手动「检查更新」也走 check():开关关闭后只展示对话框,下载留给「立即更新」+ expect(source).toContain('if (setting.auto_update)')+ expect(source).toContain('void this.download()')+ })++ it('stops polling and silent downloads until the switch is on and settings are hydrated', () => {+ const source = read('src/layout/index.tsx')++ expect(source).toContain('store.setting.hydrated')+ expect(source).toContain('store.setting.auto_update')+ expect(source).toContain('void store.desktopUpdater.check()')+ })+})