# 09-typed-ipc-contracts / app 一个「类型安全 IPC 契约」演示:通道、请求/响应类型、手写校验器与结构化错误都放在 `shared/ipc.ts`;三个页签分别展示成功信封、公开错误、10 条校验用例。 ## 运行 ```bash pnpm --filter @tutorial/09-typed-ipc-contracts-app start pnpm --filter @tutorial/09-typed-ipc-contracts-app smoke pnpm --filter @tutorial/09-typed-ipc-contracts-app shots pnpm --filter @tutorial/09-typed-ipc-contracts-app diagnostics ``` ## smoke 输出 ```json {"evt":"smoke","ok":true,"created":1,"emptyTitle":"TITLE_EMPTY","tooManyTags":"TOO_MANY_TAGS", "unknownField":"UNKNOWN_FIELD","listCount":1,"casesFailed":0,"noStack":true} ``` ## 结构 - `shared/ipc.ts`:通道、`Envelope`、请求/响应类型、`ContractError`、两个校验器、`toPublicError` - `main/`:`notes:create` / `notes:list` / `contract:cases` / 演示用 `notes:reset`;`--diagnostics` 打印真实校验堆栈 - `preload/`:只暴露 `createNote/createNoteRaw/listNotes/runCases/resetNotes` - `src/`:契约 / 错误 / 校验用例三个页签 ## testid | testid | 用途 | | --- | --- | | `app-title` | 页面标题 | | `tab-contract` / `tab-error` / `tab-cases` | 三个页签 | | `title-input` / `body-input` / `tags-input` | 表单 | | `create-button` / `bad-empty` / `bad-tags` / `bad-extra` | 正常与三种非法请求 | | `response-json` / `note-table` | 响应信封与笔记列表 | | `error-code` / `error-request-id` / `error-detail` / `error-stack` | 公开错误字段 | | `case-table` / `cases-summary` / `case-row` | 校验用例 | ## 已知限制 - 只在 macOS arm64 验证;`requestId` 含时间戳,截图只用于说明结构。 - `createNoteRaw` 与 `notes:reset` 只用于演示,生产应删除或加严格限制。