diff --git a/apps/mobile-shell/scripts/check-config.mjs b/apps/mobile-shell/scripts/check-config.mjs index 7b17c9cdd..22798d81d 100644 --- a/apps/mobile-shell/scripts/check-config.mjs +++ b/apps/mobile-shell/scripts/check-config.mjs @@ -42,6 +42,11 @@ const capabilitiesTestPath = new URL( const capabilitiesTestSource = fs.readFileSync(capabilitiesTestPath, 'utf8'); const clipboardPath = new URL('../src/host-bridge/clipboard.ts', import.meta.url); const clipboardSource = fs.readFileSync(clipboardPath, 'utf8'); +const clipboardTestPath = new URL( + '../src/host-bridge/clipboard.test.ts', + import.meta.url, +); +const clipboardTestSource = fs.readFileSync(clipboardTestPath, 'utf8'); const dispatchPath = new URL('../src/host-bridge/dispatch.ts', import.meta.url); const dispatchSource = fs.readFileSync(dispatchPath, 'utf8'); const dispatchTestPath = new URL( @@ -2156,9 +2161,19 @@ for (const snippet of [ throw new Error(`mobile shell clipboard module is missing ${snippet}`); } } -if (!bridgeTestSource.includes("'猫'.repeat(100000)")) { +if (!clipboardTestSource.includes("'猫'.repeat(100000)")) { throw new Error('mobile shell clipboard tests must cover Unicode truncation'); } +for (const snippet of [ + 'rejects unavailable clipboard text without reporting a successful empty value', + 'Clipboard.getStringAsync).mockResolvedValue(undefined as never)', + "code: 'host_error'", + "message: 'clipboard text unavailable'", +]) { + if (!clipboardTestSource.includes(snippet)) { + throw new Error(`mobile shell clipboard tests must cover unavailable reads: ${snippet}`); + } +} if ( !hapticsSource.includes('normalizeHostBridgeHapticsImpactStyle(rawStyle)') || diff --git a/apps/mobile-shell/src/host-bridge/clipboard.test.ts b/apps/mobile-shell/src/host-bridge/clipboard.test.ts index d7f08ad5a..1f1d49da4 100644 --- a/apps/mobile-shell/src/host-bridge/clipboard.test.ts +++ b/apps/mobile-shell/src/host-bridge/clipboard.test.ts @@ -119,6 +119,15 @@ describe('mobile clipboard helpers', () => { }); }); + test('rejects unavailable clipboard text without reporting a successful empty value', async () => { + vi.mocked(Clipboard.getStringAsync).mockResolvedValue(undefined as never); + + await expect(readMobileClipboardText()).rejects.toMatchObject({ + code: 'host_error', + message: 'clipboard text unavailable', + }); + }); + test('wraps HostBridge clipboard read responses', async () => { vi.mocked(Clipboard.getStringAsync).mockResolvedValue('作品号 PZ-1'); diff --git a/docs/project-memory/shared-memory/decision-log.md b/docs/project-memory/shared-memory/decision-log.md index c65e6c9e9..cd5d2ca56 100644 --- a/docs/project-memory/shared-memory/decision-log.md +++ b/docs/project-memory/shared-memory/decision-log.md @@ -114,7 +114,7 @@ - 2026-06-19 草稿生成 HostBridge 消费门禁:`PlatformEntryFlowShellImpl` 只负责派生草稿通知和未读数量,实际宿主同步经 `platformHostBridgeSync.ts` 调用 `showHostLocalNotification` / `setHostAppBadgeCount`;`npm run check:native-shells` 必须运行该同步层的真实 Tauri transport 测试,并继续覆盖通知模型、未读计数模型、音频导入和文档导入等 H5 HostBridge 消费测试。 - 2026-06-18 剪贴板读取能力:新增 `clipboard.readText` HostBridge capability,H5 只能读取纯文本结果,契约限制返回文本最多 100000 字符;Expo 壳通过 `expo-clipboard` 读取系统剪贴板文本,Tauri 壳通过 Rust 侧 `tauri-plugin-clipboard-manager` 读取文本且不开放插件 JS guest API。该能力不读取图片、HTML、文件列表或剪贴板监听事件,宿主未声明或读取失败时由 H5 视作失败并保留原流程。 - 2026-06-19 移动壳剪贴板边界:Expo `clipboard.writeText` / `clipboard.readText` 的系统剪贴板读写、共享 100000 字符归一、payload 校验和 HostBridge 成功 / 失败响应边界统一收口在 `apps/mobile-shell/src/host-bridge/clipboard.ts`;`dispatch.ts` 只负责把 HostBridge request 委托给 `writeMobileHostBridgeClipboardText(request)` / `readMobileHostBridgeClipboardText(request)`,不得直接导入 `expo-clipboard`、调用 `Clipboard.setStringAsync` / `Clipboard.getStringAsync` 或包装剪贴板成功响应。移动壳配置检查会覆盖该模块结构、共享文本边界和 dispatch 委托关系,避免剪贴板能力散落到分发层。 -- 2026-06-20 移动剪贴板单测边界:`apps/mobile-shell/src/host-bridge/clipboard.test.ts` 直接覆盖 Expo `clipboard.writeText` / `clipboard.readText` 的共享文本归一、100000 字符截断、非字符串写入拒绝、空字符串纯文本读写、系统剪贴板读写调用和 HostBridge 成功 / 失败响应包装;根级 `npm run check:native-shells` 会把该测试文件列入移动桥接层结构清单,避免移动剪贴板边界只靠完整 HostBridge bridge 流程间接覆盖。 +- 2026-06-20 移动剪贴板单测边界:`apps/mobile-shell/src/host-bridge/clipboard.test.ts` 直接覆盖 Expo `clipboard.writeText` / `clipboard.readText` 的共享文本归一、100000 字符截断、非字符串写入拒绝、空字符串纯文本读写、不可用读取返回 `host_error`、系统剪贴板读写调用和 HostBridge 成功 / 失败响应包装;根级 `npm run check:native-shells` 会把该测试文件列入移动桥接层结构清单,移动壳配置检查会反查不可用读取失败语义,避免移动剪贴板边界只靠完整 HostBridge bridge 流程间接覆盖或把底层不可用值伪装成成功空文本。 - 2026-06-19 桌面壳剪贴板边界:Tauri `clipboard.writeText` / `clipboard.readText` 的系统剪贴板读写、共享 100000 字符归一、payload 校验和响应边界统一收口在 `apps/desktop-shell/src-tauri/src/host_bridge/clipboard.rs`;`dispatch.rs` 只负责把 HostBridge request 委托给 `write_desktop_host_bridge_clipboard_text(...)` / `read_desktop_host_bridge_clipboard_text(...)`,不得直接承接剪贴板文本截断、payload 解析或插件读写细节;桌面 share fallback 仍可调用底层写剪贴板函数复制分享文本。桌面壳配置检查会覆盖该模块结构、共享文本边界和 dispatch 委托关系,避免剪贴板能力散落到分发层。 - 2026-06-19 桌面壳本地通知边界:Tauri `notification.showLocal` 的 payload 清洗、权限状态检查、prompt 权限请求和系统通知发送统一收口在 `apps/desktop-shell/src-tauri/src/host_bridge/notifications.rs`;`dispatch.rs` 只负责把 HostBridge request 委托给 `show_desktop_local_notification(...)` 并映射响应,不得直接调用 `app.notification()`、`NotificationExt` 或 `PermissionState`。桌面壳配置检查会覆盖该模块结构、权限语义和 dispatch 委托关系,避免本地通知能力散落到分发层。 - 2026-06-18 文本文件导入能力:新增 `file.importText` HostBridge capability,H5 统一通过 `importHostTextFile()` 读取宿主返回的纯文本内容;Expo 壳通过 `expo-document-picker` 打开系统文档选择器,Tauri 壳通过系统文件选择框读取真实文本文件。两端只接受 `text/plain`、`text/markdown`、`text/csv`、`application/json` 或对应扩展名,单次不超过 5 MiB,成功只返回清洗后的文件名、MIME、UTF-8 文本内容和字节数,不暴露设备 URI / 本机绝对路径,也不开放通用文件系统。Expo 文本导入的 DocumentPicker 调用、大小校验、文本读取和 HostBridge 成功响应包装统一收口在 `apps/mobile-shell/src/host-bridge/files.ts`,`dispatch.ts` 只委托文件模块。