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:
Miguel Ángel
2026-10-25 04:44:34 +00:00
committed by GitHub
parent 32d2d3cba0
commit 221f3671f2
2 changed files with 35 additions and 0 deletions
+31
View File
@@ -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);
});
});
+4
View File
@@ -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 {