Skip to content

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

test(e2e): 收紧断言、暴露静默失败并统一宿主解析

hairyf283591ab5ede
diff --git a/test/e2e/desktop/02-pet-window.e2e.ts b/test/e2e/desktop/02-pet-window.e2e.ts
index 342c71a5..38445936 100644
--- a/test/e2e/desktop/02-pet-window.e2e.ts
+++ b/test/e2e/desktop/02-pet-window.e2e.ts
@@ -1,14 +1,14 @@
/**
- * 批次 02 的 L3 段 · `dsh-tauri-pet` 的**独立桌宠窗口**(用例来源:
- * `docs/testing/plugins/02-dsh-tauri-pet.md` §4 的 `TC-PET-L3-02-001..004`)。
+ * 批次 02 的 L3 段 · `dsh-tauri-pet` 的**独立桌宠窗口**(契约见 `docs/specs/desktop.test.md`
+ * 与 `docs/specs/plugin.test.md`;用例编号 `TC-PET-L3-02-001..004`)。
*
- * 为什么这一段的运行归属是 `desktop` 车道而不是 `plugin` 车道(子设计 §2 决策 1):
- * 四条断言的对象都是 **Tauri 原生产物**——独立 OS 窗口句柄集合(`main` / `pet`)、
- * 窗口创建与销毁、尺寸边界的命令级拒绝。这些在纯浏览器里不可能观测,而 `plugin`
- * 车道的 CI 作业跑在 ubuntu-latest、没有 Tauri;把用例留在插件文件里就等于「写了却永不执行」。
+ * 为什么这一段的运行归属是 `desktop` 车道而不是 `plugin` 车道:四条断言的对象都是
+ * **Tauri 原生产物**——独立 OS 窗口句柄集合(`main` / `pet`)、窗口创建与销毁、尺寸边界的
+ * 命令级拒绝。这些在纯浏览器里不可能观测,而 `plugin` 车道的 CI 作业跑在 ubuntu-latest、
+ * 没有 Tauri;把用例留在插件文件里就等于「写了却永不执行」。
*
* 前置:Windows + `pnpm build:debug`。运行:
- * `pnpm test:e2e:desktop -- --run test/e2e/desktop/02-pet-window.e2e.ts`
+ * `node node_modules/vitest/vitest.mjs run --project desktop test/e2e/desktop/02-pet-window.e2e.ts`
* (本机若已有桌面实例占着 WebDriver 4445,用 `TAURI_WEBDRIVER_PORT=<空闲端口>` 另开一路。)
*
* 命令通道(实测确定的唯一可行路径):**帧内** `__TAURI_INTERNALS__.invoke` 会被
@@ -16,6 +16,11 @@
* **壳层**(`main` webview,`http://tauri.localhost/`)里调用——那里的 `invoke` 直连
* Rust。启用/关闭走侧栏入口的真实点击(用户路径),只读状态走壳层 `get_pet_status`。
* 窗口句柄集合经 `getWindowHandles()` 读取,是「独立 OS 窗口是否真的存在」的外部证据。
+ *
+ * 报错采集(与 `boot.e2e.ts` 同源):壳层在 `startDesktopApp()` 之后立即装收集器,帧内在
+ * 进入 iframe 后装同一个收集器;001/003/004 三条点击驱动的用例在收尾断言两边都为空。
+ * 盲区与 `desktop.test.md` 一致:**只能在进入上下文之后安装**,因此帧内与 `pet` WebView 的
+ * 加载期报错不可观测(后者由「窗口句柄真的出现 / 消失 + 命令级状态收敛」间接兜底)。
*/
import type { DesktopApp } from '../support/desktop-host'
@@ -58,6 +63,33 @@ function elementExists(selector: string): boolean {
return document.querySelector(selector) !== null
}
+/**
+ * 在页面(壳层或帧内)安装报错收集器:三类页面级错误收进 `window.__dshE2eErrors`。
+ *
+ * 只装一次;`console.error` 保留原实现,收集不改变页面行为。
+ */
+function collectPageErrors(): void {
+ const host = window as unknown as { __dshE2eErrors?: string[] }
+ if (host.__dshE2eErrors)
+ return
+
+ const errors: string[] = []
+ host.__dshE2eErrors = errors
+ window.addEventListener('error', event => errors.push(`error: ${event.message}`))
+ window.addEventListener('unhandledrejection', event => errors.push(`unhandledrejection: ${String(event.reason)}`))
+
+ const original = console.error.bind(console)
+ console.error = (...args: unknown[]) => {
+ errors.push(`console.error: ${args.map(String).join(' ')}`)
+ original(...args)
+ }
+}
+
+/** 读回当前上下文的报错收集器;收集器不存在时返回空数组。 */
+function readPageErrors(): string[] {
+ return (window as unknown as { __dshE2eErrors?: string[] }).__dshE2eErrors ?? []
+}
+
/** 元素的 `aria-pressed`。 */
function elementAriaPressed(selector: string): string | null {
return document.querySelector(selector)?.getAttribute('aria-pressed') ?? null
@@ -79,10 +111,14 @@ describe.skipIf(process.platform !== 'win32')('桌面端桌宠独立窗口', ()
beforeAll(async () => {
app = await startDesktopApp()
const browser = app.browser
+ // 尽早装壳层收集器:装配失败、iframe 加载失败都会在壳层留下痕迹
+ await browser.execute(collectPageErrors)
const iframe = await browser.$(SHELL_IFRAME)
await completePreinstall(browser, ASSEMBLY_TIMEOUT_MS)
await iframe.waitForDisplayed({ timeout: ASSEMBLY_TIMEOUT_MS })
await browser.switchFrame(iframe)
+ // 帧内收集器只能在进入帧之后安装,因此加载期报错不在覆盖范围内
+ await browser.execute(collectPageErrors)
await browser.waitUntil(
() => browser.execute(elementExists, PET_ICON),
{ timeout: 60_000, timeoutMsg: '内嵌 dsh 界面未渲染出桌宠入口(插件 client 未生效)' },
@@ -92,6 +128,30 @@ describe.skipIf(process.platform !== 'win32')('桌面端桌宠独立窗口', ()
await setEnabled(false)
}, ASSEMBLY_TIMEOUT_MS)
+ /** 壳层报错快照(当前上下文必须已在壳层)。 */
+ async function shellErrors(): Promise<string[]> {
+ return await app!.browser.execute(readPageErrors) as string[]
+ }
+
+ /** 帧内报错快照:自行进出 iframe,调用方不必关心当前上下文。 */
+ async function frameErrors(): Promise<string[]> {
+ const browser = app!.browser
+ const iframe = await browser.$(SHELL_IFRAME)
+ await browser.switchFrame(iframe)
+ try {
+ return await browser.execute(readPageErrors) as string[]
+ }
+ finally {
+ await browser.switchFrame(null)
+ }
+ }
+
+ /** 收尾断言:壳层与内嵌 dsh 页面都不得留下未捕获错误。 */
+ async function expectNoPageErrors(scene: string): Promise<void> {
+ expect(await frameErrors(), `${scene}:内嵌 dsh 页面出现报错`).toEqual([])
+ expect(await shellErrors(), `${scene}:壳层出现报错`).toEqual([])
+ }
+
afterAll(async () => {
await app?.stop()
})
@@ -212,6 +272,8 @@ describe.skipIf(process.platform !== 'win32')('桌面端桌宠独立窗口', ()
// 用例(003)首次点击就成了幂等写、窗口不会出现——上一轮 003 失败的实测原因。
await clickIconToggling('true', [MAIN_WEBVIEW], '再次点击入口后 pet 窗口必须销毁')
expect((await status()).enabled, '关闭后状态必须回到 enabled:false').toBe(false)
+
+ await expectNoPageErrors('TC-PET-L3-02-001 建窗/销毁全流程')
})
it('TC-PET-L3-02-002 [反向] 未启用桌宠时不存在桌宠窗口', async () => {
@@ -234,6 +296,8 @@ describe.skipIf(process.platform !== 'win32')('桌面端桌宠独立窗口', ()
await clickIconToggling('true', [MAIN_WEBVIEW], '二次点击后 pet 窗口必须销毁')
expect((await status()).enabled, '二次点击后状态必须回到 enabled:false').toBe(false)
+
+ await expectNoPageErrors('TC-PET-L3-02-003 点击切换往返')
})
it('TC-PET-L3-02-004 桌宠尺寸边界:范围内接受、越界拒绝且不改状态', async () => {
@@ -256,5 +320,7 @@ describe.skipIf(process.platform !== 'win32')('桌面端桌宠独立窗口', ()
await app!.browser.execute(shellInvoke, 'set_pet_size', { size: PET_SIZE_DEFAULT })
expect((await status()).pet_size, '收尾必须恢复默认尺寸').toBe(PET_SIZE_DEFAULT)
await setEnabled(false)
+
+ await expectNoPageErrors('TC-PET-L3-02-004 尺寸边界')
})
})
diff --git a/test/e2e/plugins/01-dsh-host-and-core-contract.e2e.ts b/test/e2e/plugins/01-dsh-host-and-core-contract.e2e.ts
index 3137fea1..8cad367f 100644
--- a/test/e2e/plugins/01-dsh-host-and-core-contract.e2e.ts
+++ b/test/e2e/plugins/01-dsh-host-and-core-contract.e2e.ts
@@ -1,5 +1,5 @@
/**
- * 批次 01 · 编排骨架与共享路由契约(用例来源:`docs/testing/plugins/01-dsh-host-and-core-contract.md`)。
+ * 批次 01 · 编排骨架与共享路由契约(契约见 `docs/specs/plugin.test.md`)。
*
* 本批是全套插件用例的地基,两段各有不可替代的作用:
* - 编排骨架不成立时,后面所有「插件路由 404」都无法区分是插件没挂上还是宿主没起来;
diff --git a/test/e2e/plugins/02-dsh-tauri-pet.e2e.ts b/test/e2e/plugins/02-dsh-tauri-pet.e2e.ts
index 6c918957..6018db7f 100644
--- a/test/e2e/plugins/02-dsh-tauri-pet.e2e.ts
+++ b/test/e2e/plugins/02-dsh-tauri-pet.e2e.ts
@@ -5,15 +5,17 @@
* 立刻刷一帧注释(`get.ts` 的 pushComment),所以「收到 `:` 开头的一行」就是
* 「路由已注册且 handler 跑起来了」的正向证据。
*
- * 无浏览器:本用例只走 HTTP,先把编排骨架跑稳;客户端渲染(Bundle Slot 挂载、
- * DOM 节点)待 `docs/testing/plugins/02-dsh-tauri-pet.md` 的客户端部分接线。
+ * 上半部分只走 HTTP:断言对象是路由注册与 SSE 字节;下半部分是浏览器层用例,
+ * 覆盖 Bundle Slot 挂载与侧栏 DOM 补丁。
*/
import type { Browser } from 'playwright'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { afterAll, beforeAll, describe, expect, inject, it } from 'vitest'
+import { PET_ICON_RETRY_MAX, PET_ICON_RETRY_MS } from '../../../packages/dsh-tauri-pet/src/client/constants/index.ts'
import {
+ expectNoSyntheticFallbacks,
launchDshBrowser,
newDshPage,
openSettings,
@@ -59,6 +61,16 @@ const KEEPALIVE_MS = 15_000
/** 第 2 帧心跳的可接受上界:一个周期 + 2s 抖动余量,不因读慢了就放宽。 */
const KEEPALIVE_WINDOW_MAX_MS = 17_000
+/**
+ * 侧栏入口兜底轮询的最长存活窗口,取自插件真实常量:
+ * `packages/dsh-tauri-pet/src/client/register/sidebar-icon.ts:110-114` 每 `PET_ICON_RETRY_MS`
+ * 走一轮,`tries > PET_ICON_RETRY_MAX` 即停止,因此最长 31 轮。
+ */
+const RETRY_WINDOW_MS = PET_ICON_RETRY_MS * (PET_ICON_RETRY_MAX + 1)
+
+/** 观察时长:必须长于轮询窗口,否则「预算耗尽之后」的断言无从谈起。 */
+const RETRY_SETTLE_MS = 18_000
+
/** 一次读取的结果:累计文本、自建连起的耗时、已消费的响应块数。 */
interface SseRead {
text: string
@@ -223,7 +235,7 @@ describe('L2 客户端', () => {
it('验证顶层页面不注册任何桌宠槽位', async () => {
const top = await newDshPage(browser, { path: '/', ready: SETTINGS_TRIGGER })
try {
- await openSettings(top.page, top.frame)
+ await openSettings(top.page, top.frame, top.syntheticFallbacks)
const slots = await top.frame.evaluate(() => ({
hasTrigger: document.querySelector('.dshp-settings-trigger') !== null,
@@ -234,6 +246,7 @@ describe('L2 客户端', () => {
expect(slots.hasTrigger, '顶层页面必须真的渲染出设置触发器(否则这条断言是空转)').toBe(true)
expect(slots.petIcons, '顶层页面不得被插入桌宠入口(window.parent === window 早退)').toBe(0)
expect(slots.petSections, '顶层页面不得注册桌宠设置分区').toBe(0)
+ expectNoSyntheticFallbacks(top)
expect(top.errors, '早退路径不得产出应用级错误').toEqual([])
}
finally {
@@ -244,7 +257,7 @@ describe('L2 客户端', () => {
it('验证 iframe 内桌宠设置分区正常渲染且无崩溃', async () => {
const app = await newDshPage(browser)
try {
- await openSettings(app.page, app.frame)
+ await openSettings(app.page, app.frame, app.syntheticFallbacks)
const nav = app.frame.locator(SETTINGS_NAV_ITEM).filter({ hasText: '宠物' })
expect(await nav.count(), '桌宠分区必须在导航里注册且唯一(同 id 不得重复注册)').toBe(1)
@@ -253,7 +266,7 @@ describe('L2 客户端', () => {
'分区导航项必须由设置侧栏渲染',
).toBe(true)
- await selectSettingsSection(app.page, app.frame, '宠物')
+ await selectSettingsSection(app.page, app.frame, '宠物', app.syntheticFallbacks)
const panel = app.frame.locator('.dshp-pet__page')
await expect.poll(
@@ -280,6 +293,7 @@ describe('L2 客户端', () => {
expect(panelState.sizeSlider!.min, '尺寸下限必须与插件常量一致').toBe('50')
expect(panelState.sizeSlider!.max, '尺寸上限必须与插件常量一致').toBe('200')
expect(panelState.alerts, '正常渲染时不得出现错误条').toEqual([])
+ expectNoSyntheticFallbacks(app)
expect(app.errors, '分区注册与渲染不得抛出应用级错误').toEqual([])
}
finally {
@@ -342,11 +356,12 @@ describe('L2 客户端', () => {
it('验证侧栏长时间未就绪时停止轮询且不抛错', async () => {
const app = await newDshPage(browser, { ready: SETTINGS_TRIGGER })
try {
- const budget = await app.frame.evaluate(() => ({ retryMs: 500, retryMax: 30 }))
- expect(budget.retryMs, '夹具必须与插件的兜底轮询周期一致').toBe(500)
- expect(budget.retryMs * (budget.retryMax + 1), '轮询兜底预算必须是一个可等完的有限窗口').toBeLessThanOrEqual(20_000)
+ expect(
+ RETRY_WINDOW_MS,
+ `观察窗口 ${RETRY_SETTLE_MS}ms 必须覆盖插件真实轮询预算 ${RETRY_WINDOW_MS}ms(PET_ICON_RETRY_MS×PET_ICON_RETRY_MAX,常量变大时本用例必须失败)`,
+ ).toBeLessThan(RETRY_SETTLE_MS)
- await new Promise(resolve => setTimeout(resolve, 18_000))
+ await new Promise(resolve => setTimeout(resolve, RETRY_SETTLE_MS))
const state = await app.frame.evaluate(() => {
const button = document.querySelector('[data-dsh-tauri-pet-icon]')
diff --git a/test/e2e/plugins/03-dsh-tauri-rightclick.e2e.ts b/test/e2e/plugins/03-dsh-tauri-rightclick.e2e.ts
index 53d6c9e7..da5558a2 100644
--- a/test/e2e/plugins/03-dsh-tauri-rightclick.e2e.ts
+++ b/test/e2e/plugins/03-dsh-tauri-rightclick.e2e.ts
@@ -1,5 +1,5 @@
/**
- * 批次 03 · `dsh-tauri-rightclick` 的宿主路由(用例来源:`docs/testing/plugins/03-dsh-tauri-rightclick.md`)。
+ * 批次 03 · `dsh-tauri-rightclick` 的宿主路由(契约见 `docs/specs/plugin.test.md`)。
*
* 本插件是唯一带真实系统副作用的 L2 路由:`open/url` 与 `open/path` 的正向分支会真的
* 拉起本机浏览器 / 文件管理器。因此这里只落地**在副作用之前就返回**的拒绝分支;
diff --git a/test/e2e/plugins/04-dsh-tauri-session.e2e.ts b/test/e2e/plugins/04-dsh-tauri-session.e2e.ts
index d39e5c32..6704e6a0 100644
--- a/test/e2e/plugins/04-dsh-tauri-session.e2e.ts
+++ b/test/e2e/plugins/04-dsh-tauri-session.e2e.ts
@@ -1,5 +1,5 @@
/**
- * 批次 04 · `dsh-tauri-session` 宿主路由(用例来源:`docs/testing/plugins/04-dsh-tauri-session.md`)。
+ * 批次 04 · `dsh-tauri-session` 宿主路由(契约见 `docs/specs/plugin.test.md`)。
*
* 本批只走 HTTP,断言对象是外部世界(状态码、响应字节、`allow` 头),不采信插件自报。
* `DELETE` 也按 JSON 读体是本插件与常规 REST 直觉相反的负向考点;`allow` 成员顺序属
diff --git a/test/e2e/plugins/05-dsh-tauri-worktree.e2e.ts b/test/e2e/plugins/05-dsh-tauri-worktree.e2e.ts
index 3f32f25b..75c9b794 100644
--- a/test/e2e/plugins/05-dsh-tauri-worktree.e2e.ts
+++ b/test/e2e/plugins/05-dsh-tauri-worktree.e2e.ts
@@ -1,5 +1,5 @@
/**
- * 批次 05 · `dsh-tauri-worktree` 宿主路由(用例来源:`docs/testing/plugins/05-dsh-tauri-worktree.md`)。
+ * 批次 05 · `dsh-tauri-worktree` 宿主路由(契约见 `docs/specs/plugin.test.md`)。
*
* 断言对象是外部世界(状态码、响应字节、清单回读),不采信插件自报。
* 本文件刻意只覆盖**无需真实 git 仓库**的路径:`linkDependencies` 默认 `true`
diff --git a/test/e2e/plugins/06-dsh-tauri-ui.e2e.ts b/test/e2e/plugins/06-dsh-tauri-ui.e2e.ts
index 6bbe490b..72bb3bb4 100644
--- a/test/e2e/plugins/06-dsh-tauri-ui.e2e.ts
+++ b/test/e2e/plugins/06-dsh-tauri-ui.e2e.ts
@@ -1,18 +1,19 @@
/**
- * 批次 06 · `dsh-tauri-ui` 宿主路由(用例来源:`docs/testing/plugins/06-dsh-tauri-ui.md`)。
+ * 批次 06 · `dsh-tauri-ui` 宿主路由与设置侧栏(契约见 `docs/specs/plugin.test.md`)。
*
- * 本批只覆盖续跑路由的两条拒绝分支:缺参(400)与会话不存在(404)。断言对象是外部
+ * 宿主侧只覆盖续跑路由的两条拒绝分支:缺参(400)与会话不存在(404)。断言对象是外部
* 世界(HTTP 状态码与响应字节),不采信插件自报;`error` 文案必须逐字相等,否则
* 「路由在跑」与「路由换了实现」在测试里不可区分。
*
* 复用 globalSetup 的共享宿主(`also` 默认已挂载本插件),不另起进程。
* 运行中 / 已正常结束(409)与两条注入失败(500:loader 缺失 / `dsh-llm` 导出缺失)都需要
- * 真实会话,scratch 宿主无造会话手段,保持待补(`00-overview.md` G9)。
+ * 真实会话,scratch 宿主无造会话手段,保持待补。
*/
import type { Browser } from 'playwright'
import { afterAll, beforeAll, describe, expect, inject, it } from 'vitest'
import {
+ expectNoSyntheticFallbacks,
launchDshBrowser,
newDshPage,
openSettings,
@@ -88,7 +89,7 @@ describe('L2 客户端', () => {
expect(triggerHost.triggerInsideSidebar, '设置触发器必须是侧栏内的原生按钮').toBe(true)
expect(triggerHost.triggerTag, '触发器必须是 button').toBe('BUTTON')
- await openSettings(app.page, app.frame)
+ await openSettings(app.page, app.frame, app.syntheticFallbacks)
const state = await app.frame.evaluate(() => {
const root = document.querySelector('[data-slot-sidebar="dsh-tauri-ui"]')
@@ -109,6 +110,7 @@ describe('L2 客户端', () => {
expect(state.railWidth, '侧栏宽度必须落在插件声明的 264–420px 夹紧区间内(插件不覆写宿主宽度)')
.toBeGreaterThanOrEqual(264)
expect(state.railWidth!).toBeLessThanOrEqual(420)
+ expectNoSyntheticFallbacks(app)
expect(app.errors, '侧栏注入不得抛出应用级错误').toEqual([])
}
finally {
@@ -123,7 +125,7 @@ describe('L2 客户端', () => {
expect(await trigger.getAttribute('aria-expanded'), '初始必须为 false').toBe('false')
expect(await app.frame.locator(SETTINGS_SIDEBAR).count(), '初始不得渲染设置侧栏').toBe(0)
- await openSettings(app.page, app.frame)
+ await openSettings(app.page, app.frame, app.syntheticFallbacks)
expect(await trigger.getAttribute('aria-expanded'), '首次点击后必须为 true').toBe('true')
await expect.poll(
async () => await app.frame.locator(SETTINGS_SIDEBAR).first().isVisible(),
@@ -138,6 +140,7 @@ describe('L2 客户端', () => {
{ timeout: 10_000, message: 'Escape 后必须回到 false' },
).toBe('false')
expect(await app.frame.locator(SETTINGS_SIDEBAR).count(), '收起后设置侧栏必须卸载').toBe(0)
+ expectNoSyntheticFallbacks(app)
expect(app.errors, '开合不得抛出应用级错误').toEqual([])
}
finally {
diff --git a/test/e2e/plugins/07-dsh-tauri-panel-extension.e2e.ts b/test/e2e/plugins/07-dsh-tauri-panel-extension.e2e.ts
index 482669a1..e953b0a1 100644
--- a/test/e2e/plugins/07-dsh-tauri-panel-extension.e2e.ts
+++ b/test/e2e/plugins/07-dsh-tauri-panel-extension.e2e.ts
@@ -1,5 +1,5 @@
/**
- * 批次 07 · 扩展管理面板的 L2 宿主路由(用例来源:`docs/testing/plugins/07-dsh-tauri-panel-extension.md`)。
+ * 批次 07 · 扩展管理面板的 L2 宿主路由(契约见 `docs/specs/plugin.test.md`)。
*
* 本批只走 HTTP:断言对象是宿主返回的状态码与响应字节,以及 scratch profile 里配置文件的内容,
* 不采信插件自报。写入分支(技能保存 / 导入 / 仓库创建)会改动用户配置,本批一概不碰。
diff --git a/test/e2e/plugins/08-dsh-tauri-panel-scheduler.e2e.ts b/test/e2e/plugins/08-dsh-tauri-panel-scheduler.e2e.ts
index b6ddce5a..8075d9a7 100644
--- a/test/e2e/plugins/08-dsh-tauri-panel-scheduler.e2e.ts
+++ b/test/e2e/plugins/08-dsh-tauri-panel-scheduler.e2e.ts
@@ -1,5 +1,5 @@
/**
- * 批次 08 · `dsh-tauri-panel-scheduler` 宿主路由(用例来源:`docs/testing/plugins/08-dsh-tauri-panel-scheduler.md`)。
+ * 批次 08 · `dsh-tauri-panel-scheduler` 宿主路由(契约见 `docs/specs/plugin.test.md`)。
*
* 本批只覆盖只读清单、缺参与落盘形态,**不触发真实执行**:`run_now` 需要模型与网络,
* 归入后续批次。断言对象一律是外部世界(HTTP 状态码、响应字节、`<DSH_HOME>/crons/tasks`
diff --git a/test/e2e/plugins/09-dsh-tauri-turnrewind.e2e.ts b/test/e2e/plugins/09-dsh-tauri-turnrewind.e2e.ts
index 0bf80980..14d93a88 100644
--- a/test/e2e/plugins/09-dsh-tauri-turnrewind.e2e.ts
+++ b/test/e2e/plugins/09-dsh-tauri-turnrewind.e2e.ts
@@ -1,5 +1,5 @@
/**
- * 批次 09 · `dsh-tauri-turnrewind` 的宿主路由(用例来源:`docs/testing/plugins/09-dsh-tauri-turnrewind.md`)。
+ * 批次 09 · `dsh-tauri-turnrewind` 的宿主路由(契约见 `docs/specs/plugin.test.md`)。
*
* 插件只读:两个 GET 端点把账本里的逐回合变更记录回传给客户端卡片。判定依赖会话与工作区
* 上下文,而 scratch 宿主不造会话,因此本批刻意只覆盖无会话条件下即可判定的分支:入参校验、
diff --git a/test/e2e/plugins/10-dsh-tauri-model-config.e2e.ts b/test/e2e/plugins/10-dsh-tauri-model-config.e2e.ts
index ae8eb580..9847cf25 100644
--- a/test/e2e/plugins/10-dsh-tauri-model-config.e2e.ts
+++ b/test/e2e/plugins/10-dsh-tauri-model-config.e2e.ts
@@ -1,12 +1,14 @@
/**
- * 批次 10 · `dsh-tauri-model-config` 的宿主路由(用例来源:`docs/testing/plugins/10-dsh-tauri-model-config.md`)。
+ * 批次 10 · `dsh-tauri-model-config` 的宿主路由(L1/L2 契约见 `docs/specs/plugin.test.md`)。
*
* 插件顶替官方模型设置页:宿主侧只有 5 条路由,本批覆盖其中 4 条的无会话分支——预设表结构、
* 端点探测无 endpoint、打开配置文件、设置文件缺失时退回目录。`settings.yaml` 的真实解析与
* `POST /presets?force=true` 的上游下载由 `packages/dsh-tauri-model-config/src/host/service/`
* 下的 unit 用例覆盖,不在 L2 重复。
*
- * 断言对象是外部世界(HTTP 状态码、响应字节、scratch `DSH_HOME` 的文件状态),不采信插件自报。
+ * 断言对象是外部世界(HTTP 状态码、响应字节、scratch `DSH_HOME` 的文件状态、真实 DOM 结构),
+ * 不采信插件自报。
+ *
* 宿主复用 globalSetup 的共享实例(已挂载 dsh-tauri-model-config),不另起进程。
*/
@@ -18,6 +20,7 @@ import {
APP_MODAL,
appUrl,
dismissAppModals,
+ expectNoSyntheticFallbacks,
launchDshBrowser,
newDshPage,
openSettings,
@@ -38,6 +41,17 @@ const PRESETS_FIELDS = ['ok', 'source', 'fetchedAt', 'stale', 'count', 'presets'
/** 密钥字段名黑名单:服务端从不回显凭据(G-MC-1)。 */
const SECRET_FIELDS = ['apiKey', 'api_key', 'key', 'token'] as const
+/**
+ * 模型页的结构锚点:CSS Module 运行期类名保留原语义
+ * (`packages/dsh-tauri-model-config/src/client/models/styles.ts:69,79,82,14`)。
+ */
+const MODELS_TITLE_ROW = '[class*="titleRow"]'
+const MODELS_PROVIDER_CARD = '[class*="rowCard"],[class*="setupCard"]'
+const MODELS_ADD_ACTIONS = '[class*="addActions"]'
+
+/** 空态下页脚操作区的按钮文案(`models/locales.ts:151,212`),不含任何宽泛词。 */
+const MODELS_ADD_LABELS = ['添加提供方', '添加自定义提供方'] as const
+
interface PresetsBody {
ok?: boolean
source?: unknown
@@ -173,10 +187,10 @@ describe('L2 客户端', () => {
await browser.close()
})
- it('验证模型设置分区由本插件接管且排在首位', async () => {
+ it('验证模型设置分区由本插件接管且不重复', async () => {
const app = await newDshPage(browser)
try {
- await openSettings(app.page, app.frame)
+ await openSettings(app.page, app.frame, app.syntheticFallbacks)
const nav = await app.frame.evaluate(() =>
Array.from(document.querySelectorAll('nav[aria-label] button')).map(button => button.textContent?.trim() ?? ''))
@@ -184,7 +198,7 @@ describe('L2 客户端', () => {
expect(nav, '设置侧栏必须注册模型分区').toContain('模型')
expect(nav.filter(label => label.includes('模型')).length, 'patch 关闭官方 models 后「模型」分区必须恰好一个').toBe(1)
- await selectSettingsSection(app.page, app.frame, '模型')
+ await selectSettingsSection(app.page, app.frame, '模型', app.syntheticFallbacks)
const panel = await app.frame.evaluate(() => {
const content = document.querySelector('[class*="content-inner"]')
@@ -195,6 +209,7 @@ describe('L2 客户端', () => {
})
expect(panel.text, '模型分区必须真的渲染出内容').not.toBe('')
expect(panel.text, '模型分区必须落到本插件的模型页(含提供商/模型字样)').toMatch(/提供商|模型/)
+ expectNoSyntheticFallbacks(app)
expect(app.errors, '分区注册与渲染不得抛出应用级错误').toEqual([])
}
finally {
@@ -205,7 +220,7 @@ describe('L2 客户端', () => {
it('验证官方提供商引导弹层由本插件的 onboarding 槽位渲染且可收起', async () => {
const app = await newDshPage(browser, { dismissModals: false })
try {
- const modal = await waitForCredentialModal(app.page, app.frame)
+ const modal = await waitForCredentialModal(app.page, app.frame, app.syntheticFallbacks)
const state = await modal.evaluate((element) => {
const text = element.textContent ?? ''
return {
@@ -218,9 +233,10 @@ describe('L2 客户端', () => {
expect(state.hasDeepseek, '引导弹层必须渲染官方 DeepSeek 提供商卡片').toBe(true)
expect(state.inputCount, '引导卡片必须渲染可输入的 API 密钥字段').toBeGreaterThan(0)
expect(state.alerts, '首次进入不得出现错误条').toEqual([])
+ expectNoSyntheticFallbacks(app)
expect(app.errors, '引导弹层渲染不得抛出应用级错误').toEqual([])
- await dismissAppModals(app.page, app.frame)
+ await dismissAppModals(app.page, app.frame, app.syntheticFallbacks)
await expect.poll(
async () => await app.frame.locator(APP_MODAL).count(),
{ timeout: 15_000, message: '点「稍后配置」后引导弹层必须收起' },
@@ -234,29 +250,32 @@ describe('L2 客户端', () => {
it('验证模型页渲染提供商卡片与页脚操作区', async () => {
const app = await newDshPage(browser)
try {
- await openSettings(app.page, app.frame)
- await selectSettingsSection(app.page, app.frame, '模型')
+ await openSettings(app.page, app.frame, app.syntheticFallbacks)
+ await selectSettingsSection(app.page, app.frame, '模型', app.syntheticFallbacks)
- const state = await app.frame.evaluate(() => {
+ const state = await app.frame.evaluate(({ titleRow, providerCard, addActions }) => {
const content = document.querySelector('[class*="content-inner"]')
- const text = content?.textContent ?? ''
+ const footer = content?.querySelector(addActions)
return {
- text,
- cardish: content?.querySelectorAll('[class*="card"],[class*="provider"],[class*="setup"]').length ?? 0,
+ titleRows: content?.querySelectorAll(titleRow).length ?? 0,
+ providerCards: content?.querySelectorAll(providerCard).length ?? 0,
+ footerButtons: Array.from(footer?.querySelectorAll('button') ?? []).map(button => button.textContent?.trim() ?? ''),
buttons: content?.querySelectorAll('button').length ?? 0,
alerts: Array.from(content?.querySelectorAll('[role="alert"]') ?? []).map(alert => alert.textContent?.trim()),
navLabels: Array.from(document.querySelectorAll('nav[aria-label] button')).map(button => button.textContent?.trim()),
}
- })
+ }, { titleRow: MODELS_TITLE_ROW, providerCard: MODELS_PROVIDER_CARD, addActions: MODELS_ADD_ACTIONS })
- expect(state.text, '模型页必须非空').not.toBe('')
+ expect(state.titleRows, '模型页必须渲染标题行(证明走的是正常分支而非加载失败分支)').toBeGreaterThan(0)
expect(
- state.cardish > 0 || /暂无|添加|提供商|API/i.test(state.text),
- '模型页必须给出提供商卡片或明确的空态文案',
+ state.providerCards > 0 || MODELS_ADD_LABELS.some(label => state.footerButtons.includes(label)),
+ `模型页必须为提供商渲染卡片 ${MODELS_PROVIDER_CARD},或渲染带「添加提供方」按钮的明确空态`
+ + `(实际页脚按钮:${JSON.stringify(state.footerButtons)})`,
).toBe(true)
expect(state.buttons, '模型页必须渲染可交互的页脚操作区').toBeGreaterThan(0)
expect(state.alerts, '预设可用时不得出现错误条').toEqual([])
expect(state.navLabels.filter(label => label === '模型').length, '切换到模型页后同 id 分区不得重复').toBe(1)
+ expectNoSyntheticFallbacks(app)
expect(app.errors, '模型页渲染不得抛出应用级错误').toEqual([])
}
finally {
@@ -277,8 +296,8 @@ describe('L2 客户端', () => {
})
})
- await openSettings(app.page, app.frame)
- await selectSettingsSection(app.page, app.frame, '模型')
+ await openSettings(app.page, app.frame, app.syntheticFallbacks)
+ await selectSettingsSection(app.page, app.frame, '模型', app.syntheticFallbacks)
await new Promise(resolve => setTimeout(resolve, 2_000))
const state = await app.frame.evaluate(() => {
@@ -296,6 +315,7 @@ describe('L2 客户端', () => {
expect(state.buttons, '失败时仍必须保留可交互入口').toBeGreaterThan(0)
expect(state.inputs, '失败时仍必须保留可编辑字段').toBeGreaterThan(0)
expect(state.errorLines, '预设失败不得让模型页出现 entry.error 级错误条').toEqual([])
+ expectNoSyntheticFallbacks(app)
expect(
app.errors.filter(line => line.startsWith('PAGEERROR')),
'预设 502 只允许留下浏览器对 502 响应的 console 记录,不得有未捕获异常',
diff --git a/test/e2e/plugins/11-dsh-tauri-connection.e2e.ts b/test/e2e/plugins/11-dsh-tauri-connection.e2e.ts
index bfeecce1..56b8e899 100644
--- a/test/e2e/plugins/11-dsh-tauri-connection.e2e.ts
+++ b/test/e2e/plugins/11-dsh-tauri-connection.e2e.ts
@@ -1,5 +1,5 @@
/**
- * 批次 11 · `dsh-tauri-connection` 的桌面载体鉴权适配(用例来源:`docs/testing/plugins/11-dsh-tauri-connection.md`)。
+ * 批次 11 · `dsh-tauri-connection` 的桌面载体鉴权适配(契约见 `docs/specs/plugin.test.md`)。
*
* 本插件是全仓唯一的网络安全边界型插件:当且仅当子进程带 `DSH_TAURI_EMBEDDED=1` 时,它在
* `connection` 服务上把 401 降级为放行、把索引放行;其余取值下 `attach()` 返回 noop,鉴权完全不变。
@@ -7,17 +7,18 @@
* 三条用例都必须控制该环境变量,因此各自自带 scratch 宿主。这里不用 `support/dsh-host.ts` 的
* `startDshHost`:它在返回宿主前先做根路径 token 交换,而该交换在注入态被鉴权适配放行成 200
* (没有 303 + Set-Cookie),会把「被测行为」当成启动失败抛掉。自带编排只做脚手架与就绪等待,
- * 复用 `scaffoldDshProfile` 与 `REPO_ROOT`,不起第二个共享宿主。
+ * 复用 `scaffoldDshProfile` / `resolveDshCommand` / `resolveNodeBin` 与 `REPO_ROOT`,不起第二个共享宿主。
*/
import type { ChildProcess } from 'node:child_process'
+import type { WriteStream } from 'node:fs'
import { spawn } from 'node:child_process'
-import { createWriteStream, readFileSync, type WriteStream } from 'node:fs'
-import { basename, dirname, join } from 'node:path'
+import { createWriteStream, readFileSync, rmSync } from 'node:fs'
+import { basename, join } from 'node:path'
import process from 'node:process'
import { finished } from 'node:stream/promises'
import { describe, expect, it } from 'vitest'
-import { scaffoldDshProfile } from '../support/dsh-host'
+import { resolveDshCommand, resolveNodeBin, scaffoldDshProfile } from '../support/dsh-host'
const EMBEDDED_ENV = 'DSH_TAURI_EMBEDDED'
@@ -42,23 +43,6 @@ function log(message: string): void {
process.stderr.write(`[gate-host] ${message}\n`)
}
-function resolveDshBin(): string {
- const explicit = process.env.DSH_E2E_DSH_BIN
- if (explicit)
- return explicit
- return join(
- process.env.APPDATA ?? '',
- 'io.github.hairyf.deepseek-harness-desktop',
- 'dependencies',
- 'dsh',
- 'node_modules',
- '@deepseek-ai',
- 'dsh',
- 'lib',
- 'bin.js',
- )
-}
-
async function killTree(child: ChildProcess): Promise<void> {
if (child.pid === undefined || child.exitCode !== null)
return
@@ -115,11 +99,12 @@ async function startGateHost(): Promise<GateHost> {
})
const logPath = join(profile.home, 'dsh-web.log')
const logStream: WriteStream = createWriteStream(logPath, { flags: 'a' })
- const args = [resolveDshBin(), 'web', '--host', '127.0.0.1', '--port', '0', '--no-open']
+ const [dshBin] = resolveDshCommand()
+ const args = [dshBin, 'web', '--host', '127.0.0.1', '--port', '0', '--no-open']
log(`🚀 挂载 [${basename(profile.home)}] carrier=${process.env[EMBEDDED_ENV] ?? '(unset)'}`)
- const child = spawn(process.execPath, args, {
+ const child = spawn(resolveNodeBin(), args, {
cwd: profile.profileDir,
env: { ...process.env, DSH_HOME: profile.home },
stdio: ['ignore', 'pipe', 'pipe'],
@@ -129,6 +114,7 @@ async function startGateHost(): Promise<GateHost> {
child.stdout?.pipe(logStream, { end: false })
child.stderr?.pipe(logStream, { end: false })
+ const home = profile.home
let stopped = false
const stop = async (): Promise<void> => {
if (stopped)
@@ -139,13 +125,14 @@ async function startGateHost(): Promise<GateHost> {
child.stderr?.unpipe(logStream)
logStream.end()
await finished(logStream).catch(() => {})
+ rmSync(home, { recursive: true, force: true })
}
try {
const url = await waitForReady(child, logPath)
const baseUrl = new URL(url).origin
log(`✅ 就绪 [${baseUrl}] carrier=${process.env[EMBEDDED_ENV] ?? '(unset)'}`)
- return { baseUrl, url, home: profile.home, logPath, stop }
+ return { baseUrl, url, home, logPath, stop }
}
catch (error) {
await stop()
diff --git a/test/e2e/support/browser.ts b/test/e2e/support/browser.ts
index ca67290b..6aa8e63c 100644
--- a/test/e2e/support/browser.ts
+++ b/test/e2e/support/browser.ts
@@ -11,11 +11,15 @@
* `newContext` 阶段注入 `inject('dshCookie')`,否则 `/api/**` 与插件路由一律 401。
*
* 采集 `pageerror` / `console.error` 时按 `IGNORED_APP_ERRORS` 过滤:用例跑在纯浏览器里
- * 而没有 Tauri 宿主,所有 Tauri 桥调用必然失败(`NODE_NOT_ANSWERED`),这属于环境的
- * 预期噪声,不是被测插件的缺陷;过滤后仍出现的错误才是真问题。
+ * 而没有 Tauri 宿主,Tauri 桥调用必然失败,这属于环境的预期噪声,不是被测插件的缺陷;
+ * 过滤后仍出现的错误才是真问题。
+ *
+ * 两类「静默失败」在本文件里被显式堵住:① 弹层关不掉(`dismissAppModals` 到期即失败,
+ * 不再与「本来就没弹层」混为一谈);② 合成 `dispatchEvent` 兜底绕过命中测试(每次走兜底
+ * 都记进 `SyntheticFallback`,用例用 `expectNoSyntheticFallbacks` 把它钉在 0)。
*/
-import type { Browser, BrowserContext, Frame, Page } from 'playwright'
+import type { Browser, BrowserContext, ElementHandle, Frame, Page } from 'playwright'
import { chromium } from 'playwright'
import { expect, inject } from 'vitest'
@@ -25,12 +29,17 @@ export const EMBEDDED_DOCUMENT_PATH = '/dsh-e2e-embed.html'
/** 被测页面的 iframe 尺寸;太小会把设置侧栏折成 Rail 形态,影响几何断言。 */
export const APP_FRAME_VIEWPORT = { width: 1400, height: 900 }
-/** 「没有 Tauri 宿主」这一环境事实导致的预期噪声。 */
+/**
+ * 「没有 Tauri 宿主」这一环境事实导致的预期噪声。
+ *
+ * 每条都必须是精确串并写明理由:`'invoke '` / `'__TAURI'` / `'Failed to fetch'` 这类宽串
+ * 会把真实故障一起过滤(例如真正抛出的 invoke 失败、页面断网),假绿就从过滤器进来。
+ */
export const IGNORED_APP_ERRORS: readonly string[] = [
- 'NODE_NOT_ANSWERED',
- 'invoke ',
- '__TAURI',
- 'Failed to fetch',
+ // iframe 内 `invoke()` 把请求 `postMessage` 给父页后无人应答,15s 后按超时拒绝
+ // (`packages/dsh-tauri/src/client/service/invoke.ts:39,49,67` 的三条消息共用此前缀)。
+ // 纯浏览器里不存在 Tauri 宿主,任何插件命令都只能落到这里,与插件行为无关。
+ 'NODE_NOT_ANSWERED: invoke ',
]
/** 插件自身注入的元素用 `data-dsh-*`(`plugin.client.md` §4)。 */
@@ -73,9 +82,35 @@ export interface DshPage {
page: Page
frame: Frame
errors: string[]
+ /** 本轮走合成事件兜底的调用点;用例用 `expectNoSyntheticFallbacks` 断言为空。 */
+ syntheticFallbacks: SyntheticFallback[]
close: () => Promise<void>
}
+/**
+ * 一次「绕过命中测试的合成点击」记录。
+ *
+ * 合成 `dispatchEvent` 直接派发给目标元素,因此它只能证明「插件的 DOM 监听被触发」,
+ * 不能证明「用户点得到」——目标被后到的样式盖住、或 `#root[inert]` 吞掉指针事件时,
+ * 真实点击失败但合成点击照样生效。记录成对象而不是布尔值,是为了在断言失败时直接
+ * 给出「哪个调用点、点了哪个目标」。
+ */
+export interface SyntheticFallback {
+ /** 走兜底的调用点,如 `clickInFrame` / `openSettings` / `selectSettingsSection`。 */
+ site: string
+ /** 兜底目标的可读描述。 */
+ target: string
+}
+
+/** 断言本轮没有任何合成事件兜底:真实指针点击必须自己点得通。 */
+export function expectNoSyntheticFallbacks(app: DshPage): void {
+ const detail = app.syntheticFallbacks.map(item => `${item.site} → ${item.target}`).join('; ')
+ expect(
+ app.syntheticFallbacks,
+ `真实指针点击未生效,走了合成事件兜底(${detail || '无'})`,
+ ).toEqual([])
+}
+
export function appUrl(path = '/'): string {
return `${inject('dshBaseUrl')}${path}`
}
@@ -137,6 +172,7 @@ export async function newDshPage(browser: Browser, options: {
await addSessionCookie(context)
const page = await context.newPage()
const errors = collectAppErrors(page)
+ const syntheticFallbacks: SyntheticFallback[] = []
const embedded = options.path === undefined
if (embedded)
await installEmbedRoute(page)
@@ -151,7 +187,7 @@ export async function newDshPage(browser: Browser, options: {
await frame.waitForLoadState('domcontentloaded')
await frame.locator(options.ready ?? PET_ICON).first().waitFor({ state: 'attached', timeout: 30_000 })
if (options.dismissModals ?? true)
- await dismissAppModals(page, frame)
+ await dismissAppModals(page, frame, syntheticFallbacks)
return {
browser,
@@ -159,6 +195,7 @@ export async function newDshPage(browser: Browser, options: {
page,
frame,
errors,
+ syntheticFallbacks,
close: async () => {
await page.close().catch(() => {})
await context.close()
@@ -184,23 +221,58 @@ export async function openDshApp(options: {
}
/**
- * 关掉当前帧内的一个阻塞弹层;无弹层时返回 `false`。
+ * 等**某一个**元素从 DOM 移除。
+ *
+ * 不能用 `frame.locator(APP_MODAL).first().waitFor({ state: 'detached' })`:locator 是活的,
+ * 关掉「内测声明」后 `.first()` 立刻改指紧随其后弹出的「API Key 引导」,于是「已关掉」被
+ * 误判成「一直没关掉」。这里对点击前抓下的元素句柄轮询 `isConnected`,句柄本身消失
+ * (页面已卸载该节点)同样算已移除。
+ */
+async function waitForDetached(handle: ElementHandle, timeoutMs: number): Promise<void> {
+ const deadline = Date.now() + timeoutMs
+ while (Date.now() < deadline) {
+ const connected = await handle.evaluate(element => element.isConnected).catch(() => false)
+ if (!connected)
+ return
+ await new Promise(resolve => setTimeout(resolve, 100))
+ }
+ throw new Error(`点击关闭项后弹层在 ${timeoutMs}ms 内仍未从 DOM 移除`)
+}
+
+/**
+ * 关掉当前帧内的一个阻塞弹层;无弹层时返回 `false`,弹层存在但关不掉时抛出。
*
* 「内测声明」(`headless`,正文只有「继续」)与「API Key 引导」(取消项在 `_editorActions`)
- * 都走同一个 `Modal`,按取消容器优先、否则退回第一个按钮。
+ * 都走同一个 `Modal`,按取消容器优先、否则退回第一个按钮;前者关掉后会**紧接着**弹出后者,
+ * 因此关闭判据必须绑定被点的那个元素。
+ *
+ * 两条失败路径都必须显式暴露,否则「点不动」会被伪装成「已关闭」:
+ * ① 有弹层但没有任何按钮 → 直接报错,不再当作 `false`(那会让外层以为本来就没弹层);
+ * ② 点完之后弹层不消失 → `waitForDetached` 抛错,不再 `catch` 吞掉。
*/
-async function dismissOneModal(page: Page, frame: Frame): Promise<boolean> {
+async function dismissOneModal(
+ page: Page,
+ frame: Frame,
+ fallbacks?: SyntheticFallback[],
+): Promise<boolean> {
const dialog = frame.locator(APP_MODAL).first()
if (await dialog.count() === 0)
return false
+ const snapshot = await dialog.elementHandle()
+ if (snapshot === null)
+ return false
+
const cancel = dialog.locator(APP_MODAL_CANCEL).first()
const action = await cancel.count() > 0 ? cancel : dialog.locator('button').first()
- if (await action.count() === 0)
- return false
+ if (await action.count() === 0) {
+ throw new Error(
+ `帧内存在阻塞弹层 ${APP_MODAL},但取消容器 ${APP_MODAL_CANCEL} 与兜底 button 都不存在,无法关闭`,
+ )
+ }
- await clickInFrame(page, frame, action)
- await dialog.waitFor({ state: 'detached', timeout: 8_000 }).catch(() => {})
+ await clickInFrame(page, frame, action, fallbacks)
+ await waitForDetached(snapshot, 8_000)
return true
}
@@ -209,17 +281,32 @@ async function dismissOneModal(page: Page, frame: Frame): Promise<boolean> {
*
* 不能只在页面就绪时关一次——弹层挂载晚于服务就绪,且关闭状态按帧内页面加载判定、不落盘,
* iframe 一旦重建就重新弹出;不关掉则所有真实指针点击都会被 `#root[inert]` 吞掉。
+ *
+ * 循环**只有两个出口**:连续两次探到「无弹层」,或抛错。旧实现第三个出口是「到期直接
+ * `return`」,于是一轮都没关掉(弹层持续重挂)与「本来就没弹层」不可区分、静默假绿;
+ * 现在到期即失败,并把帧内当前的弹层数带进诊断。
*/
-export async function dismissAppModals(page: Page, frame: Frame, timeoutMs = 20_000): Promise<void> {
+export async function dismissAppModals(
+ page: Page,
+ frame: Frame,
+ fallbacks?: SyntheticFallback[],
+ timeoutMs = 20_000,
+): Promise<void> {
const deadline = Date.now() + timeoutMs
while (Date.now() < deadline) {
- if (await dismissOneModal(page, frame))
+ if (await dismissOneModal(page, frame, fallbacks))
continue
await new Promise(resolve => setTimeout(resolve, 300))
- if (await dismissOneModal(page, frame))
+ if (await dismissOneModal(page, frame, fallbacks))
continue
return
}
+
+ const remaining = await frame.locator(APP_MODAL).count()
+ throw new Error(
+ `关闭阻塞弹层超时(${timeoutMs}ms);当前帧仍有 ${remaining} 个 ${APP_MODAL}`
+ + '(弹层一直没被点掉:检查它是否持续重挂,或点击被遮罩 / inert 吞掉)',
+ )
}
/**
@@ -231,6 +318,7 @@ export async function dismissAppModals(page: Page, frame: Frame, timeoutMs = 20_
export async function waitForCredentialModal(
page: Page,
frame: Frame,
+ fallbacks?: SyntheticFallback[],
timeoutMs = 45_000,
): Promise<ReturnType<Frame['locator']>> {
const deadline = Date.now() + timeoutMs
@@ -240,25 +328,33 @@ export async function waitForCredentialModal(
return withInput.first()
if (await frame.locator(APP_MODAL).count() > 0)
- await dismissOneModal(page, frame)
+ await dismissOneModal(page, frame, fallbacks)
else
await new Promise(resolve => setTimeout(resolve, 300))
}
throw new Error('等待带凭据输入的 API Key 引导弹层超时')
}
+/** 帧内合成 `click`:仍会触发被测插件真实注册的 DOM 监听,但不经过命中测试。 */
+async function dispatchSyntheticClick(target: ReturnType<Frame['locator']>): Promise<void> {
+ await target.evaluate((element) => {
+ element.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }))
+ })
+}
+
/**
* 用真实指针事件点击(`boundingBox` 给出父页视口坐标)。
*
* dsh 的设置菜单是懒加载资源,刚打开时目标可能被后到的样式遮住,`locator.click`
- * 会一直判为不可命中而超时;需要兜底的调用方(如 `openSettings`)在指针点击无效后
- * 再补一次 frame 内的合成 `click`——它仍会触发被测插件真实注册的 DOM 监听,只是不
- * 经过命中测试。
+ * 会一直判为不可命中而超时;目标连几何都没有时退回 frame 内的合成 `click`。
+ * 兜底一旦发生就写进 `fallbacks`:合成点击证明不了「用户点得到」,必须由用例
+ * (`expectNoSyntheticFallbacks`)显式确认它没被用上,而不是静默通过。
*/
export async function clickInFrame(
page: Page,
frame: Frame,
target: ReturnType<Frame['locator']>,
+ fallbacks?: SyntheticFallback[],
): Promise<void> {
let box = await target.boundingBox()
if (box === null) {
@@ -266,25 +362,23 @@ export async function clickInFrame(
box = await target.boundingBox()
}
if (box === null) {
- await target.evaluate((element) => {
- element.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }))
- })
+ fallbacks?.push({ site: 'clickInFrame', target: target.toString() })
+ await dispatchSyntheticClick(target)
return
}
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2)
}
/** 打开设置侧栏,返回触发器的 locator。 */
-export async function openSettings(page: Page, frame: Frame) {
- await dismissAppModals(page, frame)
+export async function openSettings(page: Page, frame: Frame, fallbacks?: SyntheticFallback[]) {
+ await dismissAppModals(page, frame, fallbacks)
const trigger = frame.locator(SETTINGS_TRIGGER).first()
await trigger.waitFor({ state: 'attached', timeout: 20_000 })
if (await trigger.getAttribute('aria-expanded') !== 'true')
- await clickInFrame(page, frame, trigger)
+ await clickInFrame(page, frame, trigger, fallbacks)
if (await trigger.getAttribute('aria-expanded') !== 'true') {
- await trigger.evaluate((element) => {
- element.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }))
- })
+ fallbacks?.push({ site: 'openSettings', target: `${SETTINGS_TRIGGER} aria-expanded 未被指针点击改写` })
+ await dispatchSyntheticClick(trigger)
}
await expect.poll(
async () => await trigger.getAttribute('aria-expanded'),
@@ -299,13 +393,17 @@ export async function openSettings(page: Page, frame: Frame) {
*
* 分区导航只渲染 `label`,不渲染注册时的 `id`(`id` 只存在于 `store.sections` 快照里),
* 因此定位只能按文案;内容侧则按插件 `dshp-*` 类断言。
+ *
+ * 与 `openSettings` 同一策略:几何缺失即报错(导航项不可见就是不可点),
+ * `aria-current` 没被指针点击改写才退回合成点击,并把这次兜底记进 `fallbacks`。
*/
export async function selectSettingsSection(
page: Page,
frame: Frame,
title: string,
+ fallbacks?: SyntheticFallback[],
): Promise<ReturnType<Frame['locator']>> {
- await dismissAppModals(page, frame)
+ await dismissAppModals(page, frame, fallbacks)
const item = frame.locator(SETTINGS_NAV_ITEM, { hasText: title }).first()
await item.waitFor({ state: 'attached', timeout: 15_000 })
@@ -313,9 +411,8 @@ export async function selectSettingsSection(
expect(box, `分区「${title}」的导航项必须有可见几何`).not.toBeNull()
await page.mouse.click(box!.x + Math.min(box!.width / 2, 40), box!.y + box!.height / 2)
if (await item.getAttribute('aria-current') !== 'true') {
- await item.evaluate((element) => {
- element.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }))
- })
+ fallbacks?.push({ site: 'selectSettingsSection', target: `分区「${title}」aria-current 未被指针点击改写` })
+ await dispatchSyntheticClick(item)
}
await expect.poll(
diff --git a/test/e2e/support/dsh-host.ts b/test/e2e/support/dsh-host.ts
index c182481f..b45db8bf 100644
--- a/test/e2e/support/dsh-host.ts
+++ b/test/e2e/support/dsh-host.ts
@@ -116,7 +116,8 @@ function log(message: string): void {
process.stderr.write(`[dsh-host] ${message}\n`)
}
-function resolveNodeBin(): string {
+/** node 入口:显式环境变量优先,便于在 CI 里固定解释器。 */
+export function resolveNodeBin(): string {
return process.env.DSH_E2E_NODE_BIN ?? process.execPath
}
@@ -158,8 +159,11 @@ function tailOf(path: string, lines = 30): string {
* 业务逻辑与依赖解析
* ========================================== */
-/** 解析 dsh 入口:显式环境变量 → PATH 上的 `dsh` → 桌面端已装配的 bin.js。 */
-function resolveDshCommand(): string[] {
+/**
+ * 解析 dsh 入口:显式环境变量 → 依赖树里的 `@deepseek-ai/dsh/lib/bin.js` → 桌面端装配目录
+ * (新标识符优先,兼容旧标识符)。三处都落空时直接抛错,不回退到「可能不存在」的路径。
+ */
+export function resolveDshCommand(): string[] {
const explicit = process.env.DSH_E2E_DSH_BIN
if (explicit)
return [explicit]
diff --git a/test/e2e/support/selectors.ts b/test/e2e/support/selectors.ts
index 93ecb883..5e7f879f 100644
--- a/test/e2e/support/selectors.ts
+++ b/test/e2e/support/selectors.ts
@@ -1,7 +1,7 @@
/**
* L3 桌面端用例共享的 `data-testid` 选择器常量。
*
- * 规范见 `docs/testing/desktop/00-overview.md`:用例只认 `dsh-<业务域>-<元素名>`,
+ * 规范见 `docs/specs/desktop.test.md` §5 的「选择器口径」:用例只认 `dsh-<业务域>-<元素名>`,
* 禁止依赖 CSS 类名、DOM 层级或文本内容;跨用例复用的选择器一律登记在此。
*
* 桌面端只剩一条启动冒烟用例,因此这里只保留它真正用到的锚点;被删用例的选择器
diff --git a/test/e2e/support/wdio-probe.mjs b/test/e2e/support/wdio-probe.mjs
index 278bc0e7..9b8698df 100644
--- a/test/e2e/support/wdio-probe.mjs
+++ b/test/e2e/support/wdio-probe.mjs
@@ -3,7 +3,7 @@
// D0 临时探针:验证 debug 二进制内嵌的 WebDriver server 能否被纯 HTTP 驱动。
// 只验这一个不确定性,通过后由正式接线(test/e2e/support/desktop-host.ts)取代;
// 现状:桌面端冒烟已走 desktop-host.ts,本探针保留为不依赖 WDIO 的最小诊断通道,
-// 供插件用例集引用(见 docs/testing/plugins/02-dsh-tauri-pet.md)。
+// 保留为不依赖 WDIO 的最小诊断通道之一(测试协议见 docs/specs/plugin.test.md)。
import { spawn } from 'node:child_process'
import { closeSync, existsSync, openSync, readFileSync } from 'node:fs'