chore(vendor): import pi 1.3.0
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
39
third_party/pi/packages/coding-agent/test/clipboard-image-native-errors.test.ts
vendored
Normal file
39
third_party/pi/packages/coding-agent/test/clipboard-image-native-errors.test.ts
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
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(),
|
||||
readClipboardFilePaths: vi.fn(async () => null),
|
||||
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() },
|
||||
showError: 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();
|
||||
expect(context.showError).toHaveBeenCalledExactlyOnceWith(
|
||||
"Failed to paste from clipboard: Native clipboard operation failed",
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user