

























@@ -3,6 +3,11 @@ import net from "node:net";
33import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
44import { stripAnsi } from "../../packages/terminal-core/src/ansi.js";
55import { mockProcessPlatform } from "../test-utils/vitest-spies.js";
6+import {
7+getWindowsPowerShellExePath,
8+getWindowsSystem32ExePath,
9+getWindowsWmicExePath,
10+} from "./windows-install-roots.js";
611712const runCommandWithTimeoutMock = vi.hoisted(() => vi.fn());
813@@ -422,7 +427,7 @@ describe("inspectPortUsage on Windows", () => {
422427setPlatform("win32");
423428runCommandWithTimeoutMock.mockImplementation(async (argv: string[]) => {
424429const [command] = argv;
425-if (command === "netstat") {
430+if (command === getWindowsSystem32ExePath("netstat.exe")) {
426431return {
427432stdout:
428433" TCP 127.0.0.1:50123 127.0.0.1:18789 ESTABLISHED 4242\r\n" +
@@ -431,10 +436,10 @@ describe("inspectPortUsage on Windows", () => {
431436code: 0,
432437};
433438}
434-if (command === "tasklist") {
439+if (command === getWindowsSystem32ExePath("tasklist.exe")) {
435440return { stdout: "Image Name: node.exe\r\n", stderr: "", code: 0 };
436441}
437-if (command === "powershell") {
442+if (command === getWindowsPowerShellExePath()) {
438443return {
439444stdout:
440445'"C:\\Program Files\\nodejs\\node.exe" C:\\Users\\me\\AppData\\Roaming\\npm\\node_modules\\openclaw\\dist\\index.js logs --follow\r\n',
@@ -460,17 +465,17 @@ describe("inspectPortUsage on Windows", () => {
460465setPlatform("win32");
461466runCommandWithTimeoutMock.mockImplementation(async (argv: string[]) => {
462467const [command] = argv;
463-if (command === "netstat") {
468+if (command === getWindowsSystem32ExePath("netstat.exe")) {
464469return {
465470stdout: " TCP 127.0.0.1:18789 0.0.0.0:0 LISTENING 4242\r\n",
466471stderr: "",
467472code: 0,
468473};
469474}
470-if (command === "tasklist") {
475+if (command === getWindowsSystem32ExePath("tasklist.exe")) {
471476return { stdout: "Image Name: node.exe\r\n", stderr: "", code: 0 };
472477}
473-if (command === "powershell") {
478+if (command === getWindowsPowerShellExePath()) {
474479return {
475480stdout:
476481'"C:\\Program Files\\nodejs\\node.exe" C:\\Users\\me\\AppData\\Roaming\\npm\\node_modules\\openclaw\\dist\\index.js gateway run\r\n',
@@ -496,7 +501,7 @@ describe("inspectPortUsage on Windows", () => {
496501setPlatform("win32");
497502runCommandWithTimeoutMock.mockImplementation(async (argv: string[]) => {
498503const [command] = argv;
499-if (command === "netstat") {
504+if (command === getWindowsSystem32ExePath("netstat.exe")) {
500505return {
501506stdout:
502507" TCP 127.0.0.1:187890 0.0.0.0:0 LISTENING 9000\r\n" +
@@ -517,20 +522,20 @@ describe("inspectPortUsage on Windows", () => {
517522setPlatform("win32");
518523runCommandWithTimeoutMock.mockImplementation(async (argv: string[]) => {
519524const [command] = argv;
520-if (command === "netstat") {
525+if (command === getWindowsSystem32ExePath("netstat.exe")) {
521526return {
522527stdout: " TCP 127.0.0.1:18789 0.0.0.0:0 LISTENING 4242\r\n",
523528stderr: "",
524529code: 0,
525530};
526531}
527-if (command === "tasklist") {
532+if (command === getWindowsSystem32ExePath("tasklist.exe")) {
528533return { stdout: "Image Name: node.exe\r\n", stderr: "", code: 0 };
529534}
530-if (command === "powershell") {
535+if (command === getWindowsPowerShellExePath()) {
531536return { stdout: "", stderr: "access denied", code: 1 };
532537}
533-if (command === "wmic") {
538+if (command === getWindowsWmicExePath()) {
534539return {
535540stdout: "CommandLine=node.exe C:\\openclaw\\dist\\index.js gateway run\r\n",
536541stderr: "",
@@ -544,6 +549,6 @@ describe("inspectPortUsage on Windows", () => {
544549545550expect(result.listeners[0]?.commandLine).toContain("openclaw");
546551const commandNames = runCommandWithTimeoutMock.mock.calls.map(([argv]) => argv[0]);
547-expect(commandNames).toContain("wmic");
552+expect(commandNames).toContain(getWindowsWmicExePath());
548553});
549554});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。