DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
test(e2e): 删除桌宠入口相关用例
hairyf9733398877d4
diff --git a/docs/specs/desktop.test.md b/docs/specs/desktop.test.mdindex 7a76858f..d7c6d174 100644--- a/docs/specs/desktop.test.md+++ b/docs/specs/desktop.test.md@@ -24,12 +24,11 @@ L3 车道仅验证:**壳层是否将 dsh 正确装配、启动并嵌入**。* 嵌入在 dsh iframe 内的 DOM(业务面板、侧栏、Tab、对话框等),统一使用 Playwright 库 API 断言;* 配置、语言、档案、插件生命周期、更新等非壳层职责的业务行为。-### 当前车道用例(2 文件 / 5 条)+### 当前车道用例(1 文件 / 1 条)| 文件 | 说明 || --- | --- || `test/e2e/desktop/boot.e2e.ts` | **启动冒烟**:显式冷装配 → 触发真实下载落盘 → 内核启动 → 页面无报错 |-| `test/e2e/desktop/pet.e2e.ts` | **桌宠窗口(4条)**:OS 窗口创建与销毁 / 未启用不存在 / 侧栏入口联动 / 尺寸越界拦截 |---diff --git a/docs/specs/plugin.test.md b/docs/specs/plugin.test.mdindex 6685bd5b..b41f9f04 100644--- a/docs/specs/plugin.test.md+++ b/docs/specs/plugin.test.md@@ -59,7 +59,7 @@ vitest.plugin.config.ts # plugin project 配置* `unit` project: 匹配 `packages/**/*.{test,spec}.*`、`test/**`、`src/**/*.test.ts`(自动排除 `.e2e.ts`)* `test/archive/**`: 任何 project 均不匹配。-* **文件拆分**:允许同一插件拆分不同层级(如桌宠插件:L2/C 位于 `plugins/dsh-tauri-pet.e2e.ts`,L3 窗口测试位于 `desktop/pet.e2e.ts`,以避免 Linux CI 环境跳过 Windows-only 的 Tauri 测试)。+* **文件拆分**:允许同一插件拆分不同层级(如桌宠插件:L2/C 位于 `plugins/dsh-tauri-pet.e2e.ts`;桌面端仅保留启动冒烟 `desktop/boot.e2e.ts`,桌宠的 L3 窗口用例已随「设置菜单入口迁到官方账号菜单」一并删除)。---diff --git a/test/e2e/desktop/pet.e2e.ts b/test/e2e/desktop/pet.e2e.tsdeleted file mode 100644index c2f820e0..00000000--- a/test/e2e/desktop/pet.e2e.ts+++ /dev/null@@ -1,364 +0,0 @@-import type { DesktopApp } from '../support/desktop'-import process from 'node:process'-import { afterAll, beforeAll, describe, expect, it } from 'vitest'-import { startDesktopApp } from '../support/desktop'-import { dismissDshModals } from '../support/onboarding'-import { completePreinstall } from '../support/preinstall'-import { SHELL_IFRAME } from '../support/selectors'--// ==========================================-// 1. 常量配置-// ==========================================--/** 冷装配(真的联网下载 Node + dsh)的等待上限。 */-const ASSEMBLY_TIMEOUT_MS = 900_000--/** 桌宠窗口创建/销毁的收敛窗口(Rust 侧建窗是异步的)。 */-const PET_WINDOW_TIMEOUT_MS = 30_000--/** 主窗口 label,同时也是 WebDriver 的 window handle。 */-const MAIN_WEBVIEW = 'main'--/** 桌宠独立窗口 label(`src-tauri/src/desktop/pet.rs:29`)。 */-const PET_WEBVIEW = 'pet'--/** 插件就绪锚点:插件样式元素(`mountStyle` 交给 css-render 落成 `style[cssr-id=…]`)。 */-const PET_STYLES = 'style[cssr-id="dsh-tauri-pet-styles"]'--/**- * 菜单入口:桌面载体下由官方账号菜单占据 `settings.launcher` 座位- * (`@deepseek-ai/dsh-client-ui-settings-account` 的 `AccountMenu`),- * 0.1.7 起侧栏不再有插件自有的 `.dshp-settings-trigger`。- *- * 锚点取 `aria-haspopup="menu"`:账号触发器是官方 primitives 的 portal `Menu` 锚,- * 该属性同时是插件识别菜单的稳定结构(不依赖文案,文案随语言变)。- */-const ACCOUNT_MENU_TRIGGER = 'button[aria-haspopup="menu"]'--/** 账号菜单里的桌宠条目(`packages/dsh-tauri-pet/src/client/constants/index.ts`)。 */-const PET_MENU_ITEM = '[data-dsh-tauri-pet-menu-item="1"]'--/** 桌宠尺寸合法区间(`src-tauri/src/desktop/pet.rs:48-49` 的 50.0 / 200.0)。 */-const PET_SIZE_MIN = 50-const PET_SIZE_MAX = 200-const PET_SIZE_DEFAULT = 100--// ==========================================-// 2. 类型定义-// ==========================================--interface PetStatus {- enabled?: boolean- visible?: boolean- active_pet?: string- pet_size?: number | null-}--interface WindowWithDshErrors extends Window {- __dshE2eErrors?: string[]- __TAURI_INTERNALS__?: {- invoke: (name: string, payload?: Record<string, unknown>) => Promise<unknown>- }-}--// ==========================================-// 3. 浏览器端 DOM/Tauri 脚本函数(在 `browser.execute` 中执行)-// ==========================================--/** 元素是否存在 */-function elementExists(selector: string): boolean {- return document.querySelector(selector) !== null-}--/** 匹配元素的数量(`browser.$$` 的 `length` 在 WDIO 9 里是 Promise,脚本函数更直接) */-function elementCount(selector: string): number {- return document.querySelectorAll(selector).length-}--/** 在页面(壳层或帧内)安装报错收集器:三类页面级错误收进 `window.__dshE2eErrors` */-function collectPageErrors(): void {- const host = window as unknown as WindowWithDshErrors- 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 originalConsoleError = console.error.bind(console)- console.error = (...args: unknown[]) => {- errors.push(`console.error: ${args.map(String).join(' ')}`)- originalConsoleError(...args)- }-}--/** 读回当前上下文的报错收集器 */-function readPageErrors(): string[] {- return (window as unknown as WindowWithDshErrors).__dshE2eErrors ?? []-}--/** 壳层内调用 Tauri 命令 */-function shellInvoke(cmd: string, args?: unknown): Promise<unknown> {- const internals = (window as unknown as WindowWithDshErrors).__TAURI_INTERNALS__- if (!internals) {- throw new Error('壳层缺少 __TAURI_INTERNALS__:当前上下文不是 Tauri WebView')- }- return internals.invoke(cmd, args as Record<string, unknown> | undefined)-}--// ==========================================-// 4. 测试套件-// ==========================================--describe.skipIf(process.platform !== 'win32')('桌面端桌宠独立窗口', () => {- let app: DesktopApp-- 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 })-- // 切入 iframe 安装收集器并等待 UI 渲染。- //- // 就绪锚点必须覆盖「插件真的挂上了菜单入口」这一步:只等桌宠样式就进用例,会让第一条- // 用例去和菜单锚的挂载赛跑(CI 上曾整轮输掉这场赛跑)。桌宠条目由插件在菜单展开时才- // 克隆出来,这里只能等到入口存在。- await withIframe(async () => {- await browser.execute(collectPageErrors)- await browser.waitUntil(- () => browser.execute(elementExists, PET_STYLES),- { timeout: 60_000, timeoutMsg: '内嵌 dsh 界面未渲染出桌宠插件产物(插件 client 未生效)' },- )- try {- await browser.waitUntil(- () => browser.execute(elementExists, ACCOUNT_MENU_TRIGGER),- { timeout: 60_000, timeoutMsg: '菜单入口未渲染(账号菜单锚缺席)' },- )- }- catch (error) {- // 入口缺席时把现场钉进失败信息:只看超时文案分不清「插件没挂上」「菜单锚存在但- // 触发器没渲染」还是「帧内报错把渲染打断了」,CI 上无从复盘。- throw new Error(`${(error as Error).message}\n${await describeSettingsScene()}`)- }- })-- await dismissDshModals(browser)- await setEnabled(false)- }, ASSEMBLY_TIMEOUT_MS)-- afterAll(async () => {- await app?.stop()- })-- // ------------------------------------------- // Helper 函数库(特定于套件)- // -------------------------------------------- /** 封装 iframe 切换的高阶函数,自动保证调用后切回主框架 */- async function withIframe<T>(action: () => Promise<T>): Promise<T> {- const browser = app.browser- const iframe = await browser.$(SHELL_IFRAME)- await browser.switchFrame(iframe)- try {- return await action()- }- finally {- await browser.switchFrame(null)- }- }-- /** 壳层报错快照(当前上下文必须已在壳层) */- async function shellErrors(): Promise<string[]> {- return (await app.browser.execute(readPageErrors)) as string[]- }-- /** 帧内报错快照:自动进出 iframe */- async function frameErrors(): Promise<string[]> {- return withIframe(() => app.browser.execute(readPageErrors) as Promise<string[]>)- }-- /** 收尾断言:壳层与内嵌 dsh 页面都不得留下未捕获错误 */- async function expectNoPageErrors(scene: string): Promise<void> {- expect(await frameErrors(), `${scene}:内嵌 dsh 页面出现报错`).toEqual([])- expect(await shellErrors(), `${scene}:壳层出现报错`).toEqual([])- }-- /** 壳层读状态 */- async function status(): Promise<PetStatus> {- return (await app.browser.execute(shellInvoke, 'get_pet_status')) as PetStatus- }-- /** 壳层写启用状态 */- async function setEnabled(enabled: boolean): Promise<void> {- await app.browser.execute(shellInvoke, 'set_pet_enabled', { enabled })- await app.browser.waitUntil(- async () => (await status()).enabled === enabled,- { timeout: PET_WINDOW_TIMEOUT_MS, timeoutMsg: `把 enabled 写成 ${enabled} 后状态未收敛` },- )- }-- /** 等窗口句柄集合收敛到期望值 */- async function waitHandles(expected: string[], message: string): Promise<void> {- await app.browser.waitUntil(- async () => {- const handles = await app.browser.getWindowHandles()- return handles.length === expected.length && expected.every(handle => handles.includes(handle))- },- { timeout: PET_WINDOW_TIMEOUT_MS, timeoutMsg: message },- )- }-- /** 越界提交必须由命令层拒绝(暂禁 WDIO 500 重试机制) */- async function expectSizeRejected(outOfRange: number): Promise<void> {- const browser = app.browser- const retryCount = browser.options.connectionRetryCount- browser.options.connectionRetryCount = 0-- try {- await expect(- browser.execute(shellInvoke, 'set_pet_size', { size: outOfRange }),- ).rejects.toThrow(/PET_SIZE_OUT_OF_RANGE/)- }- finally {- browser.options.connectionRetryCount = retryCount- }- }-- /**- * 帧内打开账号菜单,并等菜单里出现唯一的桌宠条目。- *- * 0.1.7 起桌面载体没有插件自有的侧栏设置入口:官方账号菜单占据 `settings.launcher`- * 座位(点开即「设置 / 意见反馈 / 退出登录」,桌宠条目由插件插在「设置」之后)。- * 桌宠条目只在菜单展开时才克隆出来,所以必须先把菜单打开再断言。- */- async function openPetMenu(): Promise<void> {- const browser = app.browser- await dismissDshModals(browser)-- await withIframe(async () => {- const trigger = await browser.$(ACCOUNT_MENU_TRIGGER)- if (await trigger.getAttribute('aria-expanded') !== 'true')- await trigger.click()-- await browser.waitUntil(- async () => await browser.execute(elementCount, PET_MENU_ITEM) === 1,- { timeout: 30_000, timeoutMsg: '账号菜单展开后必须出现唯一的桌宠条目' },- )- })- }-- /** 帧内现场快照:入口/菜单锚/根节点计数与页内错误,用于锚点缺席时的定位。 */- async function describeSettingsScene(): Promise<string> {- return await app.browser.execute(() => {- const host = window as unknown as WindowWithDshErrors- const count = (selector: string): number => document.querySelectorAll(selector).length- return JSON.stringify({- readyState: document.readyState,- menuTrigger: count('button[aria-haspopup="menu"]'),- legacyTrigger: count('.dshp-settings-trigger'),- menu: count('[role="menu"]'),- sidebarSlot: count('[data-slot="sidebar"]'),- root: count('#root'),- petStyles: count('style[cssr-id="dsh-tauri-pet-styles"]'),- petMenuItem: count('[data-dsh-tauri-pet-menu-item="1"]'),- errors: (host.__dshE2eErrors ?? []).slice(0, 5),- })- }) as string- }-- /** 帧内点击账号菜单里的桌宠条目(用户路径的唯一开关入口),随后菜单自行收起。 */- async function togglePet(): Promise<void> {- const browser = app.browser- await openPetMenu()-- await withIframe(async () => {- await (await browser.$(PET_MENU_ITEM)).click()- })-- await dismissDshModals(browser)- }-- /** 从账号菜单切换桌宠,先断后端状态真的翻转,再等窗口句柄收敛(全部断言 Tauri 原生产物)。 */- async function togglePetExpecting(expected: string[], message: string): Promise<void> {- const before = (await status()).enabled- expect(before, '切换前必须能读到后端 enabled 状态(否则后端已失联)').toBeTypeOf('boolean')-- await togglePet()-- expect((await status()).enabled, `点击桌宠条目后后端 enabled 必须从 ${before} 翻转`).toBe(!before)- await waitHandles(expected, message)- }-- // ------------------------------------------- // 5. 测试用例集- // -------------------------------------------- it('TC-PET-L3-02-001 启用后出现独立的桌宠窗口', async () => {- await waitHandles([MAIN_WEBVIEW], '复位后窗口句柄必须恰为主窗口')-- await togglePetExpecting([MAIN_WEBVIEW, PET_WEBVIEW], '点击设置菜单里的桌宠条目后必须出现独立的 pet 窗口句柄')-- const state = await status()- expect(state.enabled, '创建窗口后状态必须为 enabled:true').toBe(true)- expect(state.visible, 'enabled 为真时 visible 必须同为真').toBe(true)-- await togglePetExpecting([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 () => {- await setEnabled(false)-- const state = await status()- expect(state.enabled, '关闭态下必需为 false').toBe(false)- expect(state.visible, '未启用时不得报告可见').toBe(false)- expect(await app.browser.getWindowHandles(), '未启用时窗口句柄必须恰为 [main]').toEqual([MAIN_WEBVIEW])- })-- it('TC-PET-L3-02-003 设置菜单桌宠条目切换后窗口随之创建与销毁', async () => {- await setEnabled(false)- await waitHandles([MAIN_WEBVIEW], '复位后窗口句柄必须恰为主窗口')- expect((await status()).enabled, '复位后后端必须停在关闭态').toBe(false)-- await togglePetExpecting([MAIN_WEBVIEW, PET_WEBVIEW], '首次点击后必须出现 pet 窗口')- expect((await status()).enabled, '首次点击后状态必须为 enabled:true').toBe(true)-- await togglePetExpecting([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 () => {- await setEnabled(true)-- for (const inRange of [PET_SIZE_MIN, PET_SIZE_MAX]) {- await app.browser.execute(shellInvoke, 'set_pet_size', { size: inRange })- expect((await status()).pet_size, `范围内提交 ${inRange} 必须被接受并落盘`).toBe(inRange)- }-- const settled = (await status()).pet_size- for (const outOfRange of [0, PET_SIZE_MIN - 1, PET_SIZE_MAX + 1, 999]) {- await expectSizeRejected(outOfRange)- expect(- (await status()).pet_size,- `越界提交 ${outOfRange} 不得改动已落盘的尺寸`,- ).toBe(settled)- }-- 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/dsh-tauri-pet.e2e.ts b/test/e2e/plugins/dsh-tauri-pet.e2e.tsindex f7d9d5b6..bef843f6 100644--- a/test/e2e/plugins/dsh-tauri-pet.e2e.ts+++ b/test/e2e/plugins/dsh-tauri-pet.e2e.ts@@ -6,10 +6,10 @@* 「路由已注册且 handler 跑起来了」的正向证据。** 上半部分只走 HTTP:断言对象是路由注册与 SSE 字节;下半部分是浏览器层用例,- * 覆盖 Bundle Slot 挂载与设置菜单 DOM 补丁。+ * 覆盖 Bundle Slot 挂载。*/-import type { Browser, Locator } from 'playwright'+import type { Browser } from 'playwright'import { readFileSync } from 'node:fs'import { join } from 'node:path'import { afterAll, beforeAll, describe, expect, inject, it } from 'vitest'@@ -18,23 +18,12 @@ import {launchDshBrowser,newDshPage,openSettings,- openSettingsMenu,- PET_MENU_ITEM,- PET_MENU_PATCHED,PET_STYLES,selectSettingsSection,SETTINGS_NAV_ITEM,SETTINGS_TRIGGER,} from '../support/browser'-/** 桌宠条目里承载文案的节点(与插件 `MENU_ITEM_LABEL_SELECTOR` 对齐)。 */-const MENU_ITEM_LABEL = '[class*="itemLabel"]'--/** 读桌宠条目的文案:用 `textContent`(插件自己写的就是它,不触发布局)。 */-function readMenuLabel(item: Locator): Promise<string> {- return item.locator(MENU_ITEM_LABEL).first().evaluate(element => element.textContent?.trim() ?? '')-}-/** 与 `packages/dsh-tauri-pet/src/shared/constants.ts` 的 SESSION_STREAM_PATH 对齐。 */const SESSION_STREAM_PATH = '/api/desktop/dsh-tauri-pet/session/stream'@@ -299,104 +288,4 @@ describe('L2 客户端', () => {await app.close()}})-- it('验证设置菜单里克隆出唯一的桌宠条目且状态可读', async () => {- const app = await newDshPage(browser, { ready: PET_STYLES })- try {- await openSettingsMenu(app.page, app.frame, app.syntheticFallbacks)-- await expect.poll(- async () => await app.frame.locator(PET_MENU_ITEM).count(),- { timeout: 20_000, message: '设置菜单展开后必须出现桌宠条目(菜单补丁未生效)' },- ).toBe(1)-- const item = app.frame.locator(PET_MENU_ITEM).first()- expect(await item.evaluate(element => element.tagName), '克隆体必须沿用菜单项的原生元素').toBe('BUTTON')- expect(await item.getAttribute('role'), '克隆体必须仍是规范菜单项').toBe('menuitem')- expect(- await item.evaluate(element => element.closest('[role="menu"]')?.getAttribute('data-dsh-tauri-pet-menu-patched') ?? null),- '桌宠条目所在的菜单必须带补丁标记(幂等守卫)',- ).toBe('1')- expect(- await app.frame.locator(PET_MENU_PATCHED).count(),- '本层只有壳层设置菜单一个「设置」菜单,被打补丁的菜单必须恰为一个',- ).toBe(1)-- // 文案随状态变化,属不稳定文案:按 testing.md 用正则限定两种合法取值并校验状态语义。- // 本层(浏览器态 iframe,无 Tauri 宿主)`invoke` 必然失败,插件 `enabled()` 读到的- // `status` 恒为 null,因此合法取值只有「未开启」一侧;出现另一侧说明状态来源被伪造。- const label = await readMenuLabel(item)- expect(label, '桌宠条目文案必须是「未开启」一侧(状态不可读时 enabled() === false)').toMatch(/^(启用宠物|Enable pet)$/)- expect(- await item.locator('[class*="itemIcon"] svg').count(),- '克隆体必须换成插件自己的爪子图标,而不是继承「设置」的齿轮',- ).toBe(1)-- await item.click()-- // 克隆体不在 React fiber 里,官方 onSelect 不会触发;插件自己补发 pointerdown 收起菜单,- // 这是「点击真的进了插件处理器」的正向证据。- await expect.poll(- async () => await app.frame.locator(SETTINGS_TRIGGER).first().getAttribute('aria-expanded'),- { timeout: 15_000, message: '点击桌宠条目后设置菜单必须收起(点击未进插件处理器)' },- ).toBe('false')-- await openSettingsMenu(app.page, app.frame, app.syntheticFallbacks)- await expect.poll(- async () => await app.frame.locator(PET_MENU_ITEM).count(),- { timeout: 15_000, message: '重开菜单后桌宠条目必须重新出现且仍为 1 个' },- ).toBe(1)- expect(- await readMenuLabel(app.frame.locator(PET_MENU_ITEM).first()),- '宿主未应答时不得乐观翻转本地状态:重开后文案仍必须是「未开启」一侧',- ).toMatch(/^(启用宠物|Enable pet)$/)-- expectNoSyntheticFallbacks(app)- expect(app.errors, '菜单补丁不得抛出应用级错误').toEqual([])- }- finally {- await app.close()- }- })-- it('验证设置菜单重开与重复扫描后桌宠条目恒为一个', async () => {- const app = await newDshPage(browser, { ready: PET_STYLES })- const itemCount = async () => await app.frame.locator(PET_MENU_ITEM).count()- try {- await openSettingsMenu(app.page, app.frame, app.syntheticFallbacks)- await expect.poll(itemCount, { timeout: 20_000, message: '设置菜单展开后必须出现桌宠条目' }).toBe(1)-- // 每一轮都真实收起再重开:菜单节点被重建、MutationObserver 也再跑一次扫描,- // 两处都不得叠加计数(幂等守卫靠菜单上的补丁标记)。- for (let round = 1; round <= 3; round += 1) {- await app.frame.locator(PET_MENU_ITEM).first().click()- await expect.poll(- async () => await app.frame.locator(SETTINGS_TRIGGER).first().getAttribute('aria-expanded'),- { timeout: 15_000, message: `第 ${round} 轮点击后菜单必须收起,否则重开路径未被验证` },- ).toBe('false')-- await openSettingsMenu(app.page, app.frame, app.syntheticFallbacks)- await expect.poll(itemCount, { timeout: 15_000, message: `第 ${round} 次重开菜单后桌宠条目必须仍为 1 个` }).toBe(1)-- // 真实制造 childList 变更(观察器配置为 childList + subtree),逼出一次重新扫描。- await app.frame.evaluate(() => {- const probe = document.createElement('div')- document.body.appendChild(probe)- probe.remove()- })-- await expect.poll(itemCount, { timeout: 15_000, message: `第 ${round} 次重新扫描后桌宠条目不得被重复插入` }).toBe(1)- expect(- await app.frame.locator(PET_MENU_PATCHED).count(),- `第 ${round} 次重新扫描后被打补丁的菜单仍必须恰为一个`,- ).toBe(1)- }-- expectNoSyntheticFallbacks(app)- expect(app.errors, '重复扫描不得抛出应用级错误').toEqual([])- }- finally {- await app.close()- }- })})