Skip to content

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

feat(ssh): add disable action beside settings tabs (#838)

Mao Mr1d2a4442a2a8
diff --git a/packages/dsh-tauri-ssh/src/client/components/ssh-section.test.tsx b/packages/dsh-tauri-ssh/src/client/components/ssh-section.test.tsx
index 1e69e806..b9cdf9c0 100644
--- a/packages/dsh-tauri-ssh/src/client/components/ssh-section.test.tsx
+++ b/packages/dsh-tauri-ssh/src/client/components/ssh-section.test.tsx
@@ -17,7 +17,7 @@ function bootWire(options: { enabled?: boolean } = {}) {
if (call.url === `${baseURL}/settings` && call.http === 'GET')
return replies.ok({ enabled })
if (call.url === `${baseURL}/settings`) {
- enabled = true
+ enabled = call.body.enabled === true
return replies.ok({ enabled })
}
if (call.url === `${baseURL}/session/role`)
@@ -64,6 +64,23 @@ describe('sshSection', () => {
expect(screen.getByRole('tab', { selected: true }).textContent).toBe('t:tabs.machines')
})
+ it('点击禁用:保存关闭开关后回到 Hero 并卸载已访问的面板', async () => {
+ bootWire({ enabled: true })
+ render(<SshSection t={t as never} />)
+ await waitFor(() => expect(screen.getByTestId('ssh-tabs')).toBeTruthy())
+ fireEvent.click(screen.getByRole('tab', { name: 't:tabs.sync' }))
+
+ const button = screen.getByRole('button', { name: 't:disable' })
+ expect(screen.getByTestId('ssh-tabs').contains(button)).toBe(true)
+ fireEvent.click(button)
+
+ await waitFor(() => expect(screen.getByTestId('ssh-enable').textContent).toBe('t:hero.enable'))
+ expect(sent.filter(call => call.url === `${baseURL}/settings` && call.http === 'POST').map(call => call.body)).toEqual([{ enabled: false }])
+ expect(store.machines.enabled).toBe(false)
+ expect(screen.queryByTestId('ssh-tabs')).toBeNull()
+ expect(screen.queryAllByRole('tabpanel', { hidden: true })).toEqual([])
+ })
+
it('已启用:Tabs 默认停在「SSH 机器」,切换后渲染同步面板且已访问面板保持挂载', async () => {
bootWire({ enabled: true })
render(<SshSection t={t as never} />)
diff --git a/packages/dsh-tauri-ssh/src/client/components/ssh-section.tsx b/packages/dsh-tauri-ssh/src/client/components/ssh-section.tsx
index 78be822e..c87e8e48 100644
--- a/packages/dsh-tauri-ssh/src/client/components/ssh-section.tsx
+++ b/packages/dsh-tauri-ssh/src/client/components/ssh-section.tsx
@@ -68,7 +68,7 @@ export function SshSection({ t }: SshSectionProps): ReactNode {
size="sm"
disabled={state.enabling}
data-testid="ssh-enable"
- onClick={() => void service.enable()}
+ onClick={() => void service.setEnabled(true)}
>
{state.enabling ? t('hero.enabling') : t('hero.enable')}
</Button>
@@ -81,7 +81,7 @@ export function SshSection({ t }: SshSectionProps): ReactNode {
return (
<div className="flex flex-col gap-[12px] max-w-[960px] text-primary" data-testid="ssh-section">
- <div className="flex flex-wrap items-center gap-[8px]" data-testid="ssh-tabs">
+ <div className="flex flex-wrap justify-between items-center gap-[8px]" data-testid="ssh-tabs">
<SegmentedControl
id={SSH_TABS_ID}
label={t('nav')}
@@ -92,6 +92,9 @@ export function SshSection({ t }: SshSectionProps): ReactNode {
openTab(next)
}}
/>
+ <Button variant="ghost" size="sm" disabled={state.enabling} onClick={() => void service.setEnabled(false)}>
+ {t('disable')}
+ </Button>
</div>
{tabs.filter(value => value === tab || visited.has(value)).map((value) => {
const selected = value === tab
diff --git a/packages/dsh-tauri-ssh/src/client/locales/index.ts b/packages/dsh-tauri-ssh/src/client/locales/index.ts
index 48960d35..2c2cc8e6 100644
--- a/packages/dsh-tauri-ssh/src/client/locales/index.ts
+++ b/packages/dsh-tauri-ssh/src/client/locales/index.ts
@@ -9,6 +9,7 @@ export const zh = {
'hero.desc': '把本机作为发起端,用 SSH 连接其他机器上的 dsh 实例:直连使用本机 ~/.ssh 的配置与密钥,可管理多台机器并一键切换、同步插件与 Skill。默认关闭,开启后才建立连接。',
'hero.enable': '启用 SSH',
'hero.enabling': '正在启用…',
+ 'disable': '禁用',
'error.unavailable': 'SSH 服务不可用:插件未加载或本地实例未就绪。',
'title': 'SSH 远程机器',
'intro': '连接直接使用本机 ~/.ssh 的配置与密钥:支持 config 别名、IdentityFile 与默认密钥;密码和私钥口令可选,仅在密钥不可用时作为回退。',
@@ -130,6 +131,7 @@ export const en: Record<keyof typeof zh, string> = {
'hero.desc': 'Drive other machines\' dsh instances from this one over SSH: connections use this machine\'s ~/.ssh directly, and you can keep several machines, switch between them, and sync plugins and skills. Off by default — nothing connects until you enable it.',
'hero.enable': 'Enable SSH',
'hero.enabling': 'Enabling…',
+ 'disable': 'Disable',
'error.unavailable': 'The SSH service is unavailable: the plugin is not loaded or the local instance is not ready.',
'title': 'SSH Remote Machines',
'intro': 'Connections use this machine\'s ~/.ssh directly: config aliases, IdentityFile, and the default keys are honored; password and passphrase are optional fallbacks.',
diff --git a/packages/dsh-tauri-ssh/src/client/service/machines.test.ts b/packages/dsh-tauri-ssh/src/client/service/machines.test.ts
index 5a9f8027..3e416bac 100644
--- a/packages/dsh-tauri-ssh/src/client/service/machines.test.ts
+++ b/packages/dsh-tauri-ssh/src/client/service/machines.test.ts
@@ -313,12 +313,30 @@ describe('feature switch', () => {
return replies.ok({ remote: false })
})
await service.loadSettings()
- await expect(service.enable()).resolves.toEqual({ ok: true })
+ await expect(service.setEnabled(true)).resolves.toEqual({ ok: true })
expect(store.machines.enabled).toBe(true)
expect(store.machines.enabling).toBe(false)
expect(store.machines.machines.map(row => row.id)).toEqual(['a'])
})
+ it('keeps SSH enabled when disabling fails and clears the pending flag', async () => {
+ store.machines.setEnabled(true, null)
+ answer(() => replies.fail('cannot save'))
+ await expect(service.setEnabled(false)).resolves.toEqual({ ok: false, error: 'cannot save' })
+ expect(store.machines.enabled).toBe(true)
+ expect(store.machines.enabling).toBe(false)
+ expect(store.machines.error).toBe('cannot save')
+ })
+
+ it('disables without reloading machines', async () => {
+ store.machines.setEnabled(true, null)
+ answer(() => replies.ok({ enabled: false }))
+ await expect(service.setEnabled(false)).resolves.toEqual({ ok: true })
+ expect(store.machines.enabled).toBe(false)
+ expect(store.machines.enabling).toBe(false)
+ expect(callsOf('/machines', 'GET')).toEqual([])
+ })
+
it('reads an unavailable settings endpoint as disabled with the transport code', async () => {
answer(() => replies.http(405))
await service.loadSettings()
diff --git a/packages/dsh-tauri-ssh/src/client/service/machines.ts b/packages/dsh-tauri-ssh/src/client/service/machines.ts
index 542bc1bd..08592843 100644
--- a/packages/dsh-tauri-ssh/src/client/service/machines.ts
+++ b/packages/dsh-tauri-ssh/src/client/service/machines.ts
@@ -49,10 +49,10 @@ export async function load(): Promise<void> {
}
}
-export async function enable(): Promise<ServiceResult> {
+export async function setEnabled(enabled: boolean): Promise<ServiceResult> {
store.machines.beginEnable()
try {
- store.machines.setEnabled(enabledOf(await api.postSettings({ enabled: true })) !== false, null)
+ store.machines.setEnabled(enabledOf(await api.postSettings({ enabled })) ?? enabled, null)
if (store.machines.enabled === true)
await load()
return { ok: true }