Skip to content

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

fix(rightclick): 右键粘贴在没有纯文本时复用宿主垫片 (#1193)

liang-zhenxiangd7c28d171de8
diff --git a/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.test.ts b/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.test.ts
index a7b2399c..5722b261 100644
--- a/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.test.ts
+++ b/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.test.ts
@@ -2,7 +2,8 @@
import type { SessionSummaryLike } from '../types'
import type { MenuComposer } from './context-menu.types'
import { afterEach, expect, it, vi } from 'vitest'
-import { buildSessionMenu } from './context-menu.menu'
+import { locale } from '../locales'
+import { buildEditableMenu, buildSessionMenu } from './context-menu.menu'
const { invoke } = vi.hoisted(() => ({ invoke: vi.fn() }))
vi.mock('dsh-tauri/client', async importOriginal => ({
@@ -13,6 +14,64 @@ vi.mock('dsh-tauri/client', async importOriginal => ({
afterEach(() => {
vi.unstubAllGlobals()
invoke.mockReset()
+ document.body.replaceChildren()
+})
+
+function editableMenu() {
+ const actions = new Map<string, () => unknown>()
+ const composer = {
+ add: (label: string, action: () => unknown) => actions.set(label, action),
+ split: vi.fn(),
+ toast: vi.fn(),
+ copyText: vi.fn(),
+ } as unknown as MenuComposer
+ const editable = document.createElement('textarea')
+ document.body.appendChild(editable)
+ buildEditableMenu(composer, editable, '')
+ return { actions, editable }
+}
+
+it('剪贴板没有文本时把文件/图片粘贴交给宿主垫片(issue #1190)', async () => {
+ vi.stubGlobal('dshDesktop', {})
+ invoke.mockResolvedValue(null)
+ const paste = vi.fn().mockResolvedValue(true)
+ vi.stubGlobal('__dsh_paste_clipboard__', paste)
+ const { actions, editable } = editableMenu()
+
+ await actions.get(locale.text('paste'))?.()
+
+ expect(paste).toHaveBeenCalledExactlyOnceWith(editable)
+ expect(document.activeElement).toBe(editable)
+})
+
+it('宿主垫片不在场且没有文本时保留原提示', async () => {
+ vi.stubGlobal('dshDesktop', {})
+ invoke.mockResolvedValue(null)
+ const { actions } = editableMenu()
+
+ await expect(actions.get(locale.text('paste'))?.()).rejects.toThrow()
+})
+
+it('宿主垫片未处理时同样保留原提示', async () => {
+ vi.stubGlobal('dshDesktop', {})
+ invoke.mockResolvedValue(null)
+ vi.stubGlobal('__dsh_paste_clipboard__', vi.fn().mockResolvedValue(false))
+ const { actions } = editableMenu()
+
+ await expect(actions.get(locale.text('paste'))?.()).rejects.toThrow()
+})
+
+it('剪贴板有文本时只走文本粘贴,不再请求宿主垫片', async () => {
+ vi.stubGlobal('dshDesktop', {})
+ invoke.mockResolvedValue('hello')
+ const paste = vi.fn().mockResolvedValue(true)
+ vi.stubGlobal('__dsh_paste_clipboard__', paste)
+ const { actions, editable } = editableMenu()
+
+ await actions.get(locale.text('paste'))?.()
+
+ expect(editable.value).toBe('hello')
+ expect(paste).not.toHaveBeenCalled()
})
it('only offers a desktop window in the shell and targets the clicked session without selecting it', async () => {
diff --git a/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts b/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts
index bca29f7f..10f00aff 100644
--- a/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts
+++ b/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts
@@ -24,7 +24,7 @@ import {
supportsSessionPin,
togglePinSession,
} from '../service/menu'
-import { readClipboard } from '../utils/clipboard'
+import { pasteNativeClipboard, readClipboard } from '../utils/clipboard'
import { pasteInto, replaceSelection, selectAll, selectSurface } from '../utils/editable'
import { externalUrl, selectedUrl } from '../utils/url'
import { redoShortcutLabel, shortcutLabel } from './context-menu.utils'
@@ -239,8 +239,12 @@ export function buildEditableMenu(composer: MenuComposer, editable: HTMLElement,
composer.add(locale.text('copy'), () => composer.copyText(selection, locale.text('copied')), shortcutLabel('C'))
composer.add(locale.text('paste'), async () => {
const clipboard = await readClipboard()
- if (clipboard === null)
+ if (clipboard === null) {
+ editable.focus()
+ if (await pasteNativeClipboard(editable))
+ return
throw new Error(locale.text('clipboardReadFailed', { key: shortcutLabel('V') }))
+ }
if (!pasteInto(editable, clipboard))
throw new Error(locale.text('editPositionUnknown'))
}, shortcutLabel('V'))
diff --git a/packages/dsh-tauri-rightclick/src/client/utils/clipboard.test.ts b/packages/dsh-tauri-rightclick/src/client/utils/clipboard.test.ts
index 925c2abe..281af990 100644
--- a/packages/dsh-tauri-rightclick/src/client/utils/clipboard.test.ts
+++ b/packages/dsh-tauri-rightclick/src/client/utils/clipboard.test.ts
@@ -1,5 +1,6 @@
+// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from 'vitest'
-import { readClipboard } from './clipboard'
+import { pasteNativeClipboard, readClipboard } from './clipboard'
const invoke = vi.hoisted(() => vi.fn())
@@ -53,6 +54,27 @@ describe('readClipboard — 桌面载体', () => {
})
})
+describe('pasteNativeClipboard — 宿主 paste 垫片', () => {
+ it('没有垫片时按未处理返回,浏览器直开不额外弹错', async () => {
+ await expect(pasteNativeClipboard(document.createElement('div'))).resolves.toBe(false)
+ })
+
+ it('把目标元素交给垫片并透传是否已处理(issue #1190)', async () => {
+ const paste = vi.fn().mockResolvedValue(true)
+ vi.stubGlobal('__dsh_paste_clipboard__', paste)
+ const editable = document.createElement('div')
+
+ await expect(pasteNativeClipboard(editable)).resolves.toBe(true)
+ expect(paste).toHaveBeenCalledExactlyOnceWith(editable)
+ })
+
+ it('垫片抛错时按未处理返回,不把异常抛进菜单动作', async () => {
+ vi.stubGlobal('__dsh_paste_clipboard__', vi.fn().mockRejectedValue(new Error('bridge failed')))
+
+ await expect(pasteNativeClipboard(document.createElement('div'))).resolves.toBe(false)
+ })
+})
+
describe('readClipboard — 浏览器直开', () => {
it('没有 dshDesktop 标记时只用 Web Clipboard,不碰原生命令', async () => {
stubWebClipboard(vi.fn().mockResolvedValue('web text'))
diff --git a/packages/dsh-tauri-rightclick/src/client/utils/clipboard.ts b/packages/dsh-tauri-rightclick/src/client/utils/clipboard.ts
index 6e70b942..e9c785a5 100644
--- a/packages/dsh-tauri-rightclick/src/client/utils/clipboard.ts
+++ b/packages/dsh-tauri-rightclick/src/client/utils/clipboard.ts
@@ -18,7 +18,8 @@ export async function readClipboard(): Promise<string | null> {
try {
return await invoke<string | null>('read_clipboard_text')
}
- catch {
+ catch (error) {
+ console.warn('[rightclick] read_clipboard_text failed:', error)
return null
}
}
@@ -26,11 +27,31 @@ export async function readClipboard(): Promise<string | null> {
try {
return await navigator.clipboard.readText()
}
- catch {}
+ catch (error) {
+ console.warn('[rightclick] navigator.clipboard.readText failed:', error)
+ }
}
return null
}
+/**
+ * 剪贴板里没有纯文本时(复制的是文件/图片),交给宿主注入的 paste 垫片
+ * (`src-tauri/src/desktop/paste.rs` 的 `__dsh_paste_clipboard__`)向原生补读
+ * 并合成一次带附件的 paste(issue #1190)。浏览器直开没有该垫片。
+ */
+export async function pasteNativeClipboard(editable: HTMLElement): Promise<boolean> {
+ const bridge = (globalThis as { __dsh_paste_clipboard__?: (target: HTMLElement) => Promise<boolean> }).__dsh_paste_clipboard__
+ if (typeof bridge !== 'function')
+ return false
+ try {
+ return await bridge(editable)
+ }
+ catch (error) {
+ console.warn('[rightclick] native clipboard paste failed:', error)
+ return false
+ }
+}
+
// --- internal ---
/** Clipboard API 不可写时的兜底:临时 textarea + execCommand。 */
diff --git a/src-tauri/src/desktop/paste.rs b/src-tauri/src/desktop/paste.rs
index 30f6119d..60f6967b 100644
--- a/src-tauri/src/desktop/paste.rs
+++ b/src-tauri/src/desktop/paste.rs
@@ -33,15 +33,26 @@ pub(crate) const PASTE_SHIM_JS: &str = r#"(function () {
var reqSeq = 0;
var pending = {}; // id -> resolve(宿主回包按 type 分发,携带原始 data 调用)
+ // 宿主未回包(多层 iframe / 桥未挂载)时不能把右键菜单动作永久挂住。
+ var REQUEST_TIMEOUT_MS = 10000;
function request(reqType) {
return new Promise(function (resolve) {
reqSeq += 1;
var id = 'req-' + reqSeq;
- pending[id] = resolve;
+ var timer = setTimeout(function () {
+ if (!pending[id]) return;
+ delete pending[id];
+ resolve(null);
+ }, REQUEST_TIMEOUT_MS);
+ pending[id] = function (data) {
+ clearTimeout(timer);
+ resolve(data);
+ };
try {
window.parent.postMessage({ source: REQ_SRC, type: reqType, id: id }, '*');
} catch (_) {
+ clearTimeout(timer);
delete pending[id];
resolve(null);
}
@@ -112,7 +123,8 @@ pub(crate) const PASTE_SHIM_JS: &str = r#"(function () {
}
}
- // 把若干 File 塞进同一个 DataTransfer,派发一次合成 paste 给焦点元素
+ // 把若干 File 塞进同一个 DataTransfer,派发一次合成 paste 给焦点元素。
+ // 返回是否真的派发成功:菜单据此决定是否还要提示读取失败。
function dispatchPasteWithFiles(target, files) {
try {
var dt = new DataTransfer();
@@ -127,19 +139,23 @@ pub(crate) const PASTE_SHIM_JS: &str = r#"(function () {
}
if (target.isConnected) {
target.dispatchEvent(ev);
- } else {
- var active = document.activeElement;
- if (active && isPasteTarget(active)) active.dispatchEvent(ev);
+ return true;
+ }
+ var active = document.activeElement;
+ if (active && isPasteTarget(active)) {
+ active.dispatchEvent(ev);
+ return true;
}
} catch (_) {}
+ return false;
}
// 把图片作为 File 塞进新的 DataTransfer,再派发合成 paste 给焦点元素
function dispatchImagePaste(target, dataUrl) {
var blob = dataUrlToBlob(dataUrl);
- if (!blob) return;
+ if (!blob) return false;
var file = new File([blob], 'clipboard-image.png', { type: blob.type || 'image/png' });
- dispatchPasteWithFiles(target, [file]);
+ return dispatchPasteWithFiles(target, [file]);
}
// 把宿主回传的文件条目(data_url + 真实文件名/MIME)还原成 File 后一次性派发。
@@ -153,8 +169,26 @@ pub(crate) const PASTE_SHIM_JS: &str = r#"(function () {
if (!blob) continue;
files.push(new File([blob], entry.filename || 'clipboard-file', { type: entry.mime || blob.type || 'application/octet-stream' }));
}
- if (files.length > 0) dispatchPasteWithFiles(target, files);
- return files.length;
+ if (files.length === 0) return false;
+ return dispatchPasteWithFiles(target, files);
+ }
+
+ // 先问文件:从文件管理器复制文件时剪贴板只有 uri-list(对 WebKit 表现为
+ // 无图无文本),命中即贴文件(issue #1160);复制截图时文件列表为空,
+ // 落回原有图片通路(issue #610),两条路互不干扰。
+ function pasteFromNative(target) {
+ return request(REQ_FILES_TYPE).then(function (fileData) {
+ var entries = (fileData && fileData.files) || [];
+ if (entries.length > 0 && dispatchFilesPaste(target, entries)) return true;
+ // 剪贴板里确实有文件、但全部被拒(超限/不可读/目录):宿主已 toast 说明原因,
+ // 这里不再落回图片通路——那只会再报一次「读不到图片」,把真实原因盖掉。
+ if (fileData && fileData.rejected && fileData.rejected.length > 0) return true;
+ return request(REQ_TYPE).then(function (imageData) {
+ var dataUrl = imageData && imageData.data_url;
+ if (!dataUrl) return false;
+ return dispatchImagePaste(target, dataUrl);
+ });
+ });
}
// 捕获阶段先于 dsh 应用自身监听:空剪贴板时接管并走原生读取。
@@ -162,6 +196,8 @@ pub(crate) const PASTE_SHIM_JS: &str = r#"(function () {
// 且 `window.parent` 指向自身,postMessage 不会命中宿主(见 handleClipboardImage),
// 这里直接把拦截限定在子 frame,避免对壳层输入产生任何干扰。
if (window !== window.parent) {
+ // 右键菜单的「粘贴」只读得到纯文本;复制文件/图片时由菜单直接调用这里(issue #1190)。
+ window.__dsh_paste_clipboard__ = pasteFromNative;
document.addEventListener('paste', function (event) {
var dt = event.clipboardData;
if (hasImageData(dt)) return;
@@ -171,20 +207,7 @@ pub(crate) const PASTE_SHIM_JS: &str = r#"(function () {
if (!isPasteTarget(target)) return;
event.preventDefault();
- // 先问文件:从文件管理器复制文件时剪贴板只有 uri-list(对 WebKit 表现为
- // 无图无文本),命中即贴文件(issue #1160);复制截图时文件列表为空,
- // 落回原有图片通路(issue #610),两条路互不干扰。
- request(REQ_FILES_TYPE).then(function (fileData) {
- var entries = (fileData && fileData.files) || [];
- if (entries.length > 0 && dispatchFilesPaste(target, entries) > 0) return;
- // 剪贴板里确实有文件、但全部被拒(超限/不可读/目录):宿主已 toast 说明原因,
- // 这里不再落回图片通路——那只会再报一次「读不到图片」,把真实原因盖掉。
- if (fileData && fileData.rejected && fileData.rejected.length > 0) return;
- return request(REQ_TYPE).then(function (imageData) {
- var dataUrl = imageData && imageData.data_url;
- if (dataUrl) dispatchImagePaste(target, dataUrl);
- });
- });
+ pasteFromNative(target);
}, true);
}
})();"#;
diff --git a/tasks/myfix-issue-1190-clipboard-paste.md b/tasks/myfix-issue-1190-clipboard-paste.md
new file mode 100644
index 00000000..187cb9f3
--- /dev/null
+++ b/tasks/myfix-issue-1190-clipboard-paste.md
@@ -0,0 +1,34 @@
+# Fix Issue #1190: 右键「粘贴」提示无法读取剪贴板
+
+## Issue 概述
+
+- **Issue 编号**: #1190
+- **Issue 类型**: bug
+- **仓库**: dsh-tauri/deepseek-harness-desktop
+- **状态**: In Progress
+
+## 问题描述
+
+Windows 桌面端在对话输入框内右键选择「粘贴」时,顶部提示「无法读取剪贴板,请使用 Ctrl+V」。复现内容包含纯文本、文件与图片,其中复制文件后右键粘贴必然失败;同样的内容用 Ctrl+V 正常。
+
+## 相关链接
+
+- Issue URL: https://github.com/dsh-tauri/deepseek-harness-desktop/issues/1190
+- PR URL: https://github.com/dsh-tauri/deepseek-harness-desktop/pull/1193
+
+## 实现计划
+
+- [x] 理解需求(brainstorming)
+- [x] 定位根因:右键粘贴只读纯文本,文件/图片剪贴板无 CF_UNICODETEXT,原生读取返回空
+- [x] 编写测试(test-driven-development):先红 5 个用例,再实现转绿
+- [x] 复用宿主 paste 垫片完成文件/图片回退
+- [x] 验证:相关 5 个文件 33 passed;全量 unit 5349 passed / 6 skipped;typecheck、ESLint、垫片 JS 语法均通过
+- [x] 代码审查(requesting-code-review):两轮复审通过,无 Critical / Important
+- [ ] Windows 真机验证:纯文本、文件、截图三条右键粘贴路径(待有 Windows 环境时确认)
+
+## 进度记录
+
+- 2026-10-21: 开始处理,定位到 `readClipboard()` 仅调用 `read_clipboard_text`;复制文件时 arboard 返回 `ContentNotAvailable`,菜单据此抛出误导性提示。Ctrl+V 正常是因为宿主注入的 `PASTE_SHIM_JS` 会向原生补读文件/图片。
+- 2026-10-21: 垫片抽出 `pasteFromNative` 并暴露 `__dsh_paste_clipboard__`;右键粘贴在无文本时调用它,原生读取失败写入 `console.warn`。
+- 2026-10-21: 当前账号对 upstream 仓库只有 pull 权限且无 fork,分支未推送。
+- 2026-10-21: 两轮代码审查通过。新增 vm 执行型契约测试,并做变异验证(移除垫片全局后 6 个用例变红)。Windows 真机三条路径仍待确认。
diff --git a/test/clipboard-files-bridge.test.ts b/test/clipboard-files-bridge.test.ts
index 7bd9b0ff..0eac777e 100644
--- a/test/clipboard-files-bridge.test.ts
+++ b/test/clipboard-files-bridge.test.ts
@@ -74,6 +74,11 @@ describe('clipboard files bridge protocol', () => {
}
})
+ it('exposes the native paste entry point used by the right-click menu (issue #1190)', () => {
+ expect(shim).toContain('function pasteFromNative(target)')
+ expect(shim).toContain('window.__dsh_paste_clipboard__ = pasteFromNative')
+ })
+
it('keeps the image bridge untouched (regression guard for #610)', () => {
expect(shim).toContain(`var RES_TYPE = 'dsh://clipboard-image:reply'`)
expect(iframe).toContain('read_clipboard_image')
diff --git a/test/clipboard-paste-bridge.test.ts b/test/clipboard-paste-bridge.test.ts
new file mode 100644
index 00000000..e631417f
--- /dev/null
+++ b/test/clipboard-paste-bridge.test.ts
@@ -0,0 +1,166 @@
+// @vitest-environment node
+import { Buffer } from 'node:buffer'
+import { runInNewContext } from 'node:vm'
+import { describe, expect, it } from 'vitest'
+import { readSource } from './setup/read-source'
+
+/**
+ * `PASTE_SHIM_JS` 的可执行契约:右键菜单在没有纯文本时调用
+ * `window.__dsh_paste_clipboard__`,由垫片向宿主补读文件/图片并合成 paste(issue #1190)。
+ *
+ * 这些用例在 vm 里执行真实注入脚本,锁住暴露范围、文件优先顺序与返回值语义;
+ * 字符串断言无法发现全局被移出子 frame 守卫或布尔语义被改坏。
+ */
+const SHIM = readSource('src-tauri/src/desktop/paste.rs').match(/PASTE_SHIM_JS: &str = r#"([\s\S]*?)"#;/)?.[1] ?? ''
+
+const REQ_FILES = 'dsh://clipboard-files:read'
+const RES_FILES = 'dsh://clipboard-files:reply'
+const REQ_IMAGE = 'dsh://clipboard-image:read'
+const RES_IMAGE = 'dsh://clipboard-image:reply'
+const FILE = { data_url: 'data:text/plain;base64,QQ==', mime: 'text/plain', filename: 'a.txt' }
+const IMAGE = { data_url: 'data:image/png;base64,AAAA' }
+
+interface ShimReply {
+ files?: unknown[]
+ rejected?: unknown[]
+ data_url?: string
+}
+
+function loadShim(options: { childFrame: boolean, files?: ShimReply, image?: ShimReply }) {
+ const requests: string[] = []
+ const events: unknown[] = []
+ const listeners: ((event: { source: unknown, data: unknown }) => void)[] = []
+ const parent: Record<string, unknown> = {}
+
+ class TestDataTransfer {
+ files: unknown[] = []
+ items = { add: (item: unknown) => { this.files.push(item) } }
+ getData = (): string => ''
+ setData = (): void => {}
+ }
+
+ class TestClipboardEvent {
+ clipboardData: unknown
+ constructor(_type: string, init?: { clipboardData?: unknown }) {
+ this.clipboardData = init?.clipboardData
+ }
+ }
+
+ class TestBlob {
+ constructor(public parts: unknown[], public init: { type?: string } = {}) {}
+ get type(): string {
+ return this.init.type ?? ''
+ }
+ }
+
+ class TestFile extends TestBlob {
+ constructor(parts: unknown[], public name: string, init: { type?: string } = {}) {
+ super(parts, init)
+ }
+ }
+
+ const window: Record<string, any> = {
+ addEventListener: (type: string, listener: (event: unknown) => void) => {
+ if (type === 'message')
+ listeners.push(listener as (event: { source: unknown, data: unknown }) => void)
+ },
+ }
+ window.parent = options.childFrame ? parent : window
+ window.parent.postMessage = (message: { type: string, id: string }) => {
+ requests.push(message.type)
+ const reply = message.type === REQ_FILES ? options.files : options.image
+ if (!reply)
+ return
+ const type = message.type === REQ_FILES ? RES_FILES : RES_IMAGE
+ queueMicrotask(() => {
+ for (const listener of listeners)
+ listener({ source: window.parent, data: { type, id: message.id, ...reply } })
+ })
+ }
+
+ runInNewContext(SHIM, {
+ window,
+ document: { activeElement: null, addEventListener: () => {} },
+ DataTransfer: TestDataTransfer,
+ ClipboardEvent: TestClipboardEvent,
+ Event: class { constructor() {} },
+ Blob: TestBlob,
+ File: TestFile,
+ atob: (value: string) => Buffer.from(value, 'base64').toString('binary'),
+ setTimeout,
+ clearTimeout,
+ queueMicrotask,
+ })
+
+ return {
+ window,
+ requests,
+ events,
+ target: { isConnected: true, dispatchEvent: (event: unknown) => events.push(event) },
+ }
+}
+
+describe('paste shim — 右键菜单原生粘贴入口', () => {
+ it('脚本可从 Rust 源中提取(防止格式变动后测试空跑)', () => {
+ expect(SHIM).toContain('function pasteFromNative(target)')
+ })
+
+ it('只在子 frame 暴露入口,顶层壳层文档没有全局', () => {
+ const top = loadShim({ childFrame: false })
+ const child = loadShim({ childFrame: true })
+
+ expect(top.window.__dsh_paste_clipboard__).toBeUndefined()
+ expect(typeof child.window.__dsh_paste_clipboard__).toBe('function')
+ })
+
+ it('文件优先:派发一次 paste 后不再请求图片', async () => {
+ const { window, requests, events, target } = loadShim({ childFrame: true, files: { files: [FILE] } })
+
+ await expect(window.__dsh_paste_clipboard__(target)).resolves.toBe(true)
+ expect(requests).toEqual([REQ_FILES])
+ expect(events).toHaveLength(1)
+ expect((events[0] as { clipboardData: { files: unknown[] } }).clipboardData.files).toHaveLength(1)
+ })
+
+ it('文件全部被拒时返回已处理,且不回落图片通路', async () => {
+ const { window, requests, events, target } = loadShim({
+ childFrame: true,
+ files: { files: [], rejected: [{ filename: 'big.zip', reason: 'too_large' }] },
+ })
+
+ await expect(window.__dsh_paste_clipboard__(target)).resolves.toBe(true)
+ expect(requests).toEqual([REQ_FILES])
+ expect(events).toHaveLength(0)
+ })
+
+ it('剪贴板只有图片时走图片通路', async () => {
+ const { window, requests, events, target } = loadShim({
+ childFrame: true,
+ files: { files: [] },
+ image: IMAGE,
+ })
+
+ await expect(window.__dsh_paste_clipboard__(target)).resolves.toBe(true)
+ expect(requests).toEqual([REQ_FILES, REQ_IMAGE])
+ expect(events).toHaveLength(1)
+ const file = (events[0] as { clipboardData: { files: { name: string, type: string }[] } }).clipboardData.files[0]
+ expect(file.name).toBe('clipboard-image.png')
+ expect(file.type).toBe('image/png')
+ })
+
+ it('剪贴板为空时返回未处理,调用方保留原提示', async () => {
+ const { window, requests, events, target } = loadShim({ childFrame: true, files: { files: [] }, image: {} })
+
+ await expect(window.__dsh_paste_clipboard__(target)).resolves.toBe(false)
+ expect(requests).toEqual([REQ_FILES, REQ_IMAGE])
+ expect(events).toHaveLength(0)
+ })
+
+ it('目标无法接收 paste 时不谎报已处理', async () => {
+ const { window, events } = loadShim({ childFrame: true, files: { files: [FILE] }, image: {} })
+ const detached = { isConnected: false, dispatchEvent: (event: unknown) => events.push(event) }
+
+ await expect(window.__dsh_paste_clipboard__(detached)).resolves.toBe(false)
+ expect(events).toHaveLength(0)
+ })
+})