Skip to content

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

fix(extension): pass row scope to MCP toggle, delete and save (#1120)

w624265201c87a170c62
diff --git a/packages/dsh-tauri-extension/src/client/components/mcp-tab.test.tsx b/packages/dsh-tauri-extension/src/client/components/mcp-tab.test.tsx
index a6bded42..394c361e 100644
--- a/packages/dsh-tauri-extension/src/client/components/mcp-tab.test.tsx
+++ b/packages/dsh-tauri-extension/src/client/components/mcp-tab.test.tsx
@@ -2,19 +2,35 @@
import type { ReactNode } from 'react'
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
-import { getMcp, getMcpAuthorize, postMcpAuthorize, postMcpCheck } from '../apis'
+import { deleteMcp, getMcp, getMcpAuthorize, postMcp, postMcpAuthorize, postMcpCheck, postMcpToggle } from '../apis'
import { McpTab } from './mcp-tab'
const { invoke } = vi.hoisted(() => ({ invoke: vi.fn() }))
vi.mock('../apis', () => ({
+ deleteMcp: vi.fn(),
getMcp: vi.fn(),
+ postMcp: vi.fn(),
postMcpCheck: vi.fn(),
postMcpAuthorize: vi.fn(),
+ postMcpToggle: vi.fn(),
getMcpAuthorize: vi.fn(),
}))
-vi.mock('dsh-tauri/client', () => ({ compact: (items: unknown[]) => items.filter(Boolean), invoke }))
+vi.mock('dsh-tauri/client', () => ({
+ compact: (items: unknown[]) => items.filter(Boolean),
+ isEmpty: (value: object) => Object.keys(value).length === 0,
+ omitBy: (value: Record<string, unknown>, reject: (entry: unknown) => boolean) =>
+ Object.fromEntries(Object.entries(value).filter(([, entry]) => !reject(entry))),
+ invoke,
+}))
vi.mock('../service/restart', () => ({ restartHost: vi.fn() }))
-vi.mock('./mcp-editor-form', () => ({ McpEditorForm: () => null }))
+vi.mock('./mcp-editor-form', () => ({
+ McpEditorForm: ({ onSave, onPasteJsonChange }: { onSave: () => void, onPasteJsonChange: (text: string) => void }) => (
+ <>
+ <button onClick={onSave}>editorSave</button>
+ <button onClick={() => onPasteJsonChange('{"mcpServers":{"fresh":{"command":"node","args":["-v"]}}}')}>editorPaste</button>
+ </>
+ ),
+}))
vi.mock('./mcp-import-dialog', () => ({ McpImportDialog: () => null }))
vi.mock('dsh-tauri-ui/client', () => {
const Content = ({ children }: { children?: ReactNode }) => <div>{children}</div>
@@ -25,7 +41,14 @@ vi.mock('dsh-tauri-ui/client', () => {
Button: ({ children, disabled, onClick }: { children?: ReactNode, disabled?: boolean, onClick?: () => void }) => <button disabled={disabled} onClick={onClick}>{children}</button>,
Card: Object.assign(({ children }: { children?: ReactNode }) => <article>{children}</article>, { List: Content, Title: Content, Description: Content }),
Icon: Empty,
- Modal: Empty,
+ Modal: ({ open, description, children, footer }: { open: boolean, description?: string, children?: ReactNode, footer?: ReactNode }) => open
+ ? (
+ <div data-testid="modal" data-description={description}>
+ {children}
+ {footer}
+ </div>
+ )
+ : null,
PlugConnection: Empty,
Select: Empty,
Tag: Content,
@@ -43,6 +66,9 @@ beforeEach(() => {
vi.mocked(postMcpCheck).mockResolvedValue({ ok: false, detail: 'authorization required', requiresAuth: true })
vi.mocked(postMcpAuthorize).mockResolvedValue({ authorizationUrl: 'https://auth.example.test/authorize', attemptId: 'attempt-1' })
vi.mocked(getMcpAuthorize).mockResolvedValue({ status: 'pending' })
+ vi.mocked(postMcpToggle).mockResolvedValue({ ok: true, restartNeeded: false })
+ vi.mocked(deleteMcp).mockResolvedValue({ ok: true, restartNeeded: false })
+ vi.mocked(postMcp).mockResolvedValue({ ok: true, id: 'same', restartNeeded: false })
invoke.mockResolvedValue(undefined)
Object.defineProperty(window, 'dshDesktop', { configurable: true, value: {} })
})
@@ -175,3 +201,50 @@ it('cancels pending authorization polling when the component unmounts', async ()
await act(() => vi.advanceTimersByTimeAsync(10_000))
expect(getMcpAuthorize).not.toHaveBeenCalled()
})
+
+it('toggles a global row with its own scope instead of the default profile scope', async () => {
+ vi.mocked(getMcp).mockResolvedValue({ servers: [
+ { id: 'global-local', serverName: 'global local', transport: 'stdio', command: 'node', args: ['-v'], disabled: false, scope: 'global' },
+ ], restartNeeded: false })
+ render(<McpTab t={t} />)
+ const card = (await screen.findAllByRole('article'))[0]
+ fireEvent.click(within(card).getByRole('button', { name: 'toggle' }))
+ await waitFor(() => expect(postMcpToggle).toHaveBeenCalledWith({ id: 'global-local', disabled: true, scope: 'global' }))
+ expect(screen.getByRole('status').textContent).toBe('mcpApplied')
+})
+
+it('deletes a global row with its own scope so the confirmation targets the confirmed row', async () => {
+ vi.mocked(getMcp).mockResolvedValue({ servers: [
+ { id: 'global-local', serverName: 'global local', transport: 'stdio', command: 'node', args: ['-v'], disabled: false, scope: 'global' },
+ ], restartNeeded: false })
+ render(<McpTab t={t} />)
+ const card = (await screen.findAllByRole('article'))[0]
+ fireEvent.click(within(card).getByRole('button', { name: 'delete' }))
+ const modal = await screen.findByTestId('modal')
+ expect(modal.dataset.description).toBe('global-local')
+ fireEvent.click(within(modal).getByRole('button', { name: 'delete' }))
+ await waitFor(() => expect(deleteMcp).toHaveBeenCalledWith({ id: 'global-local', scope: 'global' }))
+ expect(screen.getByRole('status').textContent).toBe('mcpApplied')
+})
+
+it('saves an edited global row back to the global layer', async () => {
+ vi.mocked(getMcp).mockResolvedValue({ servers: [
+ { id: 'global-local', serverName: 'global local', transport: 'stdio', command: 'node', args: ['-v'], disabled: false, scope: 'global' },
+ ], restartNeeded: false })
+ render(<McpTab t={t} />)
+ const card = (await screen.findAllByRole('article'))[0]
+ fireEvent.click(within(card).getByRole('button', { name: 'edit' }))
+ fireEvent.click(await screen.findByRole('button', { name: 'editorSave' }))
+ await waitFor(() => expect(postMcp).toHaveBeenCalledWith({ id: 'global-local', scope: 'global', serverName: 'global local', transport: 'stdio', command: 'node', args: ['-v'], env: {} }))
+ expect(screen.getByRole('status').textContent).toBe('mcpApplied')
+})
+
+it('creates a new server in the profile layer through the pasted JSON path', async () => {
+ render(<McpTab t={t} />)
+ await screen.findAllByRole('article')
+ fireEvent.click(screen.getByRole('button', { name: 'addServer' }))
+ fireEvent.click(await screen.findByRole('button', { name: 'editorPaste' }))
+ fireEvent.click(await screen.findByRole('button', { name: 'editorSave' }))
+ await waitFor(() => expect(postMcp).toHaveBeenCalledWith({ id: '', scope: 'profile', serverName: 'fresh', transport: 'stdio', command: 'node', args: ['-v'], env: {} }))
+ expect(screen.getByRole('status').textContent).toBe('mcpApplied')
+})
diff --git a/packages/dsh-tauri-extension/src/client/components/mcp-tab.tsx b/packages/dsh-tauri-extension/src/client/components/mcp-tab.tsx
index 330383d7..398fb4c9 100644
--- a/packages/dsh-tauri-extension/src/client/components/mcp-tab.tsx
+++ b/packages/dsh-tauri-extension/src/client/components/mcp-tab.tsx
@@ -26,7 +26,7 @@ function rowKey(row: McpRow): string {
export function McpTab({ t }: McpTabProps): ReactElement {
const [servers, setServers] = useState<McpRow[] | null>(null)
const [editor, setEditor] = useState<McpEditorState | null>(null)
- const [confirmId, setConfirmId] = useState<string | null>(null)
+ const [confirmRow, setConfirmRow] = useState<McpRow | null>(null)
const [importOpen, setImportOpen] = useState(false)
const [importItems, setImportItems] = useState<McpImportItem[] | null>(null)
const [busy, setBusy] = useState(false)
@@ -221,7 +221,7 @@ export function McpTab({ t }: McpTabProps): ReactElement {
setPasteError(null)
setPasteJson('')
setEditorMode('json')
- setEditor({ id: '', serverName: '', transport: 'stdio', command: '', args: '', env: '', url: '', headers: '' })
+ setEditor({ id: '', scope: 'profile', serverName: '', transport: 'stdio', command: '', args: '', env: '', url: '', headers: '' })
}
const openEdit = (row: McpRow): void => {
@@ -231,6 +231,7 @@ export function McpTab({ t }: McpTabProps): ReactElement {
setEditorMode('form')
setEditor({
id: row.id,
+ scope: rowScope(row),
serverName: row.serverName,
transport: row.transport,
command: row.command ?? '',
@@ -286,6 +287,7 @@ export function McpTab({ t }: McpTabProps): ReactElement {
}
input = {
id: editor.id,
+ scope: editor.scope,
serverName: parsed.serverName?.trim() ?? '',
transport: parsed.transport,
...(parsed.transport === 'stdio'
@@ -296,6 +298,7 @@ export function McpTab({ t }: McpTabProps): ReactElement {
else {
input = {
id: editor.id,
+ scope: editor.scope,
serverName: editor.serverName.trim(),
transport: editor.transport,
...(editor.transport === 'stdio'
@@ -332,7 +335,7 @@ export function McpTab({ t }: McpTabProps): ReactElement {
const doToggle = async (row: McpRow): Promise<void> => {
setBusy(true)
try {
- const body = await postMcpToggle({ id: row.id, disabled: !row.disabled })
+ const body = await postMcpToggle({ id: row.id, disabled: !row.disabled, scope: rowScope(row) })
if ('error' in body)
throw new Error(body.error)
setToast({ text: t(body.restartNeeded ? 'restartNeeded' : 'mcpApplied'), ok: true, seq: Date.now() })
@@ -347,11 +350,11 @@ export function McpTab({ t }: McpTabProps): ReactElement {
}
const doRemove = async (): Promise<void> => {
- if (confirmId === null)
+ if (confirmRow === null)
return
setBusy(true)
try {
- const body = await deleteMcp({ id: confirmId })
+ const body = await deleteMcp({ id: confirmRow.id, scope: rowScope(confirmRow) })
if ('error' in body)
throw new Error(body.error)
setToast({ text: t(body.restartNeeded ? 'restartNeeded' : 'mcpApplied'), ok: true, seq: Date.now() })
@@ -362,7 +365,7 @@ export function McpTab({ t }: McpTabProps): ReactElement {
}
finally {
setBusy(false)
- setConfirmId(null)
+ setConfirmRow(null)
}
}
@@ -451,7 +454,7 @@ export function McpTab({ t }: McpTabProps): ReactElement {
</Button>
<Button variant="ghost" size="sm" disabled={busy} onClick={() => void doToggle(row)}>{t('toggle')}</Button>
<Button variant="ghost" size="sm" disabled={busy} onClick={() => openEdit(row)}>{t('edit')}</Button>
- <Button variant="ghost" size="sm" disabled={busy} onClick={() => setConfirmId(row.id)}>{t('delete')}</Button>
+ <Button variant="ghost" size="sm" disabled={busy} onClick={() => setConfirmRow(row)}>{t('delete')}</Button>
</div>
</Card>
))}
@@ -486,14 +489,14 @@ export function McpTab({ t }: McpTabProps): ReactElement {
</Modal>
<Modal
- open={confirmId !== null}
- onClose={() => setConfirmId(null)}
+ open={confirmRow !== null}
+ onClose={() => setConfirmRow(null)}
closeLabel={t('close')}
title={t('confirmRemove')}
- description={confirmId ?? undefined}
+ description={confirmRow?.id}
footer={(
<>
- <Button variant="ghost" onClick={() => setConfirmId(null)}>{t('cancel')}</Button>
+ <Button variant="ghost" onClick={() => setConfirmRow(null)}>{t('cancel')}</Button>
<Button variant="primary" disabled={busy} onClick={() => void doRemove()}>{t('delete')}</Button>
</>
)}
diff --git a/packages/dsh-tauri-extension/src/client/components/mcp-tab.types.ts b/packages/dsh-tauri-extension/src/client/components/mcp-tab.types.ts
index 6c98da7a..e29ef6b0 100644
--- a/packages/dsh-tauri-extension/src/client/components/mcp-tab.types.ts
+++ b/packages/dsh-tauri-extension/src/client/components/mcp-tab.types.ts
@@ -5,6 +5,7 @@ export type McpEditorMode = 'json' | 'form'
export interface McpEditorState {
id: string
+ scope: 'global' | 'profile'
serverName: string
transport: 'stdio' | 'streamable-http'
command: string