File size: 2,249 Bytes
d197cf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Gmail Windows tests cover gog watcher command invocation on Windows.
import path from "node:path";
import { describe, expect, it, vi } from "vitest";
import { getWindowsInstallRoots } from "../infra/windows-install-roots.js";
import { withMockedWindowsPlatform } from "../test-utils/vitest-spies.js";

const mocks = vi.hoisted(() => ({
  resolveExecutable: vi.fn(),
}));

vi.mock("../infra/executable-path.js", () => ({
  resolveExecutable: mocks.resolveExecutable,
}));

async function importGmailWithExecutable(executable: string) {
  vi.resetModules();
  mocks.resolveExecutable.mockReset();
  mocks.resolveExecutable.mockReturnValue(executable);
  return await import("./gmail.js");
}

function expectedTrustedCmdExe(): string {
  return path.win32.join(getWindowsInstallRoots().systemRoot, "System32", "cmd.exe");
}

describe("resolveGogServeInvocation on Windows", () => {
  it("wraps spaced gog .cmd paths in an outer cmd.exe command line", async () => {
    const { resolveGogServeInvocation } = await importGmailWithExecutable(
      "C:\\Program Files\\gog\\gog.cmd",
    );

    await withMockedWindowsPlatform(async () => {
      const invocation = resolveGogServeInvocation([
        "gmail",
        "watch",
        "serve",
        "--account",
        "me@example.com",
      ]);

      expect(invocation).toEqual({
        command: expectedTrustedCmdExe(),
        args: [
          "/d",
          "/s",
          "/c",
          '""C:\\Program Files\\gog\\gog.cmd" "gmail" "watch" "serve" "--account" "me@example.com""',
        ],
        windowsHide: true,
        windowsVerbatimArguments: true,
      });
    });
  });

  it("quotes caret arguments for gog .cmd wrappers", async () => {
    const { resolveGogServeInvocation } = await importGmailWithExecutable("gog.cmd");

    await withMockedWindowsPlatform(async () => {
      const invocation = resolveGogServeInvocation([
        "gmail",
        "watch",
        "serve",
        "--label",
        "release/^1",
      ]);

      expect(invocation.args).toEqual([
        "/d",
        "/s",
        "/c",
        '""gog.cmd" "gmail" "watch" "serve" "--label" "release/^1""',
      ]);
      expect(invocation.windowsVerbatimArguments).toBe(true);
    });
  });
});