|
1 | 1 | // Covers gateway process discovery across platform process listings. |
2 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { mockProcessPlatform } from "../test-utils/vitest-spies.js"; |
| 4 | +import { |
| 5 | + getWindowsPowerShellExePath, |
| 6 | + getWindowsSystem32ExePath, |
| 7 | + getWindowsWmicExePath, |
| 8 | +} from "./windows-install-roots.js"; |
4 | 9 |
|
5 | 10 | const spawnSyncMock = vi.hoisted(() => vi.fn()); |
6 | 11 | const readFileSyncMock = vi.hoisted(() => vi.fn()); |
@@ -130,6 +135,8 @@ describe("gateway-processes", () => { |
130 | 135 | parseCmdScriptCommandLineMock.mockReturnValue(["node.exe", "gateway", "run"]); |
131 | 136 |
|
132 | 137 | expect(readGatewayProcessArgsSync(77)).toEqual(["node.exe", "gateway", "run"]); |
| 138 | + expect(spawnSyncMock.mock.calls[0]?.[0]).toBe(getWindowsPowerShellExePath()); |
| 139 | + expect(spawnSyncMock.mock.calls[1]?.[0]).toBe(getWindowsWmicExePath()); |
133 | 140 | expect(parseCmdScriptCommandLineMock).toHaveBeenCalledWith("node.exe gateway run"); |
134 | 141 | }); |
135 | 142 |
|
@@ -177,6 +184,36 @@ describe("gateway-processes", () => { |
177 | 184 | expect(findVerifiedGatewayListenerPidsOnPortSync(18789)).toEqual([200]); |
178 | 185 | }); |
179 | 186 |
|
| 187 | + it("falls back from powershell to trusted netstat for windows listener pids", () => { |
| 188 | + setPlatform("win32"); |
| 189 | + spawnSyncMock |
| 190 | + .mockReturnValueOnce({ |
| 191 | + error: new Error("powershell missing"), |
| 192 | + status: null, |
| 193 | + stdout: "", |
| 194 | + }) |
| 195 | + .mockReturnValueOnce({ |
| 196 | + error: null, |
| 197 | + status: 0, |
| 198 | + stdout: [ |
| 199 | + "Proto Local Address Foreign Address State PID", |
| 200 | + "TCP 0.0.0.0:18789 0.0.0.0:0 LISTENING 200", |
| 201 | + ].join("\r\n"), |
| 202 | + }) |
| 203 | + .mockReturnValueOnce({ |
| 204 | + error: null, |
| 205 | + status: 0, |
| 206 | + stdout: "node.exe gateway run", |
| 207 | + }); |
| 208 | + parseCmdScriptCommandLineMock.mockReturnValue(["node.exe", "gateway", "run"]); |
| 209 | + isGatewayArgvMock.mockReturnValue(true); |
| 210 | + |
| 211 | + expect(findVerifiedGatewayListenerPidsOnPortSync(18789)).toEqual([200]); |
| 212 | + expect(spawnSyncMock.mock.calls[0]?.[0]).toBe(getWindowsPowerShellExePath()); |
| 213 | + expect(spawnSyncMock.mock.calls[1]?.[0]).toBe(getWindowsSystem32ExePath("netstat.exe")); |
| 214 | + expect(spawnSyncMock.mock.calls[2]?.[0]).toBe(getWindowsPowerShellExePath()); |
| 215 | + }); |
| 216 | + |
180 | 217 | it("formats pid lists as comma-separated output", () => { |
181 | 218 | expect(formatGatewayPidList([1, 2, 3])).toBe("1, 2, 3"); |
182 | 219 | }); |
|
0 commit comments