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:
2026-10-15 17:58:48 -04:00
parent 719370c8f7
commit 6081e3e325
1743 changed files with 205460 additions and 131705 deletions

View File

@@ -6,6 +6,7 @@
* instead of image/png.
*/
import { describe, expect, test, vi } from "vitest";
import { readClipboardImage } from "../src/utils/clipboard-image.ts";
function createTinyBmp1x1Red24bpp(): Uint8Array {
// Minimal 1x1 24bpp BMP (BGR + row padding to 4 bytes)
@@ -42,47 +43,24 @@ function createTinyBmp1x1Red24bpp(): Uint8Array {
}
// Mock wl-paste to return BMP
vi.mock("child_process", async () => {
const actual = await vi.importActual<typeof import("child_process")>("child_process");
return {
...actual,
spawnSync: vi.fn((command: string, args: string[]) => {
if (command === "wl-paste" && args.includes("--list-types")) {
return { status: 0, stdout: Buffer.from("image/bmp\n"), error: null };
}
if (command === "wl-paste" && args.includes("image/bmp")) {
return { status: 0, stdout: Buffer.from(createTinyBmp1x1Red24bpp()), error: null };
}
return { status: 1, stdout: Buffer.alloc(0), error: null };
}),
};
});
vi.mock("../src/utils/clipboard-command.ts", () => ({
runClipboardCommand: vi.fn(async (command: string, args: string[]) => {
if (command === "wl-paste" && args.includes("--list-types")) return Buffer.from("image/bmp\n");
if (command === "wl-paste" && args.includes("image/bmp")) return Buffer.from(createTinyBmp1x1Red24bpp());
return undefined;
}),
}));
// Mock the native clipboard (not used in Wayland path, but needs to be mocked)
vi.mock("@mariozechner/clipboard", () => ({
default: {
hasImage: vi.fn(() => false),
getImageBinary: vi.fn(() => Promise.resolve(null)),
},
vi.mock("@earendil-works/pi-tui", () => ({
getNativeClipboard: () => ({ getImage: async () => createTinyBmp1x1Red24bpp() }),
}));
describe("readClipboardImage BMP conversion", () => {
test("converts BMP to PNG on Wayland/WSLg", async () => {
const { readClipboardImage } = await import("../src/utils/clipboard-image.ts");
// Simulate Wayland session (WSLg)
const image = await readClipboardImage({
env: { WAYLAND_DISPLAY: "wayland-0" },
platform: "linux",
});
test.each(["linux", "win32"] as const)("%s: converts command/native BMP to PNG", async (platform) => {
const image = await readClipboardImage({ env: { WAYLAND_DISPLAY: "wayland-0" }, platform });
expect(image).not.toBeNull();
expect(image!.mimeType).toBe("image/png");
// Verify PNG magic bytes
expect(image!.bytes[0]).toBe(0x89);
expect(image!.bytes[1]).toBe(0x50); // P
expect(image!.bytes[2]).toBe(0x4e); // N
expect(image!.bytes[3]).toBe(0x47); // G
expect(Array.from(image!.bytes.slice(0, 4))).toEqual([0x89, 0x50, 0x4e, 0x47]);
});
});