Skip to content

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

fix(dsh-tauri-ui): 工作区服务读取吞掉 inject-only 守卫抛错;收紧未分组 E2E 定位

hairyfac6b1ac9daf3
diff --git a/packages/dsh-tauri-ui/src/client/service/ungrouped-session.test.ts b/packages/dsh-tauri-ui/src/client/service/ungrouped-session.test.ts
index 51ea1905..37e6caa8 100644
--- a/packages/dsh-tauri-ui/src/client/service/ungrouped-session.test.ts
+++ b/packages/dsh-tauri-ui/src/client/service/ungrouped-session.test.ts
@@ -17,6 +17,7 @@ interface CtxOptions {
blank?: boolean
sessionIds?: readonly SessionId[]
workspacesAvailable?: boolean
+ workspacesThrows?: boolean
create?: () => Promise<SessionId>
}
@@ -39,9 +40,14 @@ function createCtx(options: CtxOptions = {}) {
open,
},
layout: { selectPanel },
- get: (name: string) => name === 'workspaces' && options.workspacesAvailable !== false
- ? { list: { getSnapshot: () => ({ items }) } }
- : undefined,
+ get: (name: string) => {
+ if (name !== 'workspaces' || options.workspacesAvailable === false)
+ return undefined
+ // inject-only 守卫的真实形态:未注入的服务名读属性即抛错。
+ if (options.workspacesThrows === true)
+ throw new Error('service "workspaces" is not injected')
+ return { list: { getSnapshot: () => ({ items }) } }
+ },
} as unknown as ClientContext
return { ctx, create, open, selectPanel }
}
@@ -96,6 +102,15 @@ describe('startUngroupedSession', () => {
expect(create).not.toHaveBeenCalled()
})
+ it('工作区服务读取抛错(inject-only 守卫)时同样按「无法判断」处理,不阻断开会话', async () => {
+ const { ctx, create, open } = createCtx({ current: UNGROUPED, blank: true, workspacesThrows: true })
+
+ startUngroupedSession(ctx)
+
+ await vi.waitFor(() => expect(open).toHaveBeenCalledWith(UNGROUPED))
+ expect(create).not.toHaveBeenCalled()
+ })
+
it('创建失败只告警:不打开会话、不把 rejection 漏给调用点', async () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
const failure = new Error('boom')
diff --git a/packages/dsh-tauri-ui/src/client/service/ungrouped-session.ts b/packages/dsh-tauri-ui/src/client/service/ungrouped-session.ts
index bc7b1417..b6f897b0 100644
--- a/packages/dsh-tauri-ui/src/client/service/ungrouped-session.ts
+++ b/packages/dsh-tauri-ui/src/client/service/ungrouped-session.ts
@@ -33,8 +33,13 @@ interface WorkspacesRuntime {
list: { getSnapshot: () => { items: readonly { sessionIds: readonly SessionId[] }[] } }
}
-/** 走 `ctx.get`:本插件只声明了 `sessions`,读未注入的服务名会被 inject-only 守卫抛错。 */
+/** 走 `ctx.get` 并吞掉 inject-only 守卫的抛错:读不到时按「无法判断」处理,绝不阻断开会话。 */
function readWorkspaces(ctx: ClientContext): readonly { sessionIds: readonly SessionId[] }[] | undefined {
- const workspaces = ctx.get('workspaces') as WorkspacesRuntime | undefined
- return workspaces?.list.getSnapshot().items
+ try {
+ const workspaces = ctx.get('workspaces') as WorkspacesRuntime | undefined
+ return workspaces?.list.getSnapshot().items
+ }
+ catch {
+ return undefined
+ }
}
diff --git a/test/e2e/plugins/dsh-tauri-ui.e2e.ts b/test/e2e/plugins/dsh-tauri-ui.e2e.ts
index 54d8ef6a..56732ce2 100644
--- a/test/e2e/plugins/dsh-tauri-ui.e2e.ts
+++ b/test/e2e/plugins/dsh-tauri-ui.e2e.ts
@@ -245,11 +245,16 @@ describe('L2 客户端', () => {
await app.frame.locator(HERO_WORKSPACE_CHIP).click()
+ // 只认当前**可见**的菜单:文档里可能同时挂着别的已挂载菜单(portal 到 body),
+ // 不限定范围会把别的菜单条目当成这条选择器的结果。
const menu = await app.frame.evaluate(() => {
const chip = document.querySelector('.dshp-hero-workspace')
- const items = Array.from(document.querySelectorAll('button[role="menuitem"]')) as HTMLButtonElement[]
+ const menus = Array.from(document.querySelectorAll('[role="menu"]'))
+ .filter(menu => menu.getClientRects().length > 0)
+ const items = Array.from(menus[0]?.querySelectorAll('button[role="menuitem"]') ?? []) as HTMLButtonElement[]
return {
expanded: chip?.getAttribute('aria-expanded') ?? null,
+ visibleMenus: menus.length,
count: items.length,
labels: items.map(item => item.textContent?.trim() ?? ''),
firstDisabled: items[0]?.disabled ?? null,
@@ -257,6 +262,7 @@ describe('L2 客户端', () => {
})
expect(menu.expanded, '菜单打开时 chip 必须回报 aria-expanded').toBe('true')
+ expect(menu.visibleMenus, '打开后必须只有本选择器这一个可见菜单(否则断言对象不确定)').toBe(1)
expect(menu.count, '打开后必须渲染菜单条目').toBeGreaterThan(0)
expect(menu.labels[0], '「未分组」必须是第一个选项').toBe('未分组')
expect(menu.labels.filter(label => label === '未分组'), '「未分组」只能出现一次').toHaveLength(1)
@@ -278,7 +284,13 @@ describe('L2 客户端', () => {
expect(before.inert, '夹具前置:没有会话时 composer 是官方的「选择工作区」触发器').toBe(true)
// 品牌按钮与工具栏按钮共用 aria-label(官方 sidebar 词典 `session.new.label`),
- // 品牌按钮被全局样式隐藏,这里点的是可见的工具栏按钮。
+ // 品牌按钮被全局样式隐藏:先断言可见的只剩工具栏那一枚,再点它,避免点到别的按钮。
+ const visibleNewSession = await app.frame.evaluate(() =>
+ Array.from(document.querySelectorAll('button[aria-label="新建会话"]'))
+ .filter(button => button.getClientRects().length > 0)
+ .map(button => button.getAttribute('aria-label')))
+ expect(visibleNewSession, '可见的「新建会话」按钮必须唯一(品牌按钮已隐藏)').toHaveLength(1)
+
await app.frame.locator(SIDEBAR_NEW_SESSION).first().click()
await expect.poll(