дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
Pasting an image into a terminal or a Markdown file, or saving bytes from the UI, sent the data as a JSON array of numbers (3.6x the size), which Tauri and the remote server parse into a serde_json::Value first (~50x the bytes in memory: a 20 MB image took ~2.2 GB peak heap and 640 ms). Binary command arguments (fs_create_file_bytes, term_store_image) now travel as base64 text (IpcBytes): the same 20 MB takes ~112 MB and 32 ms. Native image drops reuse the base64 they already have. Co-authored-by: Mr0Bread <[email protected]>
53 рядки
2.6 KiB
TypeScript
53 рядки
2.6 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
test("local terminal stores clipboard media and pastes one shell-quoted argument", async ({ page }) => {
|
|
await page.goto("/");
|
|
const observed = await page.evaluate(async () => {
|
|
const ipcPath = "/src/platform/ipc.ts";
|
|
const sessionPath = "/src/features/terminal/session.ts";
|
|
const { commands } = await import(ipcPath);
|
|
const { TerminalSession } = await import(sessionPath);
|
|
Object.defineProperty(window, "__TAURI_INTERNALS__", {
|
|
configurable: true,
|
|
value: { transformCallback: () => 1 },
|
|
});
|
|
const stored: { id: number; data: string; mime: string }[] = [];
|
|
const writes: string[] = [];
|
|
commands.termSpawn = async () => ({ status: "ok", data: { id: 838, title: "pwsh", pid: 1 } });
|
|
commands.clipboardFileList = async () => ({ status: "ok", data: [] });
|
|
commands.termStoreImage = async (id: number, data: string, mime: string) => {
|
|
stored.push({ id, data, mime });
|
|
return { status: "ok", data: "C:\\Temp\\a'b c\\image.png" };
|
|
};
|
|
commands.termWrite = async (_id: number, data: string) => writes.push(data);
|
|
commands.termResize = async () => undefined;
|
|
commands.termKill = async () => undefined;
|
|
const container = document.createElement("div");
|
|
container.style.cssText = "position:fixed;inset:0;z-index:99999";
|
|
document.body.append(container);
|
|
const session = new TerminalSession({ key: "clipboard", cwd: "C:/Temp", onChange() {}, onFocus() {} });
|
|
try {
|
|
session.attach(container);
|
|
await session.start();
|
|
// xterm opens on a later frame, once the pane has a size.
|
|
const openDeadline = Date.now() + 5000;
|
|
while (!container.querySelector("textarea") && Date.now() < openDeadline) {
|
|
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
}
|
|
const transfer = new DataTransfer();
|
|
transfer.items.add(new File([new Uint8Array([137, 80, 78, 71])], "image.png", { type: "image/png" }));
|
|
const event = new ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData: transfer });
|
|
container.querySelector("textarea")!.dispatchEvent(event);
|
|
const deadline = Date.now() + 5000;
|
|
while (!writes.length && Date.now() < deadline) await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
return { stored, writes, claimed: event.defaultPrevented };
|
|
} finally {
|
|
session.dispose();
|
|
container.remove();
|
|
}
|
|
});
|
|
expect(observed.claimed).toBe(true);
|
|
expect(observed.stored).toEqual([{ id: 838, data: "iVBORw==", mime: "image/png" }]);
|
|
expect(observed.writes).toEqual(["'C:\\Temp\\a''b c\\image.png'"]);
|
|
});
|