DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(dsh-tauri-ui): bind workspace creation to service (#689)
hairyf8f2c8356ee75
diff --git a/packages/dsh-tauri-ui/src/client/register/hero-workspace.test.ts b/packages/dsh-tauri-ui/src/client/register/hero-workspace.test.tsindex d0fbed58..4e37ceba 100644--- a/packages/dsh-tauri-ui/src/client/register/hero-workspace.test.ts+++ b/packages/dsh-tauri-ui/src/client/register/hero-workspace.test.ts@@ -14,10 +14,14 @@ const HERO_WORKSPACE_FLOW_SLOT = 'conversation.hero.workspace.directoryFlow'const HERO_WORKSPACE_PRIORITY = -1const mocks = vi.hoisted(() => ({- createWorkspace: vi.fn(),+ workspaceService: {+ model: { create: vi.fn() },+ create(input: { path: string }) { return this.model.create(input) },+ },startUngroupedSession: vi.fn(),registrations: [] as Array<{ key: string, options: Record<string, unknown>, component: unknown }>,composerWorkspaceLess: true,+ workspaceServiceAvailable: true,}))vi.mock('../service/ungrouped-session', () => ({ startUngroupedSession: mocks.startUngroupedSession }))@@ -45,7 +49,9 @@ vi.mock('dsh-tauri/client', () => ({},}setup(controller, this, {- service: (name: string) => name === 'workspaces' ? { create: mocks.createWorkspace } : undefined,+ service: (name: string) => name === 'workspaces' && mocks.workspaceServiceAvailable+ ? mocks.workspaceService+ : undefined,has: () => mocks.composerWorkspaceLess,})return () => controller.dispose()@@ -77,6 +83,7 @@ function createCtx(options: { flowOccupied?: boolean } = {}) {afterEach(() => {mocks.registrations.length = 0mocks.composerWorkspaceLess = true+ mocks.workspaceServiceAvailable = truevi.restoreAllMocks()vi.clearAllMocks()})@@ -99,18 +106,22 @@ describe('heroWorkspaceFeature', () => {dispose()})- it('inject 工厂交出官方建工作区能力、未分组新建动作与目录流程占用源', () => {+ it('inject 工厂绑定官方建工作区服务、未分组新建动作与目录流程占用源', async () => {const { ctx, subscribe } = createCtx({ flowOccupied: true })const dispose = heroWorkspaceFeature.call(ctx)const injectFactory = mocks.registrations[0]?.options.inject as () => {- createWorkspace?: unknown+ createWorkspace?: (input: { path: string }) => Promise<{ workspaceId: string }>startUngrouped: () => voidhooks: { directoryFlow: { getSnapshot: () => boolean, subscribe: (listener: () => void) => () => void } }}const injected = injectFactory()- expect(injected.createWorkspace, '建工作区能力直接来自适配层的官方 workspaces.create').toBe(mocks.createWorkspace)+ const workspace = { workspaceId: 'workspace-new' }+ mocks.workspaceService.model.create.mockResolvedValue(workspace)+ expect(injected.createWorkspace).toBeTypeOf('function')+ await expect(injected.createWorkspace!({ path: '/tmp/example' })).resolves.toBe(workspace)+ expect(mocks.workspaceService.model.create).toHaveBeenCalledWith({ path: '/tmp/example' })injected.startUngrouped()expect(mocks.startUngroupedSession).toHaveBeenCalledTimes(1)@@ -122,6 +133,23 @@ describe('heroWorkspaceFeature', () => {dispose()})+ it('工作区服务晚于适配层就绪时仍可创建,缺席时不暴露入口', async () => {+ const { ctx } = createCtx()+ mocks.workspaceServiceAvailable = false+ const dispose = heroWorkspaceFeature.call(ctx)+ const injectFactory = mocks.registrations[0]?.options.inject as () => {+ createWorkspace?: (input: { path: string }) => Promise<{ workspaceId: string }>+ }++ expect(injectFactory().createWorkspace).toBeUndefined()+ mocks.workspaceServiceAvailable = true+ const workspace = { workspaceId: 'workspace-late' }+ mocks.workspaceService.model.create.mockResolvedValue(workspace)+ await expect(injectFactory().createWorkspace!({ path: '/tmp/late' })).resolves.toBe(workspace)+ expect(mocks.workspaceService.model.create).toHaveBeenCalledWith({ path: '/tmp/late' })+ dispose()+ })+it('缺 composer 补丁时不接管:保留官方工作区选择器并告警', () => {const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})mocks.composerWorkspaceLess = falsediff --git a/packages/dsh-tauri-ui/src/client/register/hero-workspace.ts b/packages/dsh-tauri-ui/src/client/register/hero-workspace.tsindex 717096e7..928de0b7 100644--- a/packages/dsh-tauri-ui/src/client/register/hero-workspace.ts+++ b/packages/dsh-tauri-ui/src/client/register/hero-workspace.ts@@ -48,5 +48,6 @@ export const heroWorkspaceFeature = defineRegister<ClientContext>((controller, c/** 调用期解析:适配层创建期的 `adapter.workspaces` 快照可能因服务晚到而永久缺席。 */function readCreateWorkspace(adapter: ClientAdapter): AdapterWorkspaces['create'] {- return adapter.service<AdapterWorkspaces>('workspaces')?.create+ const workspaces = adapter.service<AdapterWorkspaces>('workspaces')+ return workspaces?.create?.bind(workspaces)}