fix(cli): hide the Windows console for the port lookup and clipboard (#6449)

Co-authored-by: lorenzozanee <lorenzozanee@users.noreply.github.com>
This commit is contained in:
Miguel Ángel
2026-10-26 17:25:01 +00:00
committed by GitHub
co-authored by lorenzozanee
parent c9e86a3b01
commit 37543d223a
4 changed files with 143 additions and 2 deletions
+2 -1
View File
@@ -35,7 +35,7 @@ function detectProvider(): ClipboardProvider | undefined {
];
const cmd = process.platform === "win32" ? "where" : "which";
for (const p of candidates) {
const result = spawnSync(cmd, [p.cmd], { stdio: "ignore" });
const result = spawnSync(cmd, [p.cmd], { stdio: "ignore", windowsHide: true });
if (result.status === 0) return p;
}
return undefined;
@@ -53,6 +53,7 @@ export function copyToClipboard(text: string): boolean {
encoding: "utf-8",
stdio: ["pipe", "ignore", "ignore"],
timeout: COPY_TIMEOUT_MS,
windowsHide: true,
});
return res.status === 0;
} catch {
@@ -0,0 +1,36 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const { spawnSyncMock } = vi.hoisted(() => ({ spawnSyncMock: vi.fn() }));
vi.mock("node:child_process", () => ({ spawnSync: spawnSyncMock }));
vi.mock("node:os", () => ({ platform: () => "linux" }));
import { copyToClipboard } from "./clipboard.js";
describe("clipboard child-process options", () => {
const originalPlatform = process.platform;
beforeEach(() => {
// Exercise the `where`-based provider probe: os.platform() reports a
// non-Windows OS (so the candidate loop runs) while the probe itself
// resolves `where`, the branch taken on Windows.
Object.defineProperty(process, "platform", { value: "win32", configurable: true });
spawnSyncMock.mockReturnValue({ status: 0 });
});
afterEach(() => {
Object.defineProperty(process, "platform", { value: originalPlatform, configurable: true });
vi.clearAllMocks();
});
it("hides console windows for provider probing and copying", () => {
expect(copyToClipboard("snippet")).toBe(true);
// One `where` probe plus the provider copy itself.
expect(spawnSyncMock.mock.calls.length).toBeGreaterThanOrEqual(2);
expect(spawnSyncMock.mock.calls[0]?.[0]).toBe("where");
for (const call of spawnSyncMock.mock.calls) {
expect(call[2]).toEqual(expect.objectContaining({ windowsHide: true }));
}
});
});