DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
test(plugin-e2e): 批次 01 编排骨架与共享路由契约落地
hairyfeb214f2da4cf
diff --git a/docs/specs/plugin.test.md b/docs/specs/plugin.test.mdindex 552cfa59..f682beb7 100644--- a/docs/specs/plugin.test.md+++ b/docs/specs/plugin.test.md@@ -65,20 +65,21 @@ test/e2e/├── support/│ ├── dsh-host.ts # 共享环境脚手架(Scratch DSH_HOME、挂载、启动、鉴权交换、清理)│ └── desktop-host.ts # L3 桌面端宿主编排-├── plugins/*.e2e.ts # L2 插件宿主 E2E(由 plugin project 匹配)+├── plugins/<序号>-<主题>.e2e.ts # L2 插件宿主 E2E(由 plugin project 匹配)└── desktop/*.e2e.ts # L3 桌面端宿主 E2E(由 desktop project 匹配)test/archive/* # 历史用例归档(只读参考,不被任何 project 匹配)vitest.config.ts # 根配置:包含 Projects 清单与全局别名vitest.unit.config.ts # unit project 配置vitest.plugin.config.ts # plugin project 配置(插件 L2)vitest.desktop.config.ts # desktop project 配置(桌面端 L3)-docs/testing/plugins/<序号>-<插件名>.md # 插件测试文档+docs/testing/plugins/<序号>-<主题>.md # 插件测试文档```* **命名约定**:L2/L3 文件必须使用 `*.e2e.ts`,与 L1 的 `*.test.ts` / `*.spec.ts` 严格区分。+* **文件名对应**:`test/e2e/plugins/<序号>-<主题>.e2e.ts` 与 `docs/testing/plugins/<序号>-<主题>.md` **同名同序号一一对应**。一个编号只允许一个测试文件;同一批次内的 L2 / 客户端 / L3 用例用 `describe` 分区,不拆成多个文件。总览类文档(`00-overview.md`)不承载用例,故无对应测试文件。* **用例编号**:`TC-<业务域>-<层级>-<文件序号>-<序号>`,如 `TC-PET-L2-03-001`。业务域取该文件的主域前缀、文件序号取 `docs/testing/plugins/<序号>-*.md` 的序号、序号在「文件 + 层级」内从 `001` 起连续(层级取 `L2` / `L3` / `C`)。序号**不跨文件连续**:新增用例只影响本文件,不会波及后续文件。* **匹配策略**:`unit` 匹配 `*.{test,spec}.*`(自动排他 `.e2e.ts`);`plugin` 显式指定 `test/e2e/plugins/**/*.e2e.ts`,`desktop` 指定 `test/e2e/desktop/*.e2e.ts`。-* **映射关系**:文档中的每条用例条目必须与代码中的 `test()` 一一对应。+* **映射关系**:文档中的每条用例条目必须与代码中的 `it()` 一一对应。---diff --git a/docs/testing/README.md b/docs/testing/README.mdindex 47188b55..844989b8 100644--- a/docs/testing/README.md+++ b/docs/testing/README.md@@ -25,11 +25,13 @@| 层 | 用例位置 | 运行器 | 驱动 / 宿主 || --- | --- | --- | --- || **L1** 单元 | `packages/<name>/src/**/*.test.ts` | Vitest `unit` project | 无宿主,允许 Mock |-| **L2** 插件宿主 E2E | `test/e2e/plugins/*.e2e.ts` | Vitest `plugin` 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。+插件用例的测试文件与用例文档**同名同序号一一对应**:`test/e2e/plugins/<序号>-<主题>.e2e.ts` ↔ `docs/testing/plugins/<序号>-<主题>.md`,一个编号只允许一个测试文件(批内按层用 `describe` 分区)。+---## 3. 目录约定diff --git a/docs/testing/history.md b/docs/testing/history.mdindex 56a4a6a0..4f589a80 100644--- a/docs/testing/history.md+++ b/docs/testing/history.md@@ -34,3 +34,5 @@| 2026-09 | **桌面端 E2E 收敛为一条启动冒烟**:桌面壳层职责收敛为「进入下载装配 → dsh 内核启动 → 页面无报错」。删除 `test/e2e/desktop/01-window-shell.e2e.ts`、`02-config-locale.e2e.ts` 与只服务它们的 `support/{navbar-menu,config-dialog,onboarding}.ts`,新增 `test/e2e/desktop/boot.e2e.ts`(`TC-DSK-L3-01-001`,含壳层与帧内报错收集);`support/selectors.ts` 只保留冒烟用到的锚点。`desktop-host.ts` 去掉 `disableDownload` 车道,下载缓存默认改为本次运行独占空目录(装配必然真的下载并落盘),WebDriver 端口改从 `TAURI_WEBDRIVER_PORT` 读取(默认 4445,非法值当场 Fail)。生产侧「禁用自动下载」机制一并移除:`DISABLE_AUTO_DOWNLOAD`、`DSH_E2E_DISABLE_DOWNLOAD`、`auto_download_disabled()`、`RuntimeInfo.auto_download_disabled`、`setup.tsx` 的禁用页与 `status.download_disabled*` 文案、`store.harness.downloadDisabled` 及相关 Rust 单测。文档:`docs/testing/desktop/` 只保留 `00-overview.md`(重写)与 `01-boot.md`(新增),其余 11 份用例文档归档到 `archive/docs/testing/desktop/`;`docs/specs/desktop.test.md` 与 `docs/testing/README.md` 同步收敛 || 2026-09 | **插件用例文档收敛(17 → 11 个文件,170 → 108 条)**:移除清单监控、生命周期指令、预装引导、异常恢复、档案与补丁隔离、跨插件集成 6 份文档(`11`–`16`),归档到 `archive/docs/testing/plugins/`;`plugins/00-overview.md` §3/§6/§7/§8、`docs/testing/README.md`、`docs/testing/progressive.md` §4.2 与 `docs/specs/desktop.test.md` §7 同步收敛 || 2026-09 | 变更历史从 `progressive.md` §5 迁出为独立文件 `docs/testing/history.md`;`AGENTS.md` 增加测试入口约定(改动行为须同步 `docs/testing/README.md` 指向的用例文档与测试代码) |+| 2026-09 | **测试文件与用例文档同名同序号**:`test/e2e/plugins/<序号>-<主题>.e2e.ts` ↔ `docs/testing/plugins/<序号>-<主题>.md`,一个编号只允许一个测试文件(批内按层用 `describe` 分区)。`session-stream.e2e.ts` → `02-dsh-tauri-pet.e2e.ts`;新增 `01-dsh-host-and-core-contract.e2e.ts`。`docs/specs/plugin.test.md` §4 与 `plugins/00-overview.md` §2/§3/§9 同步 |+| 2026-09 | **批次 `01` 实现并运行验证(插件车道,12 例全绿)**:`test/e2e/plugins/01-dsh-host-and-core-contract.e2e.ts` 覆盖编排骨架 6 例(`TC-HOST-L2-01-001`–`006`)+ 共享路由契约 6 例(`TC-CORE-L2-01-001`–`006`),`pnpm test:e2e:plugin` 全车道 14 例通过。编排新增导出 `assertMountRegistered`(`test/e2e/support/dsh-host.ts:273`),使 link 模式下不可达的「挂载漏登记」分支可被直接覆盖。「未构建产物」夹具改用 `dsh-tauri-tsdown`(源码即产物、被 `build:plugins` 显式排除),不再移动仓库产物。**实测修正**:跨源变更请求在真实宿主里由上游 `dsh-client-connection` 的 Host/Origin 围栏先拒(`forbidden`),路由层 `routes/index.ts:287` 的 `cross-origin-request` 在 L2 不可达,该分支由 L1 `packages/dsh-tauri/src/host/routes/index.test.ts:240` 覆盖,`plugins/01` 的期望值已按可观察事实改写;`plugins/00-overview.md` 缺口 G1/G4 消解、新增 G10 |diff --git a/docs/testing/plugins/00-overview.md b/docs/testing/plugins/00-overview.mdindex 447907d0..f6c52348 100644--- a/docs/testing/plugins/00-overview.md+++ b/docs/testing/plugins/00-overview.md@@ -3,7 +3,7 @@> 层级:总览(不承载可执行用例本体)> 规范来源:[插件 E2E 测试规范](../../specs/plugin.test.md)、[桌面端 E2E 测试规范](../../specs/desktop.test.md)> 流程来源:[渐进式测试推进规则](../progressive.md)-> 状态:提案中(文档已提交,等待授权与运行验证)+> 状态:已验证(总览事实已按当前实现刷新;批次 01 已通过运行验证)---@@ -32,11 +32,12 @@| `docs/specs/desktop.test.md` | 用例文档字段与优先级口径、`data-testid` 规范、端口/数据目录隔离、目录归属 || `docs/testing/progressive.md` | 单批单卡、状态定义与台账位置 || 源码事实 | `packages/*/src/**`、`src/**`、`src-tauri/src/**`、`test/e2e/support/**` |-| 现有测试 | `test/e2e/plugins/session-stream.e2e.ts`(SSE 首帧已落地) |+| 现有测试 | `test/e2e/plugins/01-dsh-host-and-core-contract.e2e.ts`(编排骨架 + 共享路由契约 12 例已落地)、`test/e2e/plugins/02-dsh-tauri-pet.e2e.ts`(SSE 首帧 2 例已落地) |**已记录的冲突与取舍**:1. **用例文档目录**:`desktop.test.md` §3.2 写 `docs/testing/plugins/<插件名>.md`,`plugin.test.md` §4 写 `docs/testing/plugins/<name>.md`;两者一致。本次额外要求「从 00 编号开始」,故统一采用 `<序号>-<主题>.md`。+ **测试文件同规则**:`test/e2e/plugins/<序号>-<主题>.e2e.ts`,与用例文档**同名同序号一一对应**(一个编号 = 一个文档 = 一个测试文件,批内多段用 `describe` 分区,不再拆文件)。2. **优先级口径**:用例编写通用口径为 P0–P3,本仓规范为 P1–P5。**以本仓规范为准**(见 §4),不混用。3. **L2 浏览器驱动**:`plugin.test.md` §3.2 指定 Playwright 库 API;当前 `package.json` 与 `pnpm-lock.yaml` 中均无 `playwright`(见 §8 缺口 G2),因此浏览器类用例在本套文档中保留设计,但标注为**未接线**。4. **桌面端端口是否固定**:`desktop.test.md` §6 称 debug 固定 `3081`、不可动态修改;实现侧存在端口占用后递增的逻辑(`src-tauri/src/service/workflow/launch.rs:874`,`src-tauri/capabilities/default.json:4` 注释亦声明 port is NOT fixed)。**本套文档以「默认 3081 + 运行前实测空闲」为准**,不假设端口绝对不变(见 §8 G5)。@@ -48,19 +49,19 @@编号即推进顺序:编号越大,依赖越多、断言面越宽。-| 编号 | 文件 | 被测对象 | 主层级 | 对应批次 |-| --- | --- | --- | --- | --- |-| 00 | `00-overview.md` | 总览、前置、追踪矩阵 | — | — |-| 01 | `01-dsh-host-and-core-contract.md` | 编排骨架(scratch 宿主 + 挂载 + 随机端口)与共享路由契约(OPTIONS/405/403/413) | L2 | 批次 1–2 |-| 02 | `02-dsh-tauri-pet.md` | 桌宠插件(SSE → 客户端挂载 → 桌面端窗口) | L2 → L3 | 批次 3 |-| 03 | `03-dsh-tauri-rightclick.md` | 右键菜单与外部打开 | L2 → L3 | 批次 4+ |-| 04 | `04-dsh-tauri-session.md` | 会话归档与打开目录 | L2 → L3 | 批次 4+ |-| 05 | `05-dsh-tauri-worktree.md` | 工作树面板与路由 | L2 → L3 | 批次 4+ |-| 06 | `06-dsh-tauri-ui.md` | 壳层槽位注入(导航/侧栏/设置) | L2 → L3 | 批次 4+ |-| 07 | `07-dsh-tauri-panel-extension.md` | 扩展管理面板(技能 / MCP / 市场) | L2 → L3 | 批次 4+ |-| 08 | `08-dsh-tauri-panel-scheduler.md` | 定时任务面板 | L2 → L3 | 批次 4+ |-| 09 | `09-dsh-tauri-turnrewind.md` | 回合级变更记录 | L2 → L3 | 批次 4+ |-| 10 | `10-dsh-tauri-model-config.md` | 模型配置 | L2 → L3 | 批次 4+ |+| 编号 | 文件 | 测试文件(同名同序号) | 被测对象 | 主层级 | 对应批次 |+| --- | --- | --- | --- | --- | --- |+| 00 | `00-overview.md` | —(总览不承载用例) | 总览、前置、追踪矩阵 | — | — |+| 01 | `01-dsh-host-and-core-contract.md` | `01-dsh-host-and-core-contract.e2e.ts` | 编排骨架(scratch 宿主 + 挂载 + 随机端口)与共享路由契约(OPTIONS/405/403/413) | L2 | 批次 1–2 |+| 02 | `02-dsh-tauri-pet.md` | `02-dsh-tauri-pet.e2e.ts` | 桌宠插件(SSE → 客户端挂载 → 桌面端窗口) | L2 → L3 | 批次 3 |+| 03 | `03-dsh-tauri-rightclick.md` | `03-dsh-tauri-rightclick.e2e.ts` | 右键菜单与外部打开 | L2 → L3 | 批次 4+ |+| 04 | `04-dsh-tauri-session.md` | `04-dsh-tauri-session.e2e.ts` | 会话归档与打开目录 | L2 → L3 | 批次 4+ |+| 05 | `05-dsh-tauri-worktree.md` | `05-dsh-tauri-worktree.e2e.ts` | 工作树面板与路由 | L2 → L3 | 批次 4+ |+| 06 | `06-dsh-tauri-ui.md` | `06-dsh-tauri-ui.e2e.ts` | 壳层槽位注入(导航/侧栏/设置) | L2 → L3 | 批次 4+ |+| 07 | `07-dsh-tauri-panel-extension.md` | `07-dsh-tauri-panel-extension.e2e.ts` | 扩展管理面板(技能 / MCP / 市场) | L2 → L3 | 批次 4+ |+| 08 | `08-dsh-tauri-panel-scheduler.md` | `08-dsh-tauri-panel-scheduler.e2e.ts` | 定时任务面板 | L2 → L3 | 批次 4+ |+| 09 | `09-dsh-tauri-turnrewind.md` | `09-dsh-tauri-turnrewind.e2e.ts` | 回合级变更记录 | L2 → L3 | 批次 4+ |+| 10 | `10-dsh-tauri-model-config.md` | `10-dsh-tauri-model-config.e2e.ts` | 模型配置 | L2 → L3 | 批次 4+ |> `dsh-tauri-bundle`、`dsh-tauri-tsdown` 是打包/构建工具包(无 `exports["./client"]`,见各自 `package.json`),不属于产品可见插件,不在本套用例范围。@@ -86,15 +87,18 @@| 项 | 值 | 来源 || --- | --- | --- |-| 构建前置 | `pnpm build:plugins`(**当前 `packages/*/dist` 均不存在**) | `test/e2e/support/dsh-host.ts:127` |-| 入口解析 | `DSH_E2E_DSH_BIN` → PATH → 桌面端装配目录 | `test/e2e/support/dsh-host.ts:83` |-| Node 入口 | `DSH_E2E_NODE_BIN`(默认 `process.execPath`) | `test/e2e/support/dsh-host.ts:106` |-| 目标插件 | `DSH_E2E_PLUGIN`(默认 `dsh-tauri-pet`) | `test/e2e/global-setup.ts:29` |-| 附加挂载 | `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 plugin`) | `package.json:21` |-| 隔离 | 每次运行独占 `<tmp>/dsh-e2e-<plugin>-<时间戳>`,不触碰用户真实 `DSH_HOME` | `test/e2e/support/dsh-host.ts:313` |+| 构建前置 | `pnpm build:plugins`(除 `dsh-tauri-bundle` / `dsh-tauri-tsdown` 外,`packages/*/dist` 均已产出) | `test/e2e/support/dsh-host.ts:164` |+| 入口解析 | `DSH_E2E_DSH_BIN` → 仓库依赖树 → 桌面端装配目录 | `test/e2e/support/dsh-host.ts:134` |+| Node 入口 | `DSH_E2E_NODE_BIN`(默认 `process.execPath`) | `test/e2e/support/dsh-host.ts:92` |+| 目标插件 | `DSH_E2E_PLUGIN`(默认 `dsh-tauri-pet`) | `test/e2e/global-setup.ts:34` |+| 附加挂载 | `DSH_E2E_ALSO`(逗号分隔) | `test/e2e/global-setup.ts:35` |+| 挂载模式 | `DSH_E2E_MOUNT=link`(默认)/ `cli` | `test/e2e/support/dsh-host.ts:404` |+| 保留现场 | `DSH_E2E_KEEP_HOME=1` | `test/e2e/global-setup.ts:36` |+| 运行 | `pnpm test:e2e:plugin`(= `vitest --project plugin`) | `package.json:22` |+| 隔离 | 每次运行独占 `<tmp>/dsh-e2e-<plugin>-<时间戳>`,不触碰用户真实 `DSH_HOME` | `test/e2e/support/dsh-host.ts:396` |+| 用例归属 | `test/e2e/plugins/<序号>-<主题>.e2e.ts`(`fileParallelism: false`) | `vitest.plugin.config.ts:15` |++> 环境变量只影响 `globalSetup` 起的那一个共享宿主。自带宿主的用例(如 `01` 的编排骨架段与共享契约段)在进程内直接传参,不受这些变量左右。---@@ -155,21 +159,23 @@| 编号 | 类型 | 内容 | 影响 || --- | --- | --- | --- |-| G1 | 事实 | `packages/*/dist` **全部不存在**,`assertBuilt` 会先失败 | L2 用例在 `pnpm build:plugins` 之前一律不可运行 |+| G1 | ~~事实~~ 已消解 | `packages/*/dist` 现已全部产出(仅 `dsh-tauri-bundle` / `dsh-tauri-tsdown` 无产物,且被 `build:plugins` 显式排除,已作为「未构建」夹具) | 不再阻塞 L2 || G2 | 缺口 | `playwright` 未出现在 `package.json` / `pnpm-lock.yaml` / `node_modules`,与 `plugin.test.md` §3.2 的 L2 浏览器方案冲突 | 客户端渲染类用例(全部 `-C-*`)只能给出设计,标记「未接线」 |-| G3 | 缺口 | 壳层(`src/`)`data-testid` 数量为 **0**,且 `test/e2e/support/selectors.ts` 不存在,而 `desktop.test.md` §5 要求 E2E 必须用 `data-testid` | 所有 L3 用例需先随用例补 `data-testid`;当前 L3 选择器暂用 `aria-label` / slot id / 插件前缀 class |-| G4 | 缺口 | `desktop` project 尚未配置(无 `vitest.desktop.config.ts`、无 `test:e2e:desktop` 脚本、`test/e2e/specs/` 不存在) | L3 用例标注 `[自动化] 待接线`,不得写成可直接运行的 `it()` |+| G3 | 缺口 | 壳层(`src/`)`data-testid` 数量为 **0**,而 `desktop.test.md` §5 要求 E2E 必须用 `data-testid` | 所有 L3 用例需先随用例补 `data-testid`;`test/e2e/support/selectors.ts` 已建立,新选择器须登记其中 |+| G4 | ~~缺口~~ 已消解 | `desktop` project 已配置(`vitest.desktop.config.ts`、`test:e2e:desktop` 脚本、`test/e2e/desktop/boot.e2e.ts` 均已落地) | L3 用例可写成可直接运行的 `it()` || G5 | 冲突 | `desktop.test.md` §6 称 debug 端口固定 `3081` 不可改;实现存在占用递增逻辑 | 全部 L3 用例的端口前置按「实测空闲」执行,不假设端口恒定 || G6 | 事实 | 插件 client 入口仅在内嵌 frame 内生效(`window.parent !== window`) | 所有 `-C-*` 与 `-L3-*` 用例必须构造 iframe 环境;顶层页面断言槽位必然失败 |-| G7 | 假设 | 各插件可被单独挂载(`DSH_E2E_PLUGIN=<pkg>`);需要核心桥时通过 `DSH_E2E_ALSO=dsh-tauri` 一并挂载 | 若某插件强依赖其它插件,需在其文件中追加 `also` 说明 |+| G7 | 假设 | 各插件可被单独挂载(`startDshHost({ plugin })`);需要核心桥时通过 `also: ['dsh-tauri']` 一并挂载 | 若某插件强依赖其它插件,需在其文件中追加 `also` 说明 || G8 | 缺口 | `test/e2e/.artifacts/` 仅有文档约定与 `.gitignore`,无实现 | 失败产物(截图 / stdout)需在接线时补齐,否则失败定位只能依赖日志 || G9 | 缺口 | 会话类用例(`09` turnrewind、`06` ui 的部分分支)需要真实会话,scratch 宿主当前无造会话手段 | 相关用例标记「待补」,是本套文档最大的功能盲区 |+| G10 | 事实 | 路由层的跨源 403(`routes/index.ts:287`,`cross-origin-request`)在真实宿主里被上游 Host/Origin 围栏遮蔽,L2 不可达 | 该类断言只能落在 L1(`packages/dsh-tauri/src/host/routes/index.test.ts:240`);L2 按可观察事实断言 `forbidden` |---## 9. 维护规则1. 每条用例条目与测试代码 `it()` **1:1 对应**;改文档必改代码,反之亦然(`plugin.test.md` §4)。-2. 状态变更实时登记到 `docs/testing/progressive.md` §4.2 台账,禁止滞后补记。-3. 新增 L3 用例必须同步补 `data-testid`,并登记到 `test/e2e/support/selectors.ts`(`desktop.test.md` §5)。-4. 单文件即单批次,未验证通过前不得推进到下一个编号。\ No newline at end of file+2. 测试文件与用例文档**同名同序号**(`<序号>-<主题>.e2e.ts` ↔ `<序号>-<主题>.md`);一个批次只允许一个测试文件,批内多段用 `describe` 分区。+3. 状态变更实时登记到 `docs/testing/progressive.md` §4.2 台账,禁止滞后补记。+4. 新增 L3 用例必须同步补 `data-testid`,并登记到 `test/e2e/support/selectors.ts`(`desktop.test.md` §5)。+5. 单文件即单批次,未验证通过前不得推进到下一个编号。\ No newline at end of filediff --git a/docs/testing/plugins/01-dsh-host-and-core-contract.md b/docs/testing/plugins/01-dsh-host-and-core-contract.mdindex 6df136d1..0ac38447 100644--- a/docs/testing/plugins/01-dsh-host-and-core-contract.md+++ b/docs/testing/plugins/01-dsh-host-and-core-contract.md@@ -1,7 +1,7 @@# 编排骨架与共享路由契约(批次 01):真实 dsh 宿主 + 所有插件路由的唯一收敛点> 层级:L2 插件宿主 E2E(真实 `dsh web` 进程;无浏览器、无 Tauri)-> 自动化:`test/e2e/plugins/host-lane.e2e.ts`、`test/e2e/plugins/routes-contract.e2e.ts`(待建立;本文件是二者的用例来源)+> 自动化:`test/e2e/plugins/01-dsh-host-and-core-contract.e2e.ts`(编排骨架 6 例 + 共享路由契约 6 例,共 12 个 `it()`)> 前置:`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 plugin`)@@ -20,21 +20,21 @@| 行为 | 代码位置 || --- | --- |-| `startDshHost({ plugin, also, keepHome })` 一行起宿主 | `test/e2e/support/dsh-host.ts:307` |-| scratch 目录:`<tmp>/dsh-e2e-<plugin>-<base36 时间戳>` | `test/e2e/support/dsh-host.ts:313` |-| profile 三件套(`package.json` / `cordis.patch.yml` / `pnpm-workspace.yaml`) | `test/e2e/support/dsh-host.ts:149` |-| 默认 bundle 列表=`dsh-base` + `dsh-web-app` + 目标包 | `test/e2e/support/dsh-host.ts:316` |-| link 挂载(junction / dir symlink,离线)或 cli 挂载(`dsh plugin add`) | `test/e2e/support/dsh-host.ts:179`、`test/e2e/support/dsh-host.ts:237` |-| 挂载后必须出现在 `dsh.profile.bundles`,否则抛错 | `test/e2e/support/dsh-host.ts:335` |-| 产物预检:`main` 与 `exports["./client"]` 指向的文件必须存在 | `test/e2e/support/dsh-host.ts:127` |-| 核心解析:`DSH_E2E_DSH_BIN` → 仓库依赖树 → 桌面端装配目录,皆无则抛错 | `test/e2e/support/dsh-host.ts:121`、`test/e2e/support/dsh-host.ts:42` |-| 启动命令:`dsh web --host 127.0.0.1 --port 0 --no-open`(不带 `--skip-auth`) | `test/e2e/support/dsh-host.ts:392` |-| 鉴权交换:根路径 token → `redirect:'manual'` 断言 303 + `Set-Cookie`,取 `name=value` | `test/e2e/support/dsh-host.ts:96` |-| 就绪判定:从日志抓 `http://127.0.0.1:<port>...` 首个匹配 | `test/e2e/support/dsh-host.ts:36`、`test/e2e/support/dsh-host.ts:274` |-| 就绪上限 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` |+| `startDshHost({ plugin, also, keepHome })` 一行起宿主 | `test/e2e/support/dsh-host.ts:389` |+| scratch 目录:`<tmp>/dsh-e2e-<plugin>-<base36 时间戳>` | `test/e2e/support/dsh-host.ts:396` |+| profile 三件套(`package.json` / `cordis.patch.yml` / `pnpm-workspace.yaml`) | `test/e2e/support/dsh-host.ts:190` |+| 默认 bundle 列表=`dsh-base` + `dsh-web-app` + 目标包 | `test/e2e/support/dsh-host.ts:399` |+| link 挂载(junction / dir symlink,离线)或 cli 挂载(`dsh plugin add`) | `test/e2e/support/dsh-host.ts:221`、`test/e2e/support/dsh-host.ts:304` |+| 挂载后必须出现在 `dsh.profile.bundles`,否则抛错 | `test/e2e/support/dsh-host.ts:273` |+| 产物预检:`main` 与 `exports["./client"]` 指向的文件必须存在 | `test/e2e/support/dsh-host.ts:164` |+| 核心解析:`DSH_E2E_DSH_BIN` → 仓库依赖树 → 桌面端装配目录,皆无则抛错 | `test/e2e/support/dsh-host.ts:134`、`test/e2e/support/dsh-host.ts:43` |+| 启动命令:`dsh web --host 127.0.0.1 --port 0 --no-open`(不带 `--skip-auth`) | `test/e2e/support/dsh-host.ts:425` |+| 鉴权交换:根路径 token → `redirect:'manual'` 断言 303 + `Set-Cookie`,取 `name=value` | `test/e2e/support/dsh-host.ts:359` |+| 就绪判定:从日志抓 `http://127.0.0.1:<port>...` 首个匹配 | `test/e2e/support/dsh-host.ts:37`、`test/e2e/support/dsh-host.ts:341` |+| 就绪上限 120s | `test/e2e/support/dsh-host.ts:40` |+| 收尾:Windows `taskkill /T /F`;其余 SIGTERM→SIGKILL | `test/e2e/support/dsh-host.ts:321`、`test/e2e/support/dsh-host.ts:442` || 地址下传:`project.provide('dshBaseUrl' / 'dshUrl' / 'dshCookie' / 'dshHome' / 'dshMounted')` | `test/e2e/global-setup.ts:38` |-| project 归属:`packages/*/test/**/*.e2e.ts`,`fileParallelism: false`,超时 120s | `vitest.plugin.config.ts:15`、`vitest.plugin.config.ts:18` |+| project 归属:`test/e2e/plugins/**/*.e2e.ts`,`fileParallelism: false`,超时 120s | `vitest.plugin.config.ts:15`、`vitest.plugin.config.ts:18` |### 1.2 共享路由契约(`packages/dsh-tauri/src/host/routes/index.ts`)@@ -65,10 +65,10 @@[Case ID] TC-HOST-L2-01-001[层级] L2(真实 dsh 进程)[类型] 正向-[追踪] `docs/specs/plugin.test.md` §8 批次 1;`test/e2e/support/dsh-host.ts:307`-[自动化] 否(待建立 `test/e2e/plugins/host-lane.e2e.ts`)-[前置条件] `pnpm build:plugins` 已执行;`DSH_E2E_PLUGIN`(默认 `dsh-tauri-pet`)指向的包已构建;系统临时目录可写;dsh 核心可解析(`DSH_E2E_DSH_BIN`、仓库依赖树或桌面端装配目录任一命中)-[测试数据] `DSH_E2E_PLUGIN=dsh-tauri`;`DSH_E2E_MOUNT=link`(默认)+[追踪] `docs/specs/plugin.test.md` §8 批次 1;`test/e2e/support/dsh-host.ts:389`+[自动化] 是(`01-dsh-host-and-core-contract.e2e.ts` → `describe('编排骨架')`)+[前置条件] `pnpm build:plugins` 已执行(`dsh-tauri` 的 `dist` 与 `dist/client.cjs` 都在);系统临时目录可写;dsh 核心可解析(`DSH_E2E_DSH_BIN`、仓库依赖树或桌面端装配目录任一命中)+[测试数据] `startDshHost({ plugin: 'dsh-tauri' })`;`DSH_E2E_MOUNT` 不设置(走默认 `link`)[测试步骤] 1. 调用 `startDshHost({ plugin: 'dsh-tauri' })`。2. 读返回的 `url` / `baseUrl` / `cookie` / `home` / `mounted`。3. 带 `cookie` 对 `baseUrl` 发起 `GET /`。4. 读 `home/dsh-web.log` 末尾内容。[预期结果] 1. `startDshHost` 在 120s 内 resolve,不抛错。2. `baseUrl` 形如 `http://127.0.0.1:<非 0 端口>`;`cookie` 非空;`mounted` 精确包含 `dsh-tauri`;`home` 路径包含 `dsh-e2e-dsh-tauri-`。3. `GET /` 返回 2xx 且响应体非空。4. 日志内出现与 `url` 一致的就绪行,且未出现 `ERR_MODULE_NOT_FOUND`。[清理] 用例结束(含失败)必须调用 `stop()`;断言 `home` 目录已被删除@@ -78,12 +78,12 @@[Case ID] TC-HOST-L2-01-002[层级] L2(真实 dsh 进程)[类型] 正向-[追踪] `test/e2e/support/dsh-host.ts:316`、`test/e2e/support/dsh-host.ts:199`-[自动化] 是(同上文件)+[追踪] `test/e2e/support/dsh-host.ts:399`、`test/e2e/support/dsh-host.ts:221`+[自动化] 是(同上文件 → `describe('编排骨架')`)[前置条件] 同 TC-HOST-L2-01-001;未设置 `DSH_E2E_KEEP_HOME`-[测试数据] `DSH_E2E_PLUGIN=dsh-tauri`;`DSH_E2E_ALSO=dsh-tauri-pet`(制造「基础包 + 目标包」两段挂载)-[测试步骤] 1. 用上述环境启动宿主。2. 读 `home/profiles/web/package.json`。3. 取 `dsh.profile.bundles` 与 `dependencies`。-[预期结果] 1. 启动成功。2. `bundles` 同时包含 `dsh-tauri-pet` 与 `dsh-tauri`,且无重复项。3. `dependencies` 中两者的值均以 `link:` 开头并指向仓库 `packages/<name>`。+[测试数据] `startDshHost({ plugin: 'dsh-tauri', also: ['dsh-tauri-pet'] })`(制造「目标包 + 附加包」两段挂载)+[测试步骤] 1. 用上述参数启动宿主。2. 读 `home/profiles/web/package.json`。3. 取 `dsh.profile.bundles` 与 `dependencies`。4. 解引用 `home/profiles/web/node_modules/<name>` 链接。+[预期结果] 1. 启动成功。2. `bundles` 同时包含 `dsh-tauri-pet` 与 `dsh-tauri`,且无重复项。3. `dependencies` 中两者的值均以 `link:` 开头并指向仓库 `packages/<name>`。4. 两条链接的 realpath 都落在仓库包目录上(规格写对 ≠ 挂得上)。[清理] 同 TC-HOST-L2-01-001#### [P3] [反向] 验证挂载未登记进 bundles 时立刻失败,而不是带着半成品起服务@@ -91,37 +91,38 @@[Case ID] TC-HOST-L2-01-003[层级] L2(真实 dsh 进程)[类型] 异常-[追踪] `test/e2e/support/dsh-host.ts:335`-[自动化] 是(同上文件;用桩 profile 触发)-[前置条件] 手工构造只写了 `package.json` 与链接、但 `dsh.profile.bundles` 缺目标包的 profile;或直接调用内部校验分支-[测试数据] `bundles` 故意缺 `dsh-tauri-pet`-[测试步骤] 1. 以被篡改的 profile 触发挂载校验。2. 捕获抛出的错误文本。3. 检查 scratch 目录是否残留。-[预期结果] 1. 抛错,且错误文本包含 `挂载未注册到 dsh.profile.bundles` 与缺失包名。2. 不产生 `dsh web` 子进程(无就绪 URL)。3. scratch 目录被清理(`dsh-host.ts:340` 的 catch 分支)。-[清理] 无需额外清理+[追踪] `test/e2e/support/dsh-host.ts:273`+[自动化] 是(同上文件 → `describe('编排骨架')`)+[前置条件] 手工构造一份只登记了 `dsh-tauri-pet` 的 profile `package.json`;直接调用编排导出的校验分支 `assertMountRegistered`+[测试数据] `bundles` 故意缺 `dsh-tauri`+[测试步骤] 1. 以被篡改的 profile 触发挂载校验(一次只请求已登记的包,一次同时请求已登记与未登记的包)。2. 捕获抛出的错误文本。+[预期结果] 1. 请求已登记的包不抛错(正向对照,避免断言变成恒真)。2. 请求含未登记的包时抛错,且错误文本恰为 `挂载未注册到 dsh.profile.bundles:dsh-tauri`——只列出缺失的那个。+[清理] 删除夹具 profile 目录+[未覆盖] 「失败后 scratch 目录被清理」在此分支不可达:link 模式下 bundles 由 `addBundle` 自己写入,该分支恒不触发,故造不出「挂载失败后清理」的场景;而 `assertBuilt` 的失败发生在 `home` 创建之前,本就不涉及清理。清理契约由 TC-HOST-L2-01-001 与 TC-HOST-L2-01-005 覆盖。#### [P3] [反向] 验证产物缺失时报出可操作的构建指引[Case ID] TC-HOST-L2-01-004[层级] L2(真实 dsh 进程)[类型] 异常-[追踪] `test/e2e/support/dsh-host.ts:127`-[自动化] 是(同上文件;以未构建的包触发)-[前置条件] 选定一个 `packages/<name>/dist/index.js` 不存在的包(或临时重命名产物)-[测试数据] 未构建的包名,例如 `dsh-tauri-panel-scheduler`-[测试步骤] 1. 对其调用 `startDshHost`。2. 捕获错误文本。-[预期结果] 1. 抛错,文本包含「尚未构建」与 `pnpm build:plugins` 指引。2. 不进入 `dsh web` 启动阶段(无日志文件产生或日志为空)。-[清理] 恢复被重命名的产物+[追踪] `test/e2e/support/dsh-host.ts:164`+[自动化] 是(同上文件 → `describe('编排骨架')`)+[前置条件] `packages/dsh-tauri-tsdown` 保持源码即产物(无 `main`、无 `dist`,且被 `build:plugins` 的 `--filter !dsh-tauri-tsdown` 显式排除)+[测试数据] `startDshHost({ plugin: 'dsh-tauri-tsdown' })`+[测试步骤] 1. 对其调用 `startDshHost`。2. 捕获错误文本。3. 对比调用前后临时目录中 `dsh-e2e-dsh-tauri-tsdown-*` 的集合。+[预期结果] 1. 抛错,文本同时含「尚未构建」与 `pnpm build:plugins` 指引。2. 不进入 `dsh web` 启动阶段:临时目录中不出现该 plugin 的 scratch 目录(即无日志文件产生)。+[清理] 无(不移动、不改写任何产物)#### [P4] 验证环境变量边界:`DSH_E2E_KEEP_HOME` 控制 scratch 去留[Case ID] TC-HOST-L2-01-005[层级] L2(真实 dsh 进程)[类型] 边界-[追踪] `test/e2e/support/dsh-host.ts:376`、`test/e2e/global-setup.ts:31`-[自动化] 是(同上文件)+[追踪] `test/e2e/support/dsh-host.ts:389`、`test/e2e/support/dsh-host.ts:442`+[自动化] 是(同上文件 → `describe('编排骨架')`)[前置条件] 可重复启动宿主两次(串行,`fileParallelism` 已为 false)-[测试数据] 第一轮不设 `DSH_E2E_KEEP_HOME`;第二轮设 `DSH_E2E_KEEP_HOME=1`-[测试步骤] 1. 第一轮启动后 `stop()`,检查 `home` 是否存在。2. 第二轮启动后 `stop()`,检查 `home` 是否存在。3. 手工删除第二轮目录。+[测试数据] 第一轮 `startDshHost({ plugin: 'dsh-tauri-pet' })`;第二轮同参数加 `keepHome: true`(即 globalSetup 在 `DSH_E2E_KEEP_HOME=1` 时传入的取值)+[测试步骤] 1. 第一轮启动后 `stop()`,检查 `home` 是否存在。2. 第二轮启动后 `stop()`,检查 `home` 与 `dsh-web.log`。3. 手工删除第二轮目录。[预期结果] 1. 第一轮 `home` 目录不存在(已清理)。2. 第二轮 `home` 目录仍存在,且 `dsh-web.log` 可读。3. 删除成功,无残留锁文件。[清理] 删除第二轮 scratch 目录@@ -130,12 +131,12 @@[Case ID] TC-HOST-L2-01-006[层级] L2(真实 dsh 进程)[类型] 回归-[追踪] `test/e2e/support/dsh-host.ts:237`、`docs/specs/plugin.test.md` §5-[自动化] 是(同上文件)-[前置条件] 机器可联网、`pnpm` 可用;`DSH_E2E_PNPM_STORE_DIR` 可选指向本地 store-[测试数据] `DSH_E2E_MOUNT=cli`;`DSH_E2E_PLUGIN=dsh-tauri`+[追踪] `test/e2e/support/dsh-host.ts:304`、`docs/specs/plugin.test.md` §5+[自动化] 是(同上文件 → `describe('编排骨架')`)+[前置条件] `pnpm` 在 PATH 上(`dsh plugin add` 是 pnpm 的薄转发,`link:` 规格不解析被链接包自身的 `catalog:` 依赖,故无需 registry 元数据);`DSH_E2E_PNPM_STORE_DIR` 可选指向本地 store+[测试数据] 进程内设 `DSH_E2E_MOUNT=cli`;`startDshHost({ plugin: 'dsh-tauri' })`;结束后恢复该环境变量[测试步骤] 1. 以 cli 模式启动宿主。2. 读 `home/profiles/web/package.json`。3. 对 `baseUrl` 发起 `GET /`。-[预期结果] 1. 启动成功(允许明显长于 link 模式)。2. `dependencies` 由 `dsh plugin add` 写入,值指向仓库包路径而非自建链接。3. `GET /` 返回 2xx。+[预期结果] 1. 启动成功(允许明显长于 link 模式)。2. `dependencies` 由 `dsh plugin add` 写入,值为 `link:` 规格并指向仓库 `packages/dsh-tauri`(不是自建链接)。3. `GET /` 返回 2xx。[清理] 同 TC-HOST-L2-01-001### 2.2 共享路由契约(`TC-CORE-L2-01-*`)@@ -146,11 +147,11 @@[层级] L2(真实 dsh 进程)[类型] 正向[追踪] `packages/dsh-tauri/src/host/routes/index.ts:270`-[自动化] 是(`test/e2e/plugins/routes-contract.e2e.ts`)-[前置条件] 宿主已挂载 `dsh-tauri-pet`(提供代表路由);`DSH_E2E_MOUNT=link`;本批所有请求均须带 `startDshHost()` 换回的会话 Cookie(`inject('dshCookie')`),否则 `/api` 一律 401,断言会把鉴权失败误读成路由契约失败-[测试数据] `DSH_E2E_PLUGIN=dsh-tauri`;`DSH_E2E_ALSO=dsh-tauri-pet`+[自动化] 是(`01-dsh-host-and-core-contract.e2e.ts` → `describe('共享路由契约')`)+[前置条件] 该段在 `beforeAll` 自带宿主:`startDshHost({ plugin: 'dsh-tauri-pet', also: ['dsh-tauri-rightclick'] })`(GET 代表路由 + POST 代表路由);`DSH_E2E_MOUNT=link`;本段所有请求均须带该宿主换回的会话 Cookie,否则 `/api` 一律 401,断言会把鉴权失败误读成路由契约失败+[测试数据] 对 `GET_ONLY_PATH` 发 `OPTIONS`[测试步骤] 1. 对代表路由发起 `OPTIONS`(不带 body)。2. 读状态码与 `allow` 头。-[预期结果] 1. 状态码 204,响应体长度为 0。2. `allow` 头存在,且同时包含 `GET` 与 `OPTIONS`;因为 GET 隐含允许 HEAD,`allow` 中还应包含 `HEAD`。+[预期结果] 1. 状态码 204,响应体长度为 0。2. `allow` 头存在,按集合比较恰为 `{GET, HEAD, OPTIONS}`(`OPTIONS` 是默认预检,`HEAD` 由 GET 隐含)。[清理] 无#### [P2] 验证只声明 GET 的路径接受 HEAD 而不被判 405@@ -159,22 +160,22 @@[层级] L2(真实 dsh 进程)[类型] 正向[追踪] `packages/dsh-tauri/src/host/routes/index.ts:255`-[自动化] 是(同上文件)+[自动化] 是(同上文件 → `describe('共享路由契约')`)[前置条件] 同 TC-CORE-L2-01-001[测试数据] 同一代表路由[测试步骤] 1. 对代表路由发起 `HEAD`。2. 读状态码。-[预期结果] 1. 状态码**不是** 405(GET 隐含 HEAD 的规则生效)。2. 若因 SSE 长连接导致 200 后挂起,用例在读取响应头后立即中止连接,不等待 body。-[清理] 中止连接+[预期结果] 1. 状态码 200——既不是 405(GET 隐含 HEAD 的规则生效),也说明确实命中了真实 handler。2. SSE 长连接不会阻塞 HEAD:用例在读完响应头后立即 `abort()`,不等待 body。+[清理] `abort()` 中止连接#### [P3] [反向] 验证未声明的方法返回 405 且给出可用的 allow[Case ID] TC-CORE-L2-01-003[层级] L2(真实 dsh 进程)[类型] 异常-[追踪] `packages/dsh-tauri/src/host/routes/index.ts:275`-[自动化] 是(同上文件)+[追踪] `packages/dsh-tauri/src/host/routes/index.ts:276`+[自动化] 是(同上文件 → `describe('共享路由契约')`)[前置条件] 同 TC-CORE-L2-01-001-[测试数据] 对只声明 GET 的代表路由发 `POST`(body `{}`,`content-type: application/json`)+[测试数据] 对 `GET_ONLY_PATH` 发 `POST`(body `{}`,`content-type: application/json`)[测试步骤] 1. 发起请求。2. 读状态码、`allow` 头、响应体 JSON。[预期结果] 1. 状态码 405。2. `allow` 头包含 `GET`。3. 响应体 `error` 字段以 `仅支持 ` 开头且包含 `GET`。[清理] 无@@ -184,13 +185,14 @@[Case ID] TC-CORE-L2-01-004[层级] L2(真实 dsh 进程)[类型] 异常-[追踪] `packages/dsh-tauri/src/host/routes/index.ts:286`-[自动化] 是(同上文件)+[追踪] `packages/dsh-tauri/src/host/routes/index.ts:287`(**在 L2 被上游围栏遮蔽,见下**)+[自动化] 是(同上文件 → `describe('共享路由契约')`)[前置条件] 同 TC-CORE-L2-01-001;代表路由改为只声明 POST 的 `/api/desktop/dsh-tauri-rightclick/open/url`[测试数据] 请求头 `Origin: http://evil.example`;`content-type: application/json`;body `{}`-[测试步骤] 1. 发起请求。2. 读状态码与响应体。-[预期结果] 1. 状态码 403。2. 响应体 `error` 恰为 `cross-origin-request`。3. 宿主日志中不出现该插件 handler 的执行痕迹(拒绝发生在路由层)。+[测试步骤] 1. 发起请求。2. 读状态码与响应体 JSON。+[预期结果] 1. 状态码 403。2. 响应体 `error` 恰为 `forbidden`(连接门词汇),**不是** `cross-origin-request`。3. 响应体里不出现 handler 的成功载荷 `{"ok":true}`——拒绝发生在任何插件 handler 之前。[清理] 无+[已定论 · 期望值修正] 本条原写「`error` 恰为 `cross-origin-request`」,实测不成立:dsh 0.1.5-rc.2 的 `@deepseek-ai/dsh-client-connection` 先做 Host/Origin 围栏(`HostConnectionService.requestRejection` → `isTrustedApiRequest`,Origin 的 host 与请求 Host 不一致即返回 403),编排层的 `createHostHandler` 再把该 403 渲染成 `{ error: 'forbidden' }`。因此 `routes/index.ts:287` 的 `cross-origin-request` 分支在真实宿主里是**不可达的纵深防御**,L2 只能观察到连接门的 403。该分支由 L1 覆盖:`packages/dsh-tauri/src/host/routes/index.test.ts:240`(`it('变更操作拒绝跨源 Origin(CSRF / DNS rebinding),无 Origin 的非浏览器调用方放行')`,`:254` 断言 `cross-origin-request`)。#### [P4] [反向] 验证超过 1 MiB 的请求体被 413 终止@@ -198,11 +200,11 @@[层级] L2(真实 dsh 进程)[类型] 边界[追踪] `packages/dsh-tauri/src/host/routes/index.ts:128`、`packages/dsh-tauri/src/host/config/constants.ts:13`-[自动化] 是(同上文件)+[自动化] 是(同上文件 → `describe('共享路由契约')`)[前置条件] 同 TC-CORE-L2-01-001;使用只声明 POST 的代表路由[测试数据] body 为 `1 MiB + 1 字节` 的 JSON(`{"pad":"<填充>"}`)-[测试步骤] 1. 发起 `POST`,`content-type: application/json`。2. 读状态码。-[预期结果] 1. 状态码 413。2. 用例不因连接被中断而抛未处理异常(读取响应前先容错)。+[测试步骤] 1. 发起 `POST`,`content-type: application/json`。2. 读状态码与响应体。+[预期结果] 1. 状态码 413。2. 响应体含上限字节数 `1048576`(与 `MAX_REQUEST_BODY_BYTES` 对齐)。3. 若连接被中断,用例把它转成带说明的断言失败,而不是抛出未处理异常。[清理] 无#### [P2] [反向] 验证未挂载插件的路径返回 404,用于区分「没挂载」与「没鉴权」@@ -211,8 +213,8 @@[层级] L2(真实 dsh 进程)[类型] 异常[追踪] `docs/specs/plugin.test.md` §5 鉴权说明(Cookie 交换下 401 与 404 的区分)-[自动化] 是(同上文件)-[前置条件] 宿主**未**挂载 `dsh-tauri-turnrewind`;请求带会话 Cookie+[自动化] 是(同上文件 → `describe('共享路由契约')`)+[前置条件] 该段宿主**未**挂载 `dsh-tauri-turnrewind`;请求带会话 Cookie[测试数据] `GET /api/desktop/dsh-tauri-turnrewind/summary?sessionId=x`[测试步骤] 1. 发起请求。2. 读状态码。[预期结果] 1. 状态码 404(既不是 401 也不是 200)。2. 该结果与「挂载后同路径返回 200/4xx 业务码」形成对照,证明失败来自路由缺失而非鉴权围栏。@@ -227,19 +229,19 @@| 来源 | 覆盖 Case ID | 覆盖类型 | 缺口备注 || --- | --- | --- | --- || `docs/specs/plugin.test.md` §8 批次 1(骨架挂载 + 随机端口) | TC-HOST-L2-01-001、TC-HOST-L2-01-002 | 正向 | 未覆盖「随机端口是否真的每次不同」 |-| `docs/specs/plugin.test.md` §5 步骤 5(挂载校验) | TC-HOST-L2-01-003 | 异常 | 依赖内部校验分支的可触达性,可能需抽函数后才可测 |-| `docs/specs/plugin.test.md` §5 步骤 1(构建产物) | TC-HOST-L2-01-004 | 异常 | 会短暂移动产物,串行执行下安全 |-| `docs/specs/plugin.test.md` §9(`DSH_E2E_KEEP_HOME`) | TC-HOST-L2-01-005 | 边界 | 依赖可重复启动宿主 |-| `docs/specs/plugin.test.md` §5 挂载模式 `link`/`cli` | TC-HOST-L2-01-006 | 回归 | cli 模式需网络,不作为门禁必跑 |+| `docs/specs/plugin.test.md` §5 步骤 5(挂载校验) | TC-HOST-L2-01-003 | 异常 | 该分支在 link 模式下恒不触发,故直接调用导出的 `assertMountRegistered`;「失败后 scratch 清理」随之不可达,改由 001/005 覆盖 |+| `docs/specs/plugin.test.md` §5 步骤 1(构建产物) | TC-HOST-L2-01-004 | 异常 | 以「源码即产物」的 `dsh-tauri-tsdown` 触发,不移动、不改写任何产物 |+| `docs/specs/plugin.test.md` §9(`DSH_E2E_KEEP_HOME`) | TC-HOST-L2-01-005 | 边界 | 依赖可重复启动宿主(串行) |+| `docs/specs/plugin.test.md` §5 挂载模式 `link`/`cli` | TC-HOST-L2-01-006 | 回归 | `dsh plugin add` 是 pnpm 薄转发;`link:` 规格不解析被链接包自身的 `catalog:` 依赖,故不依赖 registry |### 3.2 共享路由契约| 来源 | 覆盖 Case ID | 覆盖类型 | 缺口备注 || --- | --- | --- | --- |-| `dsh-tauri` 路由契约:OPTIONS 204 | TC-CORE-L2-01-001 | 正向 | — |-| 路由契约:GET 隐含 HEAD | TC-CORE-L2-01-002 | 正向 | SSE 路由会挂起连接,需在读完头后中止 |+| `dsh-tauri` 路由契约:OPTIONS 204 | TC-CORE-L2-01-001 | 正向 | `allow` 按集合比较,不吃成员顺序 |+| 路由契约:GET 隐含 HEAD | TC-CORE-L2-01-002 | 正向 | SSE 路由会挂起连接,读完响应头即 `abort()` || 路由契约:405 + allow | TC-CORE-L2-01-003 | 异常 | 与各插件文件中的 405 断言**不重复**:此处只验共享层 |-| 路由契约:跨源 403 | TC-CORE-L2-01-004 | 异常 | — |+| 路由契约:跨源 403 | TC-CORE-L2-01-004 | 异常 | L2 只能观察到上游 Host/Origin 围栏的 `forbidden`;路由层 `cross-origin-request` 分支被遮蔽,改由 L1 `packages/dsh-tauri/src/host/routes/index.test.ts:240` 覆盖 || 路由契约:413 bodyLimit | TC-CORE-L2-01-005 | 边界 | — || `plugin.test.md` §5 鉴权说明:带 Cookie 后 404 与 401 可区分 | TC-CORE-L2-01-006 | 异常 | — |@@ -249,13 +251,16 @@### 4.1 编排骨架-- **假设**:`dsh-tauri` 可作为 bundle 独立挂载(它是其它插件的宿主能力提供方)。若它不能被单独挂载,TC-HOST-L2-01-001 改用 `dsh-tauri-pet` 作为目标包。-- **缺口**:`assertBuilt`(`dsh-host.ts:127`)当前不可从外部注入,TC-HOST-L2-01-004 需要临时移动产物或后续把该函数导出。-- **缺口**:本文件不覆盖「端口冲突」「宿主提前退出」分支(`dsh-host.ts:278` 已有错误路径),留待骨架跑稳后补。+- **已定论**:`dsh-tauri` 可作为 bundle 独立挂载(实测通过,TC-HOST-L2-01-001 无需退化为 `dsh-tauri-pet`)。+- **已定论**:`assertBuilt` 无需注入即可测——`packages/dsh-tauri-tsdown` 与 `packages/dsh-tauri-bundle` 都是「源码即产物」(无 `main`、无 `dist`)且被 `build-plugins.ts:542`、`build-plugins.ts:544` 的 `--filter !` 显式排除,是稳定且不污染仓库的「未构建」夹具。已改用 `dsh-tauri-tsdown`。+- **已定论**:bundles 校验分支在 link 模式下不可达(bundles 由 `addBundle` 自己写入),已抽成导出的 `assertMountRegistered`(`test/e2e/support/dsh-host.ts:273`)供直接调用。代价是该用例不再能顺带断言「失败后 scratch 目录被清理」——那一段由 001/005 的清理断言覆盖。+- **缺口**:本文件不覆盖「端口冲突」「宿主提前退出」分支(`test/e2e/support/dsh-host.ts:341` 已有错误路径),留待骨架跑稳后补。- **未纳入范围**:浏览器渲染、Tauri 窗口、插件业务语义——分别属于 02 起的各插件文件与桌面端宿主层。### 4.2 共享路由契约-- **不可覆盖**:非回环地址发起的变更请求 403(`routes/index.ts:279`)需要非本机来源,本套用例不做,仅登记为已知未覆盖分支。+- **不可覆盖**:非回环地址发起的变更请求 403(`routes/index.ts:279`)需要非本机来源,本套用例不做;由 L1 `packages/dsh-tauri/src/host/routes/index.test.ts:219` 覆盖。+- **已定论(遮蔽)**:路由层的跨源 403(`routes/index.ts:287`,`cross-origin-request`)在真实宿主里不可达——上游 `@deepseek-ai/dsh-client-connection` 的 Host/Origin 围栏(`HostConnectionService.requestRejection` → `isTrustedApiRequest`)先拒绝,编排层把它渲染成 `{ error: 'forbidden' }`。L2 断言按可观察事实写(403 + `forbidden` + 无 handler 载荷),路由层词汇留给 L1。- **已定论**:不带会话 Cookie 时 `/api` 与插件路由返回 401(上游 `authorizeIndex` 在根路径之外不做 token 交换)。因此本批一律显式携带 Cookie;L2 不再依赖桌面端的载体放行——那是 `dsh-tauri-connection` 插件在 `DSH_TAURI_EMBEDDED=1` 时提供的运行时覆写,npm 上的核心没有这个插件。-- **假设**:`allow` 头的成员顺序稳定(`SUPPORTED_METHODS` 过滤后 join,见 `routes/index.ts:255`)。若顺序不稳定,断言改为集合包含而非字符串相等。+- **已定论**:`allow` 头的成员顺序实测为 `SUPPORTED_METHODS` 过滤后的 join 顺序(`GET, HEAD, OPTIONS`);断言仍按集合比较,避免把实现顺序固化成契约。+- **已定论(分段宿主)**:共享路由契约段自带宿主(`beforeAll` 起一次,`dsh-tauri-pet` + `dsh-tauri-rightclick`)而不复用 `globalSetup`,因为它需要的挂载集与默认 lane 不同;这样本文件不依赖任何外部环境变量即可独立运行。diff --git a/docs/testing/plugins/02-dsh-tauri-pet.md b/docs/testing/plugins/02-dsh-tauri-pet.mdindex 07db8f28..b8454449 100644--- a/docs/testing/plugins/02-dsh-tauri-pet.md+++ b/docs/testing/plugins/02-dsh-tauri-pet.md@@ -1,7 +1,7 @@# dsh-tauri-pet:从 SSE 路由到桌面端桌宠窗口> 层级:L2 插件宿主 E2E → L3 桌面端宿主 E2E-> 自动化:`test/e2e/plugins/session-stream.e2e.ts`(L2,SSE 首帧已落地)、`test/e2e/plugins/pet-client.e2e.ts`(客户端,待接线)、`test/e2e/plugins/pet-window.e2e.ts`(L3,待接线)+> 自动化:`test/e2e/plugins/02-dsh-tauri-pet.e2e.ts`(单文件承载本批全部用例,批内按层用 `describe` 分区;L2 SSE 首帧 2 例已落地,客户端段与 L3 段待接线)> 前置:`pnpm build:plugins`;L3 另需 debug 二进制 + `3081` 空闲 + `TAURI_WEBDRIVER_PORT`> 编排:`test/e2e/support/dsh-host.ts`;L3 通道见 `test/e2e/support/wdio-probe.mjs`> 运行:L2 `pnpm test:e2e:plugin`;L3 见 `00-overview.md` §5.2@@ -41,7 +41,7 @@[层级] L2(真实 dsh 进程)[类型] 正向[追踪] `packages/dsh-tauri-pet/src/host/routes/session/stream/get.ts:24`;`plugin.test.md` §8 批次 3-[自动化] 是(`test/e2e/plugins/session-stream.e2e.ts:37`)+[自动化] 是(`test/e2e/plugins/02-dsh-tauri-pet.e2e.ts:43`)[前置条件] 插件已构建并挂载进 scratch profile;宿主已就绪[测试数据] `GET /api/desktop/dsh-tauri-pet/session/stream`,`accept: text/event-stream`[测试步骤] 1. 发起请求。2. 读状态码与 `content-type`。3. 读响应体前 4 个字符后中止流。@@ -53,8 +53,8 @@[Case ID] TC-PET-L2-02-002[层级] L2(真实 dsh 进程)[类型] 异常-[追踪] `packages/dsh-tauri/src/host/routes/index.ts:275`-[自动化] 是(`test/e2e/plugins/session-stream.e2e.ts:49`)+[追踪] `packages/dsh-tauri/src/host/routes/index.ts:276`+[自动化] 是(`test/e2e/plugins/02-dsh-tauri-pet.e2e.ts:55`)[前置条件] 同 TC-PET-L2-02-001[测试数据] 同路径 `POST`,body `{}`[测试步骤] 1. 发起请求。2. 读状态码与 `allow` 头。diff --git a/docs/testing/progressive.md b/docs/testing/progressive.mdindex dafecfbe..4408297e 100644--- a/docs/testing/progressive.md+++ b/docs/testing/progressive.md@@ -61,9 +61,9 @@| 批次 | 用例 / 基础设施 | 对应文档 | 状态 | 备注 || --- | --- | --- | --- | --- |-| 00 | 总览、前置与追踪矩阵 | `00-overview.md` | 提案中 | 不承载用例本体 |-| 01 | 编排骨架与共享路由契约 | `01-dsh-host-and-core-contract.md` | 提案中 | 编排代码 `test/e2e/support/dsh-host.ts` 已落地;包含 OPTIONS/405/403/413 契约 |-| 02 | `dsh-tauri-pet`(SSE → 客户端 → 桌面端窗口) | `02-dsh-tauri-pet.md` | 已实现 | SSE 首帧用例已迁至 `test/e2e/plugins/`;客户端与 L3 待接线 |+| 00 | 总览、前置与追踪矩阵 | `00-overview.md` | 已验证 | 不承载用例本体;已按当前实现刷新事实表、缺口(G1/G4 消解、新增 G10 跨源遮蔽)与文件命名规则(测试文件与用例文档同名同序号) |+| 01 | 编排骨架与共享路由契约 | `01-dsh-host-and-core-contract.md` | 已验证 | `test/e2e/plugins/01-dsh-host-and-core-contract.e2e.ts` 12 例全绿(编排骨架 6 + 共享路由契约 6);编排新增导出 `assertMountRegistered`;跨源 403 期望值按实测修正(上游围栏 `forbidden`,路由层 `cross-origin-request` 在 L2 不可达,由 L1 覆盖) |+| 02 | `dsh-tauri-pet`(SSE → 客户端 → 桌面端窗口) | `02-dsh-tauri-pet.md` | 已实现 | 测试文件更名对齐序号(`session-stream.e2e.ts` → `02-dsh-tauri-pet.e2e.ts`);SSE 首帧 2 例已落地;客户端与 L3 待接线 || 03 | `dsh-tauri-rightclick` | `03-dsh-tauri-rightclick.md` | 提案中 | - || 04 | `dsh-tauri-session` | `04-dsh-tauri-session.md` | 提案中 | - || 05 | `dsh-tauri-worktree` | `05-dsh-tauri-worktree.md` | 提案中 | - |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.tsnew file mode 100644index 00000000..a49c355e--- /dev/null+++ b/test/e2e/plugins/01-dsh-host-and-core-contract.e2e.ts@@ -0,0 +1,287 @@+/**+ * 批次 01 · 编排骨架与共享路由契约(用例来源:`docs/testing/plugins/01-dsh-host-and-core-contract.md`)。+ *+ * 本批是全套插件用例的地基,两段各有不可替代的作用:+ * - 编排骨架不成立时,后面所有「插件路由 404」都无法区分是插件没挂上还是宿主没起来;+ * - 共享路由契约跑偏时,所有插件的负向断言都会失真。+ *+ * 断言对象一律是外部世界(HTTP 响应字节、profile 文件、临时目录),不采信插件自报。+ * 唯一例外是「挂载未登记」:link 模式下 bundles 由编排自己写入,端到端构造不出该失败形态,+ * 故直接调用导出的校验分支。+ */++import type { DshHost } from '../support/dsh-host'+import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join, resolve } from 'node:path'+import process from 'node:process'+import { afterAll, beforeAll, describe, expect, it } from 'vitest'+import { assertMountRegistered, REPO_ROOT, startDshHost } from '../support/dsh-host'++/** 源码即产物的包:无 `main`、无 `dist`,且被 `build:plugins` 显式排除,永远处于「未构建」。 */+const UNBUILT_PACKAGE = 'dsh-tauri-tsdown'++interface ProfileManifest {+ dependencies?: Record<string, string>+ dsh?: { profile?: { bundles?: string[] } }+}++function readProfileManifest(home: string): ProfileManifest {+ return JSON.parse(readFileSync(join(home, 'profiles', 'web', 'package.json'), 'utf8')) as ProfileManifest+}++/** `link:` 规格与仓库包路径对齐(CLI 会写成正斜杠,故统一 resolve 后比较)。 */+function linkedPath(spec: string): string {+ return resolve(spec.replace(/^link:/, ''))+}++describe('编排骨架', () => {+ it('验证在隔离 scratch 目录下能挂载目标插件并拉起真实 dsh web', async () => {+ const host = await startDshHost({ plugin: 'dsh-tauri' })+ try {+ expect(host.baseUrl, 'baseUrl 必须是回环地址 + 具体端口').toMatch(/^http:\/\/127\.0\.0\.1:\d+$/)+ expect(new URL(host.baseUrl).port, '端口 0 表示没有真正绑定').not.toBe('0')+ expect(host.cookie, '会话 Cookie 必须换到').not.toBe('')+ expect(host.mounted, 'mounted 必须精确包含目标包').toContain('dsh-tauri')+ expect(host.home, 'scratch 目录必须按 <tmp>/dsh-e2e-<plugin>-<时间戳> 隔离').toContain('dsh-e2e-dsh-tauri-')++ const response = await fetch(`${host.baseUrl}/`, { headers: { cookie: host.cookie } })+ expect(response.status, '根路径带 Cookie 必须可访问').toBeGreaterThanOrEqual(200)+ expect(response.status).toBeLessThan(300)+ expect((await response.text()).length, '响应体不能为空').toBeGreaterThan(0)++ const log = readFileSync(host.logPath, 'utf8')+ expect(log, '日志内必须出现与 url 一致的就绪行').toContain(host.url)+ expect(log, '就绪的宿主不应有模块解析失败').not.toContain('ERR_MODULE_NOT_FOUND')+ }+ finally {+ await host.stop()+ }+ expect(existsSync(host.home), 'stop() 后 scratch 目录必须被清理').toBe(false)+ })++ it('验证宿主启动后目标插件的 bundle 已登记进 profile', async () => {+ const host = await startDshHost({ plugin: 'dsh-tauri', also: ['dsh-tauri-pet'] })+ try {+ const manifest = readProfileManifest(host.home)+ const bundles = manifest.dsh?.profile?.bundles ?? []++ expect(bundles).toContain('dsh-tauri-pet')+ expect(bundles).toContain('dsh-tauri')+ expect(new Set(bundles).size, 'bundles 不允许重复项').toBe(bundles.length)++ for (const name of ['dsh-tauri', 'dsh-tauri-pet']) {+ const spec = manifest.dependencies?.[name] ?? ''+ expect(spec, `${name} 必须由编排写成 link: 规格`).toMatch(/^link:/)+ expect(linkedPath(spec), `${name} 必须指向仓库 packages/${name}`).toBe(join(REPO_ROOT, 'packages', name))+ }++ // 规格写得对不等于挂得上:profile 里的链接必须真的落在仓库包目录上。+ const profileDir = join(host.home, 'profiles', 'web')+ for (const name of ['dsh-tauri', 'dsh-tauri-pet']) {+ expect(+ realpathSync(join(profileDir, 'node_modules', name)),+ `${name} 的挂载链接必须解引用到仓库包`,+ ).toBe(realpathSync(join(REPO_ROOT, 'packages', name)))+ }+ }+ finally {+ await host.stop()+ }+ })++ it('[反向] 验证挂载未登记进 bundles 时立刻失败,而不是带着半成品起服务', async () => {+ const profileDir = join(tmpdir(), `dsh-e2e-mount-guard-${Date.now().toString(36)}`)+ mkdirSync(profileDir, { recursive: true })+ writeFileSync(+ join(profileDir, 'package.json'),+ `${JSON.stringify({ name: 'dsh-profile-web', dsh: { profile: { bundles: ['@deepseek-ai/dsh-base', 'dsh-tauri-pet'] } } }, null, 2)}\n`,+ )++ try {+ expect(+ () => assertMountRegistered(profileDir, ['dsh-tauri-pet']),+ '已登记的包不得误报',+ ).not.toThrow()+ expect(+ () => assertMountRegistered(profileDir, ['dsh-tauri-pet', 'dsh-tauri']),+ '缺失的包名必须列出,且只列缺失的那个',+ ).toThrowError(/^挂载未注册到 dsh\.profile\.bundles:dsh-tauri$/)+ }+ finally {+ rmSync(profileDir, { recursive: true, force: true })+ }+ expect(existsSync(profileDir), '夹具目录必须清理干净').toBe(false)+ })++ it('[反向] 验证产物缺失时报出可操作的构建指引', async () => {+ const before = new Set(readdirSync(tmpdir()))++ await expect(startDshHost({ plugin: UNBUILT_PACKAGE })).rejects.toThrowError(/尚未构建[\s\S]*pnpm build:plugins/)++ const leaked = readdirSync(tmpdir())+ .filter(name => name.startsWith(`dsh-e2e-${UNBUILT_PACKAGE}-`) && !before.has(name))+ expect(leaked, '预检失败不得留下 scratch 目录,也不得进入 dsh web 启动阶段').toEqual([])+ })++ it('验证环境变量边界:DSH_E2E_KEEP_HOME 控制 scratch 去留', async () => {+ const disposable = await startDshHost({ plugin: 'dsh-tauri-pet' })+ await disposable.stop()+ expect(existsSync(disposable.home), '默认必须清理 scratch 目录').toBe(false)++ const kept = await startDshHost({ plugin: 'dsh-tauri-pet', keepHome: true })+ try {+ await kept.stop()+ expect(existsSync(kept.home), 'KEEP_HOME 必须保留 scratch 目录').toBe(true)+ expect(readFileSync(kept.logPath, 'utf8').length, '保留的日志必须可读').toBeGreaterThan(0)+ }+ finally {+ rmSync(kept.home, { recursive: true, force: true })+ }+ expect(existsSync(kept.home), '手工删除后不得有残留锁文件').toBe(false)+ })++ it('验证 DSH_E2E_MOUNT=cli 走真实 CLI 挂载路径', async () => {+ process.env.DSH_E2E_MOUNT = 'cli'+ try {+ const host = await startDshHost({ plugin: 'dsh-tauri' })+ try {+ const spec = readProfileManifest(host.home).dependencies?.['dsh-tauri'] ?? ''+ expect(spec, 'dsh plugin add 必须把依赖写成 link: 规格').toMatch(/^link:/)+ expect(linkedPath(spec), 'CLI 写入的规格必须指向仓库包而非自建链接').toBe(join(REPO_ROOT, 'packages', 'dsh-tauri'))++ const response = await fetch(`${host.baseUrl}/`, { headers: { cookie: host.cookie } })+ expect(response.status, 'cli 挂载后宿主必须可用').toBeGreaterThanOrEqual(200)+ expect(response.status).toBeLessThan(300)+ }+ finally {+ await host.stop()+ }+ }+ finally {+ delete process.env.DSH_E2E_MOUNT+ }+ })+})++/** 只声明 GET 的代表路由(`packages/dsh-tauri-pet/src/host/routes/index.ts`)。 */+const GET_ONLY_PATH = '/api/desktop/dsh-tauri-pet/session/stream'++/** 只声明 POST 的代表路由(`packages/dsh-tauri-rightclick/src/host/routes/index.ts`)。 */+const POST_ONLY_PATH = '/api/desktop/dsh-tauri-rightclick/open/url'++/** 本批不挂载的插件路径,用于证明「路由缺失」而非「鉴权失败」。 */+const UNMOUNTED_PATH = '/api/desktop/dsh-tauri-turnrewind/summary?sessionId=x'++const BODY_LIMIT_BYTES = 1024 * 1024++describe('共享路由契约', () => {+ let host: DshHost++ // 本段自带宿主而非复用 globalSetup:它需要「GET 代表路由 + POST 代表路由」这一特定挂载集,+ // 与默认 lane 的 `dsh-tauri-pet` 不同,自带宿主才能保证本文件独立可运行。+ beforeAll(async () => {+ host = await startDshHost({ plugin: 'dsh-tauri-pet', also: ['dsh-tauri-rightclick'] })+ })++ afterAll(async () => {+ await host.stop()+ })++ /** 所有请求都必须带会话 Cookie,否则 `/api` 一律 401,会把鉴权失败误读成路由契约失败。 */+ function headers(extra: Record<string, string> = {}): Record<string, string> {+ return { cookie: host.cookie, ...extra }+ }++ function url(path: string): string {+ return `${host.baseUrl}${path}`+ }++ /** `allow` 成员顺序属实现细节,按集合比较。 */+ function allowMethods(response: Response): string[] {+ return (response.headers.get('allow') ?? '').split(',').map(entry => entry.trim()).filter(Boolean).sort()+ }++ it('验证 OPTIONS 预检在只声明 GET 的路径上返回 204 并公布 allow', async () => {+ const response = await fetch(url(GET_ONLY_PATH), { method: 'OPTIONS', headers: headers() })++ expect(response.status, '未声明的 OPTIONS 必须走默认 204 预检').toBe(204)+ expect(await response.text(), '预检响应不得带 body').toBe('')+ expect(allowMethods(response), 'allow 必须公布 GET / HEAD(GET 隐含)/ OPTIONS').toEqual(['GET', 'HEAD', 'OPTIONS'])+ })++ it('验证只声明 GET 的路径接受 HEAD 而不被判 405', async () => {+ const controller = new AbortController()+ try {+ const response = await fetch(url(GET_ONLY_PATH), {+ method: 'HEAD',+ headers: headers(),+ signal: controller.signal,+ })+ expect(response.status, 'GET 隐含 HEAD,不能落到 405').not.toBe(405)+ expect(response.status, 'HEAD 必须命中真实 handler').toBe(200)+ }+ finally {+ controller.abort()+ }+ })++ it('[反向] 验证未声明的方法返回 405 且给出可用的 allow', async () => {+ const response = await fetch(url(GET_ONLY_PATH), {+ method: 'POST',+ headers: headers({ 'content-type': 'application/json' }),+ body: '{}',+ })++ expect(response.status, '只声明了 GET,POST 必须 405').toBe(405)+ expect(response.headers.get('allow') ?? '', 'allow 必须指出可用方法').toContain('GET')++ const body = await response.json() as { error?: string }+ expect(body.error ?? '', '错误文本必须点明允许的方法').toMatch(/^仅支持 /)+ expect(body.error ?? '').toContain('GET')+ })++ it('[反向] 验证异源 Origin 的变更请求被 403 拒绝', async () => {+ const response = await fetch(url(POST_ONLY_PATH), {+ method: 'POST',+ headers: headers({ 'content-type': 'application/json', 'origin': 'http://evil.example' }),+ body: '{}',+ })++ expect(response.status, '异源变更请求必须 403').toBe(403)++ const body = await response.json() as { error?: string }+ // 上游 Host/Origin 围栏(`dsh-client-connection` 的 `requestRejection`)先于路由层生效,+ // 用的是连接门词汇 `forbidden`;路由层的 `cross-origin-request` 分支在 L2 不可达,+ // 由 `packages/dsh-tauri/src/host/routes/index.test.ts` 的 L1 用例覆盖。+ expect(body.error, '拒绝必须来自连接门,而不是路由层').toBe('forbidden')+ expect(JSON.stringify(body), 'handler 的 {"ok":true} 不得出现').not.toContain('ok')+ })++ it('[反向] 验证超过 1 MiB 的请求体被 413 终止', async () => {+ const payload = JSON.stringify({ pad: 'x'.repeat(BODY_LIMIT_BYTES) })+ expect(payload.length, '测试数据必须真的超过上限').toBeGreaterThan(BODY_LIMIT_BYTES)++ let response: Response+ try {+ response = await fetch(url(POST_ONLY_PATH), {+ method: 'POST',+ headers: headers({ 'content-type': 'application/json' }),+ body: payload,+ })+ }+ catch (error) {+ throw new Error(`超限请求体必须以 413 结束,而不是连接层异常:${(error as Error).message}`)+ }++ expect(response.status, 'bodyLimit 必须在读体时以 413 结束').toBe(413)+ expect(await response.text(), '413 必须报出上限字节数').toContain(String(BODY_LIMIT_BYTES))+ })++ it('[反向] 验证未挂载插件的路径返回 404,用于区分「没挂载」与「没鉴权」', async () => {+ const response = await fetch(url(UNMOUNTED_PATH), { headers: headers() })++ expect(response.status, '带 Cookie 时未挂载必须 404,而不是 401').toBe(404)+ expect(response.status, '不能误落到 200').not.toBe(200)+ })+})diff --git a/test/e2e/plugins/session-stream.e2e.ts b/test/e2e/plugins/02-dsh-tauri-pet.e2e.tssimilarity index 100%rename from test/e2e/plugins/session-stream.e2e.tsrename to test/e2e/plugins/02-dsh-tauri-pet.e2e.tsdiff --git a/test/e2e/support/dsh-host.ts b/test/e2e/support/dsh-host.tsindex c9a575fa..480e83ee 100644--- a/test/e2e/support/dsh-host.ts+++ b/test/e2e/support/dsh-host.ts@@ -264,6 +264,19 @@ function addBundle(profileDir: string, pkg: string): void {})}+/**+ * 挂载自检:`packages` 必须全部登记进 profile 的 `dsh.profile.bundles`,否则启动前即失败。+ *+ * 独立导出是因为该分支在 link 模式下不可达——bundles 由 `addBundle` 自己写入,端到端+ * 构造不出「挂载漏登记」;只有直接给一份 profile 才能覆盖这一失败形态。+ */+export function assertMountRegistered(profileDir: string, packages: readonly string[]): void {+ const registered = readBundles(profileDir)+ const missing = packages.filter(pkg => !registered.includes(pkg))+ if (missing.length > 0)+ throw new Error(`挂载未注册到 dsh.profile.bundles:${missing.join(', ')}`)+}+/* ==========================================* 进程与 CLI 交互* ========================================== */@@ -401,9 +414,7 @@ export async function startDshHost(options: StartDshHostOptions): Promise<DshHos}}- const missing = packages.filter(pkg => !readBundles(profileDir).includes(pkg))- if (missing.length > 0)- throw new Error(`挂载未注册到 dsh.profile.bundles:${missing.join(', ')}`)+ assertMountRegistered(profileDir, packages)}catch (error) {rmSync(home, { recursive: true, force: true })