Skip to content

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

fix(rightclick): 工作区右键「新建会话」不再静默失败 (#780) (#782)

Mao Mr7a46548b8161
diff --git a/packages/dsh-tauri-rightclick/package.json b/packages/dsh-tauri-rightclick/package.json
index ab2c68e2..f790c75a 100644
--- a/packages/dsh-tauri-rightclick/package.json
+++ b/packages/dsh-tauri-rightclick/package.json
@@ -37,6 +37,7 @@
"client": {
"inject": [
"@deepseek-ai/dsh-client-ui-layout",
+ "@deepseek-ai/dsh-client-ui-workspace",
"dsh-tauri",
"dsh-tauri-ui"
],
diff --git a/packages/dsh-tauri-rightclick/src/client/index.test.ts b/packages/dsh-tauri-rightclick/src/client/index.test.ts
new file mode 100644
index 00000000..585346cf
--- /dev/null
+++ b/packages/dsh-tauri-rightclick/src/client/index.test.ts
@@ -0,0 +1,41 @@
+import { readFileSync } from 'node:fs'
+import { dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { describe, expect, it, vi } from 'vitest'
+import { apply, inject } from './index'
+
+// 包根的装配面在 node 下无法求值:dsh-tauri/client 是 ModuleLoader 工厂产物,
+// 右键特征又会拉到 react-dom/client。这里只关心服务依赖与 effect 装配,故把
+// 两侧都换成最小形状(vitest 会把 vi.mock 提升到 import 之前,位置在此安全)。
+vi.mock('dsh-tauri/client', () => ({
+ defineLocale: () => ({ registerLocale: () => () => {}, text: (key: string) => key }),
+}))
+
+vi.mock('./register/context-menu', () => ({
+ contextMenuFeature: () => () => {},
+}))
+
+const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..')
+
+interface PackageManifest {
+ dsh?: { client?: { inject?: unknown } }
+}
+
+describe('rightclick client plugin', () => {
+ it('declares uiWorkspace so apply waits for the workspace service (issue #780)', () => {
+ expect(inject).toEqual(['locale', 'sessions', 'workspaces', 'uiWorkspace'])
+ })
+
+ it('lists the workspace package among the dsh.client inject edges', () => {
+ const manifest = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8')) as PackageManifest
+ expect(manifest.dsh?.client?.inject).toContain('@deepseek-ai/dsh-client-ui-workspace')
+ })
+
+ it('registers the locale and context-menu effects on activation', () => {
+ const effect = vi.fn()
+ apply({ effect } as unknown as Parameters<typeof apply>[0])
+ expect(effect).toHaveBeenCalledTimes(2)
+ expect(effect).toHaveBeenCalledWith(expect.any(Function), 'dsh-tauri-rightclick: locale')
+ expect(effect).toHaveBeenCalledWith(expect.any(Function), 'dsh-tauri-rightclick: context menu')
+ })
+})
diff --git a/packages/dsh-tauri-rightclick/src/client/index.ts b/packages/dsh-tauri-rightclick/src/client/index.ts
index 123dc21b..ecce5f92 100644
--- a/packages/dsh-tauri-rightclick/src/client/index.ts
+++ b/packages/dsh-tauri-rightclick/src/client/index.ts
@@ -5,7 +5,7 @@ import { contextMenuFeature } from './register/context-menu'
export const name = PLUGIN_ID
-export const inject = ['locale', 'sessions', 'workspaces']
+export const inject = ['locale', 'sessions', 'workspaces', 'uiWorkspace']
export function apply(ctx: ClientContext): void {
ctx.effect(locale.registerLocale, LOCALE_EFFECT)
diff --git a/packages/dsh-tauri-rightclick/src/client/locales/index.ts b/packages/dsh-tauri-rightclick/src/client/locales/index.ts
index c9f9493b..a7085931 100644
--- a/packages/dsh-tauri-rightclick/src/client/locales/index.ts
+++ b/packages/dsh-tauri-rightclick/src/client/locales/index.ts
@@ -68,6 +68,7 @@ const zh = {
sessionUnknown: '无法确定当前会话',
sessionNameEmpty: '会话名称不能为空',
sessionServiceUnavailable: '无法取得官方会话服务',
+ newSessionUnavailable: '无法在该工作区新建会话',
renameFailed: '重命名失败',
editPositionUnknown: '无法确定编辑位置',
} as const satisfies Record<string, string>
@@ -139,6 +140,7 @@ const en: Record<keyof typeof zh, string> = {
sessionUnknown: 'Could not determine the current session',
sessionNameEmpty: 'Session name cannot be empty',
sessionServiceUnavailable: 'Official session service is unavailable',
+ newSessionUnavailable: 'Could not create a session in this workspace',
renameFailed: 'Rename failed',
editPositionUnknown: 'Could not determine the editing position',
}
diff --git a/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts b/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts
index a5e082f2..988f80cf 100644
--- a/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts
+++ b/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts
@@ -20,6 +20,7 @@ import {
openExternalUrl,
openInExplorer,
renameSession,
+ startWorkspaceSession,
supportsSessionPin,
togglePinSession,
} from '../service/menu'
@@ -162,10 +163,10 @@ export function buildWorkspaceMenu(
): void {
const workspace = target.workspace
- composer.add(locale.text('newSession'), () => {
- // 工作区投影与 workspaces 服务来自两份内核代各自的包实例,保留既有的运行时交界断言。
- composer.workspaces.startSession?.(workspace.workspaceId as unknown as WorkspaceId)
- })
+ composer.add(locale.text('newSession'), () => startWorkspaceSession({
+ workspaces: composer.workspaces,
+ workspaceId: workspace.workspaceId as unknown as WorkspaceId,
+ }))
composer.add(locale.text('openInExplorer'), () => openInExplorer({ path: workspace.path }))
composer.split()
diff --git a/packages/dsh-tauri-rightclick/src/client/service/menu.test.ts b/packages/dsh-tauri-rightclick/src/client/service/menu.test.ts
index 1c142ea2..0445a490 100644
--- a/packages/dsh-tauri-rightclick/src/client/service/menu.test.ts
+++ b/packages/dsh-tauri-rightclick/src/client/service/menu.test.ts
@@ -12,6 +12,7 @@ import {
openExternalUrl,
openInExplorer,
renameSession,
+ startWorkspaceSession,
supportsSessionPin,
togglePinSession,
} from './menu'
@@ -377,3 +378,44 @@ describe('session pin (official 0.1.7 capability)', () => {
.toEqual({ ok: false, error: 'archive-conflict' })
})
})
+
+describe('startWorkspaceSession', () => {
+ it('reports the missing navigation capability instead of silently doing nothing', async () => {
+ // legacy 投影在两份候选服务都没有 startSession 时把该属性读为 undefined(不是抛错);
+ // 旧实现用 `startSession?.()` 可选链,点击菜单项后完全没有反馈(issue #780)。
+ const workspaces = {
+ list: { getSnapshot: () => ({ items: [], archivedSessionIds: [] }) },
+ } as unknown as WorkspacesRuntimeLike
+
+ await expect(startWorkspaceSession({ workspaces, workspaceId: WORKSPACE_ID }))
+ .resolves
+ .toEqual({ ok: false, error: 'newSessionUnavailable' })
+ })
+
+ it('starts the session in the requested workspace with the service as receiver', async () => {
+ const seen: unknown[] = []
+ const startSession = vi.fn(function (this: unknown, workspaceId: WorkspaceId) {
+ seen.push(this)
+ expect(workspaceId).toBe(WORKSPACE_ID)
+ })
+ const workspaces = { startSession } as unknown as WorkspacesRuntimeLike
+
+ await expect(startWorkspaceSession({ workspaces, workspaceId: WORKSPACE_ID }))
+ .resolves
+ .toEqual({ ok: true })
+ expect(startSession).toHaveBeenCalledWith(WORKSPACE_ID)
+ expect(seen[0]).toBe(workspaces)
+ })
+
+ it('awaits an async official implementation and surfaces its rejection', async () => {
+ const workspaces = {
+ startSession: async () => {
+ throw new Error('workspace-locked')
+ },
+ } as unknown as WorkspacesRuntimeLike
+
+ await expect(startWorkspaceSession({ workspaces, workspaceId: WORKSPACE_ID }))
+ .resolves
+ .toEqual({ ok: false, error: 'workspace-locked' })
+ })
+})
diff --git a/packages/dsh-tauri-rightclick/src/client/service/menu.ts b/packages/dsh-tauri-rightclick/src/client/service/menu.ts
index 09eac619..32d82bfe 100644
--- a/packages/dsh-tauri-rightclick/src/client/service/menu.ts
+++ b/packages/dsh-tauri-rightclick/src/client/service/menu.ts
@@ -174,6 +174,28 @@ export async function deleteWorkspace(input: {
}
}
+/**
+ * Action:在指定工作区新建会话。
+ *
+ * legacy 投影在两个候选服务都没有 `startSession` 时把该属性读为 undefined(不是抛错),
+ * 可选链调用就会静默什么都不做(issue #780),因此这里显式回报不可用。
+ */
+export async function startWorkspaceSession(input: {
+ workspaces: WorkspacesRuntimeLike
+ workspaceId: WorkspaceId
+}): Promise<ActionOutcome> {
+ const start = input.workspaces.startSession
+ if (typeof start !== 'function')
+ return { ok: false, error: locale.text('newSessionUnavailable') }
+ try {
+ await start.call(input.workspaces, input.workspaceId)
+ return { ok: true }
+ }
+ catch (error) {
+ return fail(error)
+ }
+}
+
// --- internal ---
function fail(error: unknown): ActionOutcome {
diff --git a/packages/dsh-tauri-rightclick/src/client/types/index.ts b/packages/dsh-tauri-rightclick/src/client/types/index.ts
index 48785327..5c917106 100644
--- a/packages/dsh-tauri-rightclick/src/client/types/index.ts
+++ b/packages/dsh-tauri-rightclick/src/client/types/index.ts
@@ -32,7 +32,7 @@ export type WorkspaceListSnapshotLike = Pick<WorkspaceSnapshot, 'items' | 'archi
/** 官方 workspaces 服务加上 alpha/桌面导航兼容扩展。 */
export type WorkspacesRuntimeLike = Pick<IWorkspaces, 'list' | 'archiveSession' | 'delete'> & {
- startSession?: (workspaceId: WorkspaceId) => void
+ startSession?: (workspaceId: WorkspaceId) => unknown
/** 置顶/取消置顶会话:0.1.7 起官方提供;旧核心缺席时右键菜单不展示该入口。 */
pinSession?: (sessionId: SessionId) => Promise<void>
unpinSession?: (sessionId: SessionId) => Promise<void>