# 11-main-process-services / app 一个「服务层工作台」:notes / shell / dialog 三个服务 + 30 行薄 IPC 层。 服务不 import Electron(除 `services/index.ts` 工厂),可以用 Vitest 直接测。 ## 运行 ```bash pnpm --filter @tutorial/11-main-process-services-app start pnpm --filter @tutorial/11-main-process-services-app test pnpm --filter @tutorial/11-main-process-services-app smoke pnpm --filter @tutorial/11-main-process-services-app shots pnpm --filter @tutorial/11-main-process-services-app diagnostics ``` ## smoke 输出 ```json {"evt":"smoke","ok":true,"notes":2,"readBytes":39,"badId":"BAD_ID", "allowed":true,"blocked":"URL_NOT_ALLOWED","picked":"welcome.md"} ``` ## 结构 - `main/services/notes-service.ts`:原子写、id 正则、64KB 上限 - `main/services/shell-service.ts`:https + host 白名单,`openExternal` 注入 - `main/services/dialog-service.ts`:`.md/.txt`,`showOpenDialog` 注入 - `main/services/index.ts`:唯一 import Electron 的工厂;smoke/shots 用 dryRun - `main/ipc.ts`:校验 + 转发 + 信封/requestId - `main/services/services.test.ts`:9 个 Vitest 用例(临时目录 + fake 依赖) ## testid | testid | 用途 | | --- | --- | | `app-title` | 页面标题 | | `tab-catalog` / `tab-notes` / `tab-shell` | 三个页签 | | `service-card` | 服务目录卡片 | | `note-id` / `note-content` | 笔记表单 | | `save-button` / `read-button` / `delete-button` | 保存 / 读取 / 删除 | | `note-table` / `note-row` / `response-json` | 列表与响应 | | `shell-url` / `open-button` / `allowed-text` / `blocked-text` | Shell 白名单 | | `pick-button` / `picked-name` | 文件对话框 | ## 已知限制 - 只在 macOS arm64 验证;smoke/shots 的 shell 与 dialog 使用 dryRun,不会真的打开浏览器或弹窗。 - notes 只存在 `userData/notes`,重启保留;删除目录即重置。