|
1 | 1 | import path from "node:path"; |
2 | 2 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 3 | + |
| 4 | +const detectBinaryMock = vi.hoisted(() => vi.fn(async () => false)); |
| 5 | + |
| 6 | +vi.mock("./detect-binary.js", () => ({ |
| 7 | + detectBinary: detectBinaryMock, |
| 8 | +})); |
| 9 | + |
3 | 10 | import { resolveBrowserOpenCommand } from "./browser-open.js"; |
4 | 11 | import { resetWindowsInstallRootsForTests } from "./windows-install-roots.js"; |
5 | 12 |
|
6 | 13 | afterEach(() => { |
7 | 14 | vi.restoreAllMocks(); |
8 | 15 | vi.unstubAllEnvs(); |
| 16 | + detectBinaryMock.mockReset().mockResolvedValue(false); |
9 | 17 | resetWindowsInstallRootsForTests(); |
10 | 18 | }); |
11 | 19 |
|
@@ -44,4 +52,24 @@ describe("resolveBrowserOpenCommand", () => { |
44 | 52 | expect(resolved.argv).toEqual([rundll32, "url.dll,FileProtocolHandler"]); |
45 | 53 | expect(resolved.command).toBe(rundll32); |
46 | 54 | }); |
| 55 | + |
| 56 | + it("resolves macOS open even when SSH environment variables are present", async () => { |
| 57 | + vi.spyOn(process, "platform", "get").mockReturnValue("darwin"); |
| 58 | + vi.stubEnv("SSH_CONNECTION", "192.0.2.1 12345 192.0.2.2 22"); |
| 59 | + detectBinaryMock.mockResolvedValueOnce(true); |
| 60 | + |
| 61 | + const resolved = await resolveBrowserOpenCommand(); |
| 62 | + |
| 63 | + expect(detectBinaryMock).toHaveBeenCalledWith("open"); |
| 64 | + expect(resolved).toEqual({ argv: ["open"], command: "open" }); |
| 65 | + }); |
| 66 | + |
| 67 | + it("still refuses browser launch over Linux SSH without a display", async () => { |
| 68 | + vi.spyOn(process, "platform", "get").mockReturnValue("linux"); |
| 69 | + vi.stubEnv("SSH_CONNECTION", "192.0.2.1 12345 192.0.2.2 22"); |
| 70 | + |
| 71 | + const resolved = await resolveBrowserOpenCommand(); |
| 72 | + |
| 73 | + expect(resolved).toEqual({ argv: null, reason: "ssh-no-display" }); |
| 74 | + }); |
47 | 75 | }); |
0 commit comments