mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-10-30 09:16:55 +00:00
fix(cli): stop 'hyperframes add' hanging when a desktop clipboard is available (#6271)
* fix(cli): stop 'hyperframes add' hanging when a desktop clipboard is available * test(cli): assert the clipboard copy options instead of waiting on real time
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const spawnSync = vi.hoisted(() => vi.fn());
|
||||
vi.mock("node:child_process", () => ({ spawnSync }));
|
||||
vi.mock("node:os", async (orig) => ({
|
||||
...(await orig<typeof import("node:os")>()),
|
||||
platform: () => "darwin",
|
||||
}));
|
||||
|
||||
describe("copyToClipboard", () => {
|
||||
beforeEach(() => {
|
||||
spawnSync.mockReset();
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
it("does not let the tool's background owner hold our output pipes or block forever", async () => {
|
||||
spawnSync.mockReturnValue({ status: 0 });
|
||||
const { copyToClipboard } = await import("./clipboard.js");
|
||||
expect(copyToClipboard("snippet")).toBe(true);
|
||||
const opts = spawnSync.mock.calls[0]![2];
|
||||
expect(opts.input).toBe("snippet");
|
||||
expect(opts.stdio).toEqual(["pipe", "ignore", "ignore"]);
|
||||
expect(opts.timeout).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("reports not copied when the tool times out", async () => {
|
||||
spawnSync.mockReturnValue({ status: null, error: new Error("ETIMEDOUT") });
|
||||
const { copyToClipboard } = await import("./clipboard.js");
|
||||
expect(copyToClipboard("snippet")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,8 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { platform } from "node:os";
|
||||
|
||||
const COPY_TIMEOUT_MS = 5000;
|
||||
|
||||
interface ClipboardProvider {
|
||||
cmd: string;
|
||||
args: string[];
|
||||
@@ -49,6 +51,8 @@ export function copyToClipboard(text: string): boolean {
|
||||
const res = spawnSync(provider.cmd, provider.args, {
|
||||
input: text,
|
||||
encoding: "utf-8",
|
||||
stdio: ["pipe", "ignore", "ignore"],
|
||||
timeout: COPY_TIMEOUT_MS,
|
||||
});
|
||||
return res.status === 0;
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user