mirror of
https://github.com/earendil-works/pi.git
synced 2026-10-30 07:35:24 +08:00
Replace the external clipboard dependency with small macOS, Windows, and X11 helpers and integrate them into coding-agent. Run native clipboard operations on worker threads and make command fallbacks asynchronous. Preserve incremental X11 transfers, legacy text encodings, native image formats, and existing Wayland and platform tools. Include native prebuilds with ARM64 page alignment, packaging updates, and regression coverage.
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import type * as Tui from "@earendil-works/pi-tui";
|
|
import { afterEach, expect, test, vi } from "vitest";
|
|
import { InteractiveMode } from "../src/modes/interactive/interactive-mode.ts";
|
|
|
|
const readClipboardText = vi.hoisted(() => vi.fn<() => Promise<string | null>>());
|
|
vi.mock("@earendil-works/pi-tui", async (importOriginal) => ({
|
|
...(await importOriginal<typeof Tui>()),
|
|
getNativeClipboard: () => ({
|
|
async getImage() {
|
|
throw new Error("Native clipboard operation failed");
|
|
},
|
|
}),
|
|
}));
|
|
vi.mock("../src/utils/clipboard.ts", () => ({ copyToClipboard: vi.fn(), readClipboardText }));
|
|
vi.mock("../src/utils/clipboard-command.ts", () => ({ runClipboardCommand: vi.fn(async () => undefined) }));
|
|
afterEach(() => vi.unstubAllEnvs());
|
|
|
|
test("native image errors abort paste without reading text or changing the editor", async () => {
|
|
vi.stubEnv("TERMUX_VERSION", "");
|
|
const context = {
|
|
editor: { insertTextAtCursor: vi.fn() },
|
|
ui: { requestRender: vi.fn() },
|
|
};
|
|
const prototype = InteractiveMode.prototype as unknown as {
|
|
handleClipboardPaste(this: typeof context): Promise<void>;
|
|
};
|
|
await prototype.handleClipboardPaste.call(context);
|
|
expect(readClipboardText).not.toHaveBeenCalled();
|
|
expect(context.editor.insertTextAtCursor).not.toHaveBeenCalled();
|
|
expect(context.ui.requestRender).not.toHaveBeenCalled();
|
|
});
|