Skip to content

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

test: unarchive the shell suite and split CI by test lane

hairyfa57587abced7
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 7435a696..c076b7c5 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -40,9 +40,9 @@ jobs:
skip_after_successful_duplicate: true
paths_ignore: '["**/docs/**", "**/*.md"]'
- # 插件(vitest + typecheck + lint):
- plugins:
- name: Plugins (vitest + typecheck + lint)
+ # 单元测试(vitest)+ 类型检查 + lint:
+ unit:
+ name: Unit Tests (vitest)
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest
@@ -68,12 +68,78 @@ jobs:
- name: Lint
run: pnpm run lint
+ - name: Unit test
+ run: pnpm run test:unit -- --run
+
+ # 插件 L2 E2E(vitest + Playwright 库 API):
+ # 打构建产物,起真实 `dsh web` 进程,断言宿主路由与客户端挂载点。
+ plugins-e2e:
+ name: Plugins E2E Tests (vitest + playwright)
+ needs: pre_job
+ if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v7
+
+ - name: Setup Node.js and pnpm
+ uses: ./.github/actions/setup-node-pnpm
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ # L2 只针对构建产物运行(官方「真实入口路径」要求),未构建会直接失败。
- name: Build Plugins
run: pnpm build:plugins
- # 主逻辑在 Rust 侧,这里仅确认前端纯函数测试通过
- - name: Unit test
- run: pnpm run test -- --run
+ - name: Plugin L2 test
+ run: pnpm run test:e2e:plugin -- --run
+
+ # 桌面端 L3 E2E(vitest + WebdriverIO):
+ # 驱动真实 Tauri 窗口,只能在 Windows 上跑(embedded WebDriver + WebView2)。
+ # 需要 dist/ 与内嵌前端的 debug 二进制;`tauri build` 会带上 custom-protocol,
+ # 否则应用走 devUrl 而不嵌 dist(页面为空,选择器全找不到)。
+ desktop-e2e:
+ name: Desktop E2E Tests (vitest + webdriverio)
+ needs: pre_job
+ if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
+ runs-on: windows-latest
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v7
+
+ - name: Setup Node.js and pnpm
+ uses: ./.github/actions/setup-node-pnpm
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ - name: Build core packages
+ run: pnpm --filter dsh-tauri build && pnpm --filter dsh-tauri-ui build
+
+ - name: Build Plugins
+ run: pnpm build:plugins
+
+ - name: Install Rust stable
+ uses: dtolnay/rust-toolchain@stable
+ with:
+ toolchain: stable
+
+ - name: Cache Rust build
+ uses: Swatinem/rust-cache@v2
+ with:
+ workspaces: src-tauri -> target
+
+ # dist 已由上一步的 build:plugins 前置链路产出;这里显式再跑一次前端构建,
+ # 并清空 beforeBuildCommand 避免重复触发 pnpm build(其 prebuild 会重跑插件构建)。
+ - name: Build frontend
+ run: pnpm exec vite build
+
+ - name: Build debug binary
+ run: pnpm tauri build --debug --no-bundle --config '{"build":{"beforeBuildCommand":""}}'
+
+ - name: Desktop L3 test
+ run: pnpm run test:e2e:desktop -- --run
# Rust 单元测试(应用主体逻辑):
# 这是 CI 此前完全缺失的部分。仓库里存在大量 #[cfg(windows)] 的 Windows 专属
diff --git a/docs/specs/desktop.test.md b/docs/specs/desktop.test.md
index a1ebfe1c..cd778c07 100644
--- a/docs/specs/desktop.test.md
+++ b/docs/specs/desktop.test.md
@@ -59,7 +59,7 @@ tauri::Builder::default()
* `test/e2e/support/*`:E2E 共享工具(宿主编排 `dsh-host.ts`、`desktop-host.ts`、选择器常量等)
* `test/e2e/global-setup.ts`:E2E 全局生命周期管理(启动/关闭宿主进程)
* `test/e2e/desktop/*.e2e.ts`:桌面端 E2E 用例 (`desktop` project)
-* `test/e2e/plugins/*.e2e.ts`:插件真实进程 E2E 用例 (`e2e` project)
+* `test/e2e/plugins/*.e2e.ts`:插件真实进程 E2E 用例 (`plugin` project)
* `packages/<name>/src/**/*.test.ts`:插件源码同级单元测试(保持原位)
### 3.2 用例文档目录
@@ -197,7 +197,7 @@ vitest --project unit -- <file> # 运行指定单文件测试
<br>`test/**`<br>
<br>`src/**/*.test.ts` | 排除 `test/archive/**` |
-| `e2e` | `vitest.e2e.config.ts` | `test/e2e/plugins/**/*.e2e.ts` | `globalSetup` 拉起真实 DSH;设置 `fileParallelism: false` |
+| `plugin` | `vitest.plugin.config.ts` | `test/e2e/plugins/**/*.e2e.ts` | `globalSetup` 拉起真实 DSH;设置 `fileParallelism: false` |
| `desktop` | `vitest.desktop.config.ts` | `test/e2e/desktop/*.e2e.ts` | 驱动真实 Tauri 桌面窗口 |
### 8.3 CI 与产物管理
diff --git a/docs/specs/plugin.test.md b/docs/specs/plugin.test.md
index bd1e1849..b38dba0e 100644
--- a/docs/specs/plugin.test.md
+++ b/docs/specs/plugin.test.md
@@ -27,7 +27,7 @@
| 层级 | 代码位置 | 驱动/运行器 | 断言对象 | 必选场景 |
| --- | --- | --- | --- | --- |
| **L1 单元测试** | `packages/<name>/src/**/*.test.ts` | Vitest (`unit` project) | 纯函数、路由 Handler、注册表契约 | 无条件必选 |
-| **L2 插件宿主 E2E** | `test/e2e/plugins/*.e2e.ts` | Vitest (`e2e` project) + Playwright API | 真实 `dsh web` 进程:路由响应、客户端挂载点、崩溃防护 | 每个产品可见插件 |
+| **L2 插件宿主 E2E** | `test/e2e/plugins/*.e2e.ts` | Vitest (`plugin` project) + Playwright API | 真实 `dsh web` 进程:路由响应、客户端挂载点、崩溃防护 | 每个产品可见插件 |
| **L3 桌面端宿主 E2E** | `test/e2e/desktop/*.e2e.ts` | Vitest (`desktop` project) + WebdriverIO | 桌面端壳层 + 内嵌 dsh iframe | 仅依赖 Tauri 桥的插件 |
> **分工原则**:L1 允许 Mock 宿主;L2/L3 下游全真,仅允许 Mock 外部服务(网络、模型、时钟)。
@@ -40,8 +40,8 @@
全仓**统一使用 Vitest 作为唯一测试运行器**,通过 `test.projects` 实现分层隔离:
-* **命令隔离**:使用 `vitest --project unit` 或 `--project e2e` 指定层级;`pnpm test` 运行全部。
-* **独立配置**:通过 `vitest.unit.config.ts` 与 `vitest.e2e.config.ts` (`defineProject`) 维护各自配置。
+* **命令隔离**:使用 `vitest --project unit` 或 `--project plugin` 指定层级;`pnpm test` 运行全部。
+* **独立配置**:通过 `vitest.unit.config.ts` 与 `vitest.plugin.config.ts` (`defineProject`) 维护各自配置。
* **全局报告**:由根目录 `vitest.config.ts` 统一管理报告与覆盖率(Project 级不支持配置 Reporters)。
* **生命周期**:利用 Project 的 `globalSetup` 完成真实宿主的单次启停,通过 `project.provide()` 注入服务地址。
* **浏览器驱动**:L2 采用 **Playwright 库 API** (`chromium.launch()`) 驱动浏览器,不引入 Playwright Test Runner。
@@ -70,7 +70,7 @@ test/e2e/
test/archive/* # 历史用例归档(只读参考,不被任何 project 匹配)
vitest.config.ts # 根配置:包含 Projects 清单与全局别名
vitest.unit.config.ts # unit project 配置
-vitest.e2e.config.ts # e2e project 配置(插件 L2)
+vitest.plugin.config.ts # e2e project 配置(插件 L2)
vitest.desktop.config.ts # desktop project 配置(桌面端 L3)
docs/testing/plugins/<序号>-<插件名>.md # 插件测试文档
```
@@ -94,7 +94,7 @@ docs/testing/plugins/<序号>-<插件名>.md # 插件测试文档
5. 校验挂载 ──> 确认 dsh.profile.bundles 包含目标插件(未找到则立即报错抛出)
6. 启动服务 ──> 执行 dsh web --host 127.0.0.1 --port 0 --no-open --skip-auth
7. 解析端点 ──> 捕获日志中的 `http://127.0.0.1:<port>/?token=<...>` 并解析 URL
-8. 执行测试 ──> 运行 vitest --project e2e,测试用例通过 inject() 提取服务地址
+8. 执行测试 ──> 运行 vitest --project plugin,测试用例通过 inject() 提取服务地址
9. 资源回收 ──> 触发 Teardown:终止 dsh 进程树,清空临时目录
```
@@ -102,7 +102,7 @@ docs/testing/plugins/<序号>-<插件名>.md # 插件测试文档
> **参数说明**:
> * `--skip-auth`:跳过浏览器一次性 Token 校验,避免误把“未鉴权”当作“路由丢失”。
> * `--profile`:`dsh web` 内置为 `--profile web` 别名,无需显式传参。
-> * `fileParallelism`:`e2e` project 设置为 `false`,确保单实例下串行断言的稳定性。
+> * `fileParallelism`:`plugin` project 设置为 `false`,确保单实例下串行断言的稳定性。
>
>
diff --git a/docs/testing/README.md b/docs/testing/README.md
index 85413125..e0cca3e4 100644
--- a/docs/testing/README.md
+++ b/docs/testing/README.md
@@ -25,7 +25,7 @@
| 层 | 用例位置 | 运行器 | 驱动 / 宿主 |
| --- | --- | --- | --- |
| **L1** 单元 | `packages/<name>/src/**/*.test.ts` | Vitest `unit` project | 无宿主,允许 Mock |
-| **L2** 插件宿主 E2E | `test/e2e/plugins/*.e2e.ts` | Vitest `e2e` project | 真实 `dsh web` 进程;需浏览器时用 Playwright 库 API |
+| **L2** 插件宿主 E2E | `test/e2e/plugins/*.e2e.ts` | Vitest `plugin` project | 真实 `dsh web` 进程;需浏览器时用 Playwright 库 API |
| **L3** 桌面端宿主 E2E | `test/e2e/desktop/*.e2e.ts` | Vitest `desktop` project | 真实 Tauri 窗口;WebdriverIO + `@wdio/tauri-service` |
全仓**只有一个测试运行器**(Vitest,通过 `test.projects` 分层)。WebdriverIO 与 Playwright 只作为**驱动库**被用例调用,不引入各自的 runner。
@@ -45,7 +45,7 @@ test/
├── archive/ # 历史用例归档,任何 project 都不收
vitest.config.ts # 根:projects 清单与全局别名
vitest.unit.config.ts
-vitest.e2e.config.ts
+vitest.plugin.config.ts
vitest.desktop.config.ts
```
diff --git a/docs/testing/plugins/00-overview.md b/docs/testing/plugins/00-overview.md
index d28154a6..5240b53c 100644
--- a/docs/testing/plugins/00-overview.md
+++ b/docs/testing/plugins/00-overview.md
@@ -14,7 +14,7 @@
| 层级 | 宿主 | 驱动方式 | 覆盖对象 |
| --- | --- | --- | --- |
-| L2 插件宿主 E2E | 真实 `dsh web` 进程(+ 真实浏览器页面) | Vitest `e2e` project;HTTP 断言先行,浏览器断言待接线 | 宿主路由、客户端挂载点、崩溃防护 |
+| L2 插件宿主 E2E | 真实 `dsh web` 进程(+ 真实浏览器页面) | Vitest `plugin` project;HTTP 断言先行,浏览器断言待接线 | 宿主路由、客户端挂载点、崩溃防护 |
| L3 桌面端宿主 E2E | 真实 Tauri 窗口(`deepseek-harness-desktop.exe`) | Vitest `desktop` project + WebdriverIO(内嵌 WebDriver server) | 依赖 Tauri 桥的插件与壳层集成 |
- **纳入范围**:`packages/` 下 10 个产品可见插件、核心桥接包 `dsh-tauri`、编排骨架、插件生命周期治理(清单/监控、禁用启用、升级卸载、快照、预装引导、异常修复、档案与补丁隔离、内置插件自愈)。
@@ -101,7 +101,7 @@
| 附加挂载 | `DSH_E2E_ALSO`(逗号分隔) | `test/e2e/global-setup.ts:30` |
| 挂载模式 | `DSH_E2E_MOUNT=link`(默认)/ `cli` | `test/e2e/support/dsh-host.ts:322` |
| 保留现场 | `DSH_E2E_KEEP_HOME=1` | `test/e2e/global-setup.ts:31` |
-| 运行 | `pnpm test:e2e:plugin`(= `vitest --project e2e`) | `package.json:21` |
+| 运行 | `pnpm test:e2e:plugin`(= `vitest --project plugin`) | `package.json:21` |
| 隔离 | 每次运行独占 `<tmp>/dsh-e2e-<plugin>-<时间戳>`,不触碰用户真实 `DSH_HOME` | `test/e2e/support/dsh-host.ts:313` |
---
diff --git a/docs/testing/plugins/01-host-lane-skeleton.md b/docs/testing/plugins/01-host-lane-skeleton.md
index 87dd8ce3..e5701147 100644
--- a/docs/testing/plugins/01-host-lane-skeleton.md
+++ b/docs/testing/plugins/01-host-lane-skeleton.md
@@ -4,7 +4,7 @@
> 自动化:`test/e2e/plugins/host-lane.e2e.ts`(待建立;本文件是它的用例来源)
> 前置:`pnpm build:plugins` 已产出 `packages/*/dist`;`DSH_E2E_DSH_BIN` 或桌面端装配目录内存在 `@deepseek-ai/dsh/lib/bin.js`
> 编排:`test/e2e/support/dsh-host.ts`;全局生命周期:`test/e2e/global-setup.ts`
-> 运行:`pnpm test:e2e:plugin`(= `vitest --project e2e`)
+> 运行:`pnpm test:e2e:plugin`(= `vitest --project plugin`)
本批是全套插件用例的地基:**先证明编排本身可信**,再谈插件行为。若这里不成立,后面所有「插件路由 404」都无法区分是插件没挂上还是宿主没起来。
@@ -28,7 +28,7 @@
| 就绪上限 120s | `test/e2e/support/dsh-host.ts:39` |
| 收尾:Windows `taskkill /T /F`;其余 SIGTERM→SIGKILL | `test/e2e/support/dsh-host.ts:371`、`test/e2e/support/dsh-host.ts:255` |
| 地址下传:`project.provide('dshBaseUrl' / 'dshUrl' / 'dshHome' / 'dshMounted')` | `test/e2e/global-setup.ts:33` |
-| project 归属:`packages/*/test/**/*.e2e.ts`,`fileParallelism: false`,超时 120s | `vitest.e2e.config.ts:15`、`vitest.e2e.config.ts:18` |
+| project 归属:`packages/*/test/**/*.e2e.ts`,`fileParallelism: false`,超时 120s | `vitest.plugin.config.ts:15`、`vitest.plugin.config.ts:18` |
---
diff --git a/package.json b/package.json
index 17fc1ffa..002493e9 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"release": "bumpp --pr",
"test": "vitest",
"test:unit": "vitest --project unit",
- "test:e2e:plugin": "vitest --project e2e",
+ "test:e2e:plugin": "vitest --project plugin",
"test:e2e:desktop": "vitest --project desktop",
"lint": "eslint",
"knip": "knip",
diff --git a/test/archive/backup.test.ts b/test/backup.test.ts
similarity index 97%
rename from test/archive/backup.test.ts
rename to test/backup.test.ts
index 3a8d8787..29776308 100644
--- a/test/archive/backup.test.ts
+++ b/test/backup.test.ts
@@ -1,11 +1,11 @@
-import type { BackupSettings } from '../../src/utils/backup-settings'
+import type { BackupSettings } from '../src/utils/backup-settings'
import { readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
import {
normalizeIntervalDays,
normalizeRetentionCount,
-} from '../../src/utils/backup-settings'
+} from '../src/utils/backup-settings'
describe('backup settings normalization', () => {
it('keeps a valid interval as-is', () => {
diff --git a/test/archive/clipboard.test.ts b/test/clipboard.test.ts
similarity index 96%
rename from test/archive/clipboard.test.ts
rename to test/clipboard.test.ts
index 2724a042..4286379d 100644
--- a/test/archive/clipboard.test.ts
+++ b/test/clipboard.test.ts
@@ -1,7 +1,7 @@
import { readFileSync } from 'node:fs'
import { invoke } from '@tauri-apps/api/core'
import { afterEach, describe, expect, it, vi } from 'vitest'
-import { writeClipboardText } from '../../src/utils/clipboard'
+import { writeClipboardText } from '../src/utils/clipboard'
vi.mock('@tauri-apps/api/core', () => ({
invoke: vi.fn(),
diff --git a/test/archive/clone-profile.test.ts b/test/clone-profile.test.ts
similarity index 100%
rename from test/archive/clone-profile.test.ts
rename to test/clone-profile.test.ts
diff --git a/test/archive/close-action.test.ts b/test/close-action.test.ts
similarity index 89%
rename from test/archive/close-action.test.ts
rename to test/close-action.test.ts
index c3b219f6..7895977a 100644
--- a/test/archive/close-action.test.ts
+++ b/test/close-action.test.ts
@@ -4,7 +4,7 @@ import {
CLOSE_ACTION_DEFAULT,
CLOSE_ACTION_OPTIONS,
normalizeCloseAction,
-} from '../../src/utils/close-action'
+} from '../src/utils/close-action'
describe('close action normalization', () => {
it('defaults to hiding in tray', () => {
@@ -37,8 +37,9 @@ describe('config close action control contract', () => {
expect(source).toContain('export function ConfigCloseAction')
// 读走 setting store(与 Rust 共享 .store.dat,后端改动经 setting_updated 回流)
expect(source).toContain('useStore(store.setting)')
- // 写仍走命令:后端归一化并在锁内落盘,避免与 Rust 的整对象写入互相覆盖
- expect(source).toContain('invoke(\'update_app_config\', { closeAction')
+ // 写走 store.setting.update:后端统一归一化并在锁内落盘,前端直接改 store
+ // 会与 Rust 的整对象写入互相覆盖;断言归一化后的 camelCase 字段名。
+ expect(source).toContain('closeAction: normalizeCloseAction(next)')
// 受控值始终经归一化,未加载到配置时回落 tray 而不是给 HeroUI 传 undefined
expect(source).toContain('selectedKey={normalizeCloseAction(')
})
diff --git a/test/archive/compat-iterator.test.ts b/test/compat-iterator.test.ts
similarity index 100%
rename from test/archive/compat-iterator.test.ts
rename to test/compat-iterator.test.ts
diff --git a/test/archive/core-version.test.ts b/test/core-version.test.ts
similarity index 100%
rename from test/archive/core-version.test.ts
rename to test/core-version.test.ts
diff --git a/test/e2e/support/dsh-host.ts b/test/e2e/support/dsh-host.ts
index 908f6226..e20a719e 100644
--- a/test/e2e/support/dsh-host.ts
+++ b/test/e2e/support/dsh-host.ts
@@ -33,7 +33,7 @@ const PROFILE = 'web'
* 就绪行正则:只取 URL 本体(`dsh web: ` 前缀留在匹配之外,否则 `new URL()` 会抛)。
* 必须吃到空白为止——在 `/` 处截断会丢掉 `?token=`,首屏直接 401。
*/
-const READY_RE = /http:\/\/127\.0\.0\.1:\d+[^\s]*/
+const READY_RE = /http:\/\/127\.0\.0\.1:\d\S*/
/** 就绪等待上限(冷启 dsh web + 插件装配)。 */
const READY_TIMEOUT_MS = 120_000
@@ -169,8 +169,8 @@ function writeProfile(profileDir: string, bundles: readonly string[]): void {
' protobufjs: true',
'',
'minimumReleaseAgeExclude:',
- " - '@deepseek-ai/*'",
- " - 'dsh-tauri*'",
+ ' - \'@deepseek-ai/*\'',
+ ' - \'dsh-tauri*\'',
'',
].join('\n'))
}
@@ -215,10 +215,10 @@ function run(command: string, args: readonly string[], cwd: string, env: NodeJS.
return new Promise((resolvePromise, reject) => {
const child = spawn(command, [...args], { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true })
let output = ''
- child.stdout?.on('data', (chunk: Buffer) => {
+ child.stdout?.on('data', (chunk: Uint8Array) => {
output += chunk.toString()
})
- child.stderr?.on('data', (chunk: Buffer) => {
+ child.stderr?.on('data', (chunk: Uint8Array) => {
output += chunk.toString()
})
child.on('error', reject)
@@ -360,7 +360,7 @@ export async function startDshHost(options: StartDshHostOptions): Promise<DshHos
windowsHide: true,
})
const chunks: string[] = []
- const collect = (chunk: Buffer): void => {
+ const collect = (chunk: Uint8Array): void => {
chunks.push(chunk.toString())
writeFileSync(logPath, chunks.join(''))
}
diff --git a/test/e2e/support/wdio-probe.mjs b/test/e2e/support/wdio-probe.mjs
index 0f3e21c8..2864caeb 100644
--- a/test/e2e/support/wdio-probe.mjs
+++ b/test/e2e/support/wdio-probe.mjs
@@ -1,4 +1,5 @@
#!/usr/bin/env node
+/* eslint-disable no-console -- CLI 探针:stdout 就是它唯一的产出通道 */
// D0 临时探针:验证 debug 二进制内嵌的 WebDriver server 能否被纯 HTTP 驱动。
// 只验这一个不确定性,通过后由 D1 的正式接线取代;见 docs/testing/desktop/basic.md。
diff --git a/test/archive/index.test.ts b/test/index.test.ts
similarity index 98%
rename from test/archive/index.test.ts
rename to test/index.test.ts
index 44cc5a9b..a43c453f 100644
--- a/test/archive/index.test.ts
+++ b/test/index.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { containsInotifyLimitError, formatLogLine, pickErrorLines } from '../../src/components/logs.utils'
+import { containsInotifyLimitError, formatLogLine, pickErrorLines } from '../src/components/logs.utils'
describe('formatLogLine', () => {
it('strips the official GitHub release download prefix', () => {
diff --git a/test/archive/internal-plugin-phase.test.ts b/test/internal-plugin-phase.test.ts
similarity index 87%
rename from test/archive/internal-plugin-phase.test.ts
rename to test/internal-plugin-phase.test.ts
index 6ae87d95..727d3070 100644
--- a/test/archive/internal-plugin-phase.test.ts
+++ b/test/internal-plugin-phase.test.ts
@@ -1,8 +1,8 @@
-import type { InternalPluginsPhasePayload } from '../../src/store/modules/harness'
+import type { InternalPluginsPhasePayload } from '../src/store/modules/harness'
import { readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
-import { INTERNAL_PLUGIN_PHASE_DETAILS } from '../../src/store/modules/harness'
-import { internalPluginReason } from '../../src/store/modules/harness/utils'
+import { INTERNAL_PLUGIN_PHASE_DETAILS } from '../src/store/modules/harness'
+import { internalPluginReason } from '../src/store/modules/harness/utils'
function translate(key: string): string {
return key
diff --git a/test/archive/menu-restart.test.ts b/test/menu-restart.test.ts
similarity index 83%
rename from test/archive/menu-restart.test.ts
rename to test/menu-restart.test.ts
index 2c134ee9..1250adbc 100644
--- a/test/archive/menu-restart.test.ts
+++ b/test/menu-restart.test.ts
@@ -16,7 +16,11 @@ const navbarSource = readFileSync(
describe('menu restart backend contract', () => {
it('places desktop-restart menu item after run_logs in help submenu', () => {
- expect(builderSource).toContain('&run_logs, &restart, &check_update')
+ // 源码按项分行,不再是一行字面量:改为断言三者在该子菜单里的相对顺序。
+ const helpMenu = builderSource.slice(builderSource.indexOf('"desktop-help-menu"'))
+ const order = ['&run_logs', '&restart', '&check_update'].map(item => helpMenu.indexOf(item))
+ expect(order.every(index => index >= 0)).toBe(true)
+ expect(order).toEqual([...order].sort((a, b) => a - b))
})
it('emits macos-menu-action for desktop-restart in on_menu_event', () => {
diff --git a/test/archive/patch-layer.test.ts b/test/patch-layer.test.ts
similarity index 99%
rename from test/archive/patch-layer.test.ts
rename to test/patch-layer.test.ts
index d9a4aa28..1b8ce836 100644
--- a/test/archive/patch-layer.test.ts
+++ b/test/patch-layer.test.ts
@@ -8,7 +8,7 @@ import {
patchEntryUnresolvedEntries,
patchLayerErrorDetail,
quarantineFailureDetail,
-} from '../../src/store/modules/harness/patch-layer'
+} from '../src/store/modules/harness/patch-layer'
/**
* issue #525:用户手写的 `cordis.patch.yml` 解析失败时,启动失败信息里的真实
diff --git a/test/archive/pet-asset-headers.test.ts b/test/pet-asset-headers.test.ts
similarity index 100%
rename from test/archive/pet-asset-headers.test.ts
rename to test/pet-asset-headers.test.ts
diff --git a/test/archive/pet-window-lifecycle.test.ts b/test/pet-window-lifecycle.test.ts
similarity index 100%
rename from test/archive/pet-window-lifecycle.test.ts
rename to test/pet-window-lifecycle.test.ts
diff --git a/test/archive/plugin-boot.test.ts b/test/plugin-boot.test.ts
similarity index 100%
rename from test/archive/plugin-boot.test.ts
rename to test/plugin-boot.test.ts
diff --git a/test/archive/plugin-disable.test.ts b/test/plugin-disable.test.ts
similarity index 100%
rename from test/archive/plugin-disable.test.ts
rename to test/plugin-disable.test.ts
diff --git a/test/archive/plugin-resource-closure.test.ts b/test/plugin-resource-closure.test.ts
similarity index 80%
rename from test/archive/plugin-resource-closure.test.ts
rename to test/plugin-resource-closure.test.ts
index 6213571d..ae51f92a 100644
--- a/test/archive/plugin-resource-closure.test.ts
+++ b/test/plugin-resource-closure.test.ts
@@ -1,12 +1,19 @@
-import { readdirSync, readFileSync, statSync } from 'node:fs'
+import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
import { join } from 'node:path'
-import { pathToFileURL } from 'node:url'
+import { fileURLToPath, pathToFileURL } from 'node:url'
import { describe, expect, it } from 'vitest'
const BUNDLE_MANIFEST = new URL('../packages/dsh-tauri-bundle/package.json', import.meta.url)
const RESOURCE_NODE_MODULES = new URL('../src-tauri/resources/node_modules/', import.meta.url)
const DSH_STATIC_IMPORT = /\b(?:from|import)\s*['"]@deepseek-ai\/[^'"]+['"]|\brequire\s*\(\s*['"]@deepseek-ai\/[^'"]+['"]\s*\)/
+/**
+ * 部署产物 `src-tauri/resources/node_modules/` 由 `pnpm build:plugins` 生成,不随仓库提交。
+ * 未构建时整组用例跳过——否则每次干净检出都会报「文件不存在」,把缺前置误报成缺陷。
+ * CI 的 Plugins E2E job 会先构建,因此那一条链路下本组用例照常执行。
+ */
+const BUILT = existsSync(fileURLToPath(RESOURCE_NODE_MODULES))
+
interface PluginManifest {
name?: unknown
dependencies?: Record<string, unknown>
@@ -31,7 +38,7 @@ function packageJsonFiles(root: URL): string[] {
return files
}
-describe('bundled plugin resource closure', () => {
+describe.skipIf(!BUILT)('bundled plugin resource closure', () => {
it('contains every bundled plugin with a valid entry', () => {
for (const name of bundledPluginNames()) {
const manifestUrl = new URL(`../src-tauri/resources/node_modules/${name}/package.json`, import.meta.url)
diff --git a/test/archive/plugin-uninstall.test.ts b/test/plugin-uninstall.test.ts
similarity index 100%
rename from test/archive/plugin-uninstall.test.ts
rename to test/plugin-uninstall.test.ts
diff --git a/test/archive/preinstall-uncheck.test.ts b/test/preinstall-uncheck.test.ts
similarity index 100%
rename from test/archive/preinstall-uncheck.test.ts
rename to test/preinstall-uncheck.test.ts
diff --git a/test/archive/readiness.test.ts b/test/readiness.test.ts
similarity index 99%
rename from test/archive/readiness.test.ts
rename to test/readiness.test.ts
index 2d46684c..7849fb9c 100644
--- a/test/archive/readiness.test.ts
+++ b/test/readiness.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { BoundedReloadGate, pollReadiness, SingleFlight, waitForActivityTask } from '../../src/store/modules/harness/readiness'
+import { BoundedReloadGate, pollReadiness, SingleFlight, waitForActivityTask } from '../src/store/modules/harness/readiness'
function noWait(): Promise<void> {
return Promise.resolve()
diff --git a/test/archive/release-identity.test.ts b/test/release-identity.test.ts
similarity index 98%
rename from test/archive/release-identity.test.ts
rename to test/release-identity.test.ts
index 1d4835f1..0cc9f4d3 100644
--- a/test/archive/release-identity.test.ts
+++ b/test/release-identity.test.ts
@@ -4,7 +4,7 @@ import { tmpdir } from 'node:os'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { afterEach, describe, expect, it } from 'vitest'
-import * as releaseIdentityModule from '../../scripts/release-identity.mjs'
+import * as releaseIdentityModule from '../scripts/release-identity.mjs'
interface SemverIdentity {
version: string
diff --git a/test/archive/runtime-exit-store.test.ts b/test/runtime-exit-store.test.ts
similarity index 100%
rename from test/archive/runtime-exit-store.test.ts
rename to test/runtime-exit-store.test.ts
diff --git a/test/archive/runtime-exit.test.ts b/test/runtime-exit.test.ts
similarity index 97%
rename from test/archive/runtime-exit.test.ts
rename to test/runtime-exit.test.ts
index 5dae0bba..18ee96b4 100644
--- a/test/archive/runtime-exit.test.ts
+++ b/test/runtime-exit.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { runtimeExitMessageKey, shouldAcceptRuntimeExit } from '../../src/store/modules/harness/runtime'
+import { runtimeExitMessageKey, shouldAcceptRuntimeExit } from '../src/store/modules/harness/runtime'
describe('runtime exit acceptance', () => {
const current = {
diff --git a/test/archive/setup-copy-logs.test.ts b/test/setup-copy-logs.test.ts
similarity index 92%
rename from test/archive/setup-copy-logs.test.ts
rename to test/setup-copy-logs.test.ts
index ffcfc984..9c6d2af3 100644
--- a/test/archive/setup-copy-logs.test.ts
+++ b/test/setup-copy-logs.test.ts
@@ -23,9 +23,10 @@ describe('setup error page copy-logs contract (SYST-04)', () => {
const source = readFileSync(new URL('../src/layout/components/setup.tsx', import.meta.url), 'utf8')
const nativeWrite = source.indexOf('writeClipboardText(')
expect(nativeWrite).toBeGreaterThan(-1)
- // 调用点只记录日志(失败提示统一由 helper 弹出),成功文案经第二个参数传入
+ // 调用点只记录日志(失败提示统一由 helper 弹出),成功文案经第二个参数传入。
+ // 实现走 Promise 链式 `.catch((err) =>`,不是 `try/catch`。
const callSite = source.slice(nativeWrite, nativeWrite + 500)
- expect(callSite).toContain('catch (err)')
+ expect(callSite).toContain('.catch((err) =>')
expect(callSite).toContain('messages.logs_copied')
const helper = readFileSync(new URL('../src/utils/clipboard.ts', import.meta.url), 'utf8')
diff --git a/test/archive/toast.test.ts b/test/toast.test.ts
similarity index 97%
rename from test/archive/toast.test.ts
rename to test/toast.test.ts
index 0c26a0b9..9037fd6f 100644
--- a/test/archive/toast.test.ts
+++ b/test/toast.test.ts
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
-import { activeQueues as queues, toast } from '../../src/utils/toast'
+import { activeQueues as queues, toast } from '../src/utils/toast'
afterEach(() => {
toast.clear()
diff --git a/test/archive/zoom.test.ts b/test/zoom.test.ts
similarity index 87%
rename from test/archive/zoom.test.ts
rename to test/zoom.test.ts
index dd5abe77..4b055b71 100644
--- a/test/archive/zoom.test.ts
+++ b/test/zoom.test.ts
@@ -1,12 +1,11 @@
import { describe, expect, it } from 'vitest'
import {
- nextZoomFactor,
normalizeZoomFactor,
zoomActionFromBridgeMessage,
zoomActionFromShortcut,
zoomFactorFromLevel,
zoomLevelFromFactor,
-} from '../../src/utils/zoom'
+} from '../src/utils/zoom'
function shortcut(
key: string,
@@ -91,12 +90,16 @@ describe('zoom factor stepping (mirrors Rust normalize_zoom_factor)', () => {
expect(normalizeZoomFactor(Number.POSITIVE_INFINITY)).toBe(1)
})
+ // `nextZoomFactor` 已从实现中移除:步进现在由 UI 组件按 ZOOM_FACTOR_STEP
+ // 计算后交给 normalizeZoomFactor 归一化。这里断言同一语义的现役路径。
it('steps by 0.1 and resets to 100%', () => {
- expect(nextZoomFactor(1, 'increase')).toBeCloseTo(1.1, 10)
- expect(nextZoomFactor(1, 'decrease')).toBeCloseTo(0.9, 10)
- expect(nextZoomFactor(1.7, 'reset')).toBe(1)
+ const step = (from: number, delta: number) => normalizeZoomFactor(from + delta)
+
+ expect(step(1, 0.1)).toBeCloseTo(1.1, 10)
+ expect(step(1, -0.1)).toBeCloseTo(0.9, 10)
+ expect(normalizeZoomFactor(1.7)).toBe(1.7)
// 到顶/到底后不再越界
- expect(nextZoomFactor(2, 'increase')).toBe(2)
- expect(nextZoomFactor(0.5, 'decrease')).toBe(0.5)
+ expect(step(2, 0.1)).toBe(2)
+ expect(step(0.5, -0.1)).toBe(0.5)
})
})
diff --git a/vitest.config.ts b/vitest.config.ts
index 59d35588..5ac2af2f 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -5,10 +5,13 @@ import { defineConfig } from 'vitest/config'
* 根 Vitest 配置:只放「跨 project 的全局项」与 project 清单。
*
* Vitest 不把根配置本身当作 project(除非显式列出),因此这里不再写任何 include:
- * 用例归属由 `vitest.unit.config.ts`(单元)与 `vitest.e2e.config.ts`(E2E)各自声明。
+ * 用例归属由 `vitest.unit.config.ts`(单元)、`vitest.plugin.config.ts`(插件 L2)
+ * 与 `vitest.desktop.config.ts`(桌面端 L3)各自声明。
+ *
+ * 注意 project 级配置**不继承**这里的 `resolve.alias`,各 project 需自行声明 `@/`。
*
* 仓库根还 vendored 了 dsh 核心源码(`source/` 与 `archive/`),其测试依赖 dsh 核心的
- * `@/` paths 解析(在插件 workspace 的 vitest 下不可用),故两个 project 都不纳入。
+ * `@/` paths 解析(在插件 workspace 的 vitest 下不可用),故三个 project 都不纳入。
*/
export default defineConfig({
// 与 vite.config.ts 保持一致:src 内部统一用 `@/` 别名。
@@ -20,7 +23,7 @@ export default defineConfig({
test: {
projects: [
'./vitest.unit.config.ts',
- './vitest.e2e.config.ts',
+ './vitest.plugin.config.ts',
'./vitest.desktop.config.ts',
],
},
diff --git a/vitest.e2e.config.ts b/vitest.plugin.config.ts
similarity index 88%
rename from vitest.e2e.config.ts
rename to vitest.plugin.config.ts
index 93dbf4a5..4b77f1a7 100644
--- a/vitest.e2e.config.ts
+++ b/vitest.plugin.config.ts
@@ -1,7 +1,7 @@
import { defineProject } from 'vitest/config'
/**
- * `e2e` project:插件 L2 E2E(真实 `dsh web` 进程)。
+ * `plugin` project:插件 L2 E2E(真实 `dsh web` 进程)。
*
* 用例集中在 `test/e2e/plugins/`,与桌面端 L3 的 `test/e2e/desktop/` 平级;
* 共享编排(`support/dsh-host.ts`)与 `global-setup.ts` 留在 `test/e2e/` 根下。
@@ -11,7 +11,7 @@ import { defineProject } from 'vitest/config'
*/
export default defineProject({
test: {
- name: 'e2e',
+ name: 'plugin',
include: ['test/e2e/plugins/**/*.e2e.ts'],
globalSetup: ['./test/e2e/global-setup.ts'],
environment: 'node',
diff --git a/vitest.unit.config.ts b/vitest.unit.config.ts
index 6f9796a9..96937bc9 100644
--- a/vitest.unit.config.ts
+++ b/vitest.unit.config.ts
@@ -1,3 +1,4 @@
+import { fileURLToPath } from 'node:url'
import { defineProject } from 'vitest/config'
/**
@@ -5,23 +6,31 @@ import { defineProject } from 'vitest/config'
*
* 两条来源:
* 1. 内置插件(`packages/**`)——测试与其覆盖的源码同目录、同名(`*.test.ts`);
- * 2. 壳层自身的用例——`test/unit/**` 与 `src/**` 下与逻辑同名的 `.test.ts`。
+ * 2. 壳层自身的用例——`test/**` 与 `src/**` 下与逻辑同名的 `.test.ts`。
*
* `test/archive/**` 是历史用例的归档(只读参考,不参与任何 project)。
*
+ * 别名:project 级配置不继承根 `vitest.config.ts` 的 `resolve.alias`,而壳层用例
+ * 普遍 import `@/…`,因此这里必须重复声明一次。
+ *
* 并发与超时:`dsh-tauri-worktree` 的 operation.test 会创建真实 git 仓库
* (clone/checkout/discard),全量并行时与其他文件的 git 操作竞争系统资源,
* 偶发 5s 超时 flake;限制 maxWorkers 后单独复跑稳定通过。
*
* E2E 用例(`test/e2e/desktop` 与 `test/e2e/plugins` 下的 `.e2e.ts`)由
- * `vitest.desktop.config.ts` / `vitest.e2e.config.ts` 负责,本 project 不收。
+ * `vitest.desktop.config.ts` / `vitest.plugin.config.ts` 负责,本 project 不收。
*/
export default defineProject({
+ resolve: {
+ alias: {
+ '@': fileURLToPath(new URL('./src', import.meta.url)),
+ },
+ },
test: {
name: 'unit',
include: [
'packages/**/*.{test,spec}.{ts,tsx,js,mjs,cjs}',
- 'test/unit/**/*.test.ts',
+ 'test/**/*.test.ts',
'src/**/*.test.ts',
],
exclude: ['test/archive/**', 'archive/**'],